Skip to content
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

database/sql: convert NULL to empty string #2814

Closed
andybalholm opened this issue Jan 30, 2012 · 2 comments
Closed

database/sql: convert NULL to empty string #2814

andybalholm opened this issue Jan 30, 2012 · 2 comments
Assignees

Comments

@andybalholm
Copy link
Contributor

@andybalholm andybalholm commented Jan 30, 2012

It would be nice if the sql package could scan NULL into a string variable, giving an
empty string, instead of requiring a NullString variable to handle NULLs. Users could
still use NullString if they care about the distinction.

See https://groups.google.com/forum/#!topic/golang-nuts/jNdrSeq97hY
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 30, 2012

Comment 1:

Owner changed to @bradfitz.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jan 31, 2012

Comment 2:

I think we've decided not to do this after thinking about it for a while.
It would be inconsistent with the rest of the value converters which have a policy of
never losing data.  Just like they won't convert the string "257" into a uint8, we
shouldn't collapse "" and NULL together.  Also, if we did it for strings, people would
want it for ints too, and NULL vs 0 seems potentially more serious than NULL vs "".
I'd rather see people modify their SQL to collapse them there explicitly if they want,
or write NullString explicitly if they want to get one out.  I think that being explicit
about types feels more Go-like.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.