-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
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"
)
func main() {
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
panic(fmt.Sprintf("cannot open db: %v", err))
}
err = db.Ping()
if err != nil {
panic(fmt.Sprintf("cannot open db: %v", err))
}
// interesting stuff starts here
row := db.QueryRow(`select datetime('now')`)
var t time.Time
// var t string // NOTE: using this declaration for t works
if err = row.Scan(&t); err != nil {
panic(fmt.Sprintf("cannot scan row: %v", err))
}
fmt.Printf("the time is: %s\n", t)
}
Metadata
Metadata
Assignees
Labels
No labels