Fix stdlib to return time.Time for PostgreSQL time columns#2528
Fix stdlib to return time.Time for PostgreSQL time columns#2528abrightwell wants to merge 1 commit intojackc:masterfrom
time.Time for PostgreSQL time columns#2528Conversation
The `TimeOID` case was missing from the stdlib `Rows.Next()` switch, causing `time` columns to fall through to the `default` case. The `default` case scans into a `string`, which is not a valid `driver.Value` for temporal types. When `database/sql` attempts to assign the resulting `string` to a `*time.Time` scan destination, it fails with: ``` sql: Scan error on column index 0, name "t": unsupported Scan, storing driver.Value type string into type *time.Time ``` To fix this, a `TimeOID` case is added that scans into `pgtype.Time` and converts microseconds since midnight to `time.Time`, matching the existing conversion in `timeWrapper.ScanTime` (`pgtype/builtin_wrappers.go`).
|
As mentioned in #2508, the only potential concern is that those who are currently scanning into a string would see different values. The time would be correct, but it would not be the same string. For instance: Before: "22:45:00" |
I know you mentioned a We already have a few of these edge cases, like for It's unfortunate that golang/go#67546 is still pending. Whenever it is finally resolved that will solve all these issues. |
The
TimeOIDcase was missing from the stdlibRows.Next()switch, causingtimecolumns to fall through to thedefaultcase. Thedefaultcase scans into astring, which is not a validdriver.Valuefor temporal types. Whendatabase/sqlattempts to assign the resultingstringto a*time.Timescan destination, it fails with:To fix this, a
TimeOIDcase is added that scans intopgtype.Timeand converts microseconds since midnight totime.Time, matching the existing conversion intimeWrapper.ScanTime(
pgtype/builtin_wrappers.go).Fixes: #2508