-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: document allowed Scan conversions #9157
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
Comments
On the other hand, the comment for Scan() in your paste says: |
As mentioned by @johto, there will be Thoughts? |
database/sql is really very light on docs. That said, I don't think we should change NullString. |
It is easy to work around the problem, but it is also surprising (to me). The reason is that error says At the very least, the current behavior should be documented. But I don't think this behavior is correct and think we should fix. It seems like a cop-out to use the loss of information rule as an excuse for not converting time.Time to a string. You can certainly encode a time, including its time zone, as a string without losing any information. I would make the argument that time.Time should be converted to string because all of the other types mentioned in the Scanner interface are successfully converted into string. It is surprising that time.Time is not. It feels like an oversight, not an intentional decision. In fact, are there are any Scanners in the standard library which handle time.Time? The reason I bring this up is in the first place is that the only way to read a timestamp from a database using Scan is to know a columns contains a timestamp and provide a time.Time (or NullTime in libpq). Otherwise, it's straightforward to dump a table's contents into strings if you don't care. Instead, that's an error and you have to workaround the problem for times only. It's not like timestamps are a corner case of database either. They're very prevalent. |
CL https://golang.org/cl/18935 mentions this issue. |
The text was updated successfully, but these errors were encountered: