-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: database/sql: sql.IsNull #34593
Comments
How often are NullX values declared as interface{} in the wild, where one couldn't just check v.Valid? |
SQL drivers also define their own Null* types. So IsNull() is never guaranteed to work as expected with a type switch. |
This proposal would not be robust for user types. Good to keep in mind for v2 however. |
Yeah, you're totally right about it not being robust for user types. Is it perhaps worth making them implement an interface that expects I suppose one could also check if |
I'm using it to generate SQL queries based on the type of a value. Unfortunately |
@qaisjp, you say that you are holding an interface{} that may contain one of these types, and if it is a value of one of these types that represents null, you want to format the SQL query as I'm with you so far. But then what if it's not null? This doesn't seem like it needs to be in the standard library when it can be so easily provided outside the library and would not be used that often. |
When it's not null I did something like this: Then we pass in the If it's worth mentioning, I'm no longer composing the statement this way, so no longer need an |
Given the discussion so far and especially @renthraysk's #34593 (comment) comment and the fact that @qaisjp no longer needs this function anyway, this seems like a likely decline. Leaving open for a week for final comments. |
No change in consensus, so declining. |
An addition to database/sql to quickly tell you whether one of the NullX types are in fact, "null".
It would be the addition of essentially this:
Am happy to send PR, just wanted to quickly get feedback on whether this would be fine? Or should I have used the golang-dev mailing list instead?
The text was updated successfully, but these errors were encountered: