You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to scan a *time.Time (select datetime('now')) using the below running example gives the error:
panic: cannot scan row: sql: Scan error on column index 0: unsupported Scan, storing driver.Value type []uint8 into type *time.Time
I would expect it to not give an error and instead populate the Time variable with the result, because time.Time/datetime is in the list of supported types.
However, changing the Time variable to string works as expected and outputs:
the time is: 2016-07-08 22:01:38
package main
import (
"database/sql""fmt""time"
_ "github.com/mattn/go-sqlite3"
)
funcmain() {
db, err:=sql.Open("sqlite3", ":memory:")
iferr!=nil {
panic(fmt.Sprintf("cannot open db: %v", err))
}
err=db.Ping()
iferr!=nil {
panic(fmt.Sprintf("cannot open db: %v", err))
}
// interesting stuff starts hererow:=db.QueryRow(`select datetime('now')`)
vart time.Time// var t string // NOTE: using this declaration for t worksiferr=row.Scan(&t); err!=nil {
panic(fmt.Sprintf("cannot scan row: %v", err))
}
fmt.Printf("the time is: %s\n", t)
}
The text was updated successfully, but these errors were encountered:
Trying to scan a *time.Time (
select datetime('now')
) using the below running example gives the error:I would expect it to not give an error and instead populate the Time variable with the result, because time.Time/datetime is in the list of supported types.
However, changing the Time variable to string works as expected and outputs:
The text was updated successfully, but these errors were encountered: