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
{{ message }}
Repository navigation
columns defined as TIMESTAMP DEFAULT 0 scan to the year -4713 #289
package main
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
// _ "github.com/ncruces/go-sqlite3/driver"
// _ "github.com/ncruces/go-sqlite3/embed"
"log"
"os"
"path/filepath"
"time"
)
func main() {
dir, _ := os.MkdirTemp("", "foo")
defer os.RemoveAll(dir)
db, err := sql.Open("sqlite3", filepath.Join(dir, "test.db"))
if err != nil {
log.Fatal(err)
}
if _, err := db.Exec(`CREATE TABLE IF NOT EXISTS test ( x TEXT, ts TIMESTAMP DEFAULT 0 );`); err != nil {
log.Fatal(err)
}
if _, err := db.Exec(`INSERT INTO test ( x ) VALUES ( 'foo' );`); err != nil {
log.Fatal(err)
}
row := db.QueryRow(`SELECT * from test;`)
var val string
var t time.Time
if err := row.Scan(&val, &t); err != nil {
log.Fatal(err)
}
log.Println(t)
}
When run as shown, using the github.com/mattn/go-sqlite3 driver, my TIMESTAMP DEFAULT 0 column comes back as the Unix epoch date (jan 1 1970).
If I switch around the imports to use ncruces/go-sqlite3 instead, the TIMESTAMP column comes back as -4713-11-24 12:00:00 +0000 UTC, which makes encoding/json very unhappy among other things.
Is there a way to tell the library to treat a 0 value as the epoch zero, the way mattn does?
Reactions are currently unavailable
Activity
Repository owner locked and limited conversation to collaborators on Jul 9, 2025
Activity