Columns defined as TIMESTAMP DEFAULT 0
scan to the year -4713
#290
-
Consider the following code:
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 Is there a way to tell the library to treat a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is explained in the driver documentation. The default format used by the driver is The value So this is not a bug, simply an incompatibility with That said, if you'd prefer to use Unix timestamps for everything, you can set sql.Open("sqlite3", "file:demo.db?_timefmt=unixepoch_frac") |
Beta Was this translation helpful? Give feedback.
This is explained in the driver documentation.
The default format used by the driver is
auto
, which is detailed in the SQLite documentation and theTimeFormat.Decode
documentation; it's safe to use from at least 1980 through at least 2260, otherwise there is ambiguity.The value
0
(zero) is one such case. Note that if you fire up thesqlite3
CLI, or open the SQLite3 Fiddle, and run the querySELECT datetime(0);
the result is precisely-4713-11-24 12:00:00
.So this is not a bug, simply an incompatibility with
mattn
, and not SQLite; betweenmattn
and SQLite, I'll follow SQLite.That said, if you'd prefer to use Unix timestamps for everything, you can set
_timefmt
tounixepoch
orunixepoch_frac