Comments (7)
There is no datetime type in sqlite3. Everything is treated as text on sqlite3 for unknown types.
go-sqlite3 implements a special treatment that allows the text to be treated as a string or time.
If you use time.Time or string instead of float32, you will not have this problem. If you want to treat created_at as int64 or float64, you should declare the type of created_at as integer or real.
from go-sqlite3.
See https://www.sqlite.org/datatype3.html
from go-sqlite3.
Ah. I knew sqlite was mapping SQL-spec types to a smaller subset. I didn't realize DATETIME -> NUMERIC, and numeric prefers int to real. Looks like in this case, values close to round numbers went to ints.
Note: Scanning DATETIME into time.Time doesn't work. It would be ideal if it did. I only went the epochTime/float64 route when I saw the query returning float64. When a DATETIME (aka NUMERIC) column has a real (non int) value it errors with sql: Scan error on column index 0, name "created_at": unsupported Scan, storing driver.Value type float64 into type *time.Time
Can the time.Time be updated to accept both int and real values?
from go-sqlite3.
Seems like a case could be added in convert.go
for src=float64, dest=time.Time?
from go-sqlite3.
You can make new type which can convert integer/real to time.Time.
func (v *MyDateTime) Scan(value interface{}) error {
// ...
}
func (v *MyDateTime) Value() (driver.Value, error) {
// ...
}
from go-sqlite3.
BTW, why you don't define epochTime as time.Time ?
from go-sqlite3.
why you don't define epochTime as time.Time ?
That's what I'd like to do, but it hits Scan error on column index 0, name "created_at": unsupported Scan, storing driver.Value type float64 into type *time.Time
if any values are floating point.
I def could go the custom type route.
Since the driver support epoch integers, and the SQL DATETIME type maps to both ints and reals (and strings) in sqlite, it would be nice if reals were also supported by the driver as time.Time, like ints are. Correct me if I'm wrong, but I think this is all valid SQL, and only errors on this driver?
Let me know if you'd be open to a patch adding time.Time to float64 conversion in convert.go. I could see not wanting to break back compatibility. There's also the question of information loss: I don't think it will happen in practice often, but someone could add higher than nanosecond precision to a floating point field, in which case time.Time would be losing data.
from go-sqlite3.
Related Issues (20)
- importing go-sqlite hangs my application!!?? HOT 3
- C code errors on linux amd64
- exec for update does not correctly return sql.Results HOT 1
- Can't seem to fuzz SQLite?? HOT 1
- sqlite3 in-memory mode deletes data and releases memory
- x86编译问题
- It doesn't create a new database file if opened in a `network drive` with `:encrypted.db?_key`.
- Flagged by Windows Defender since v1.14.20 HOT 2
- Race conditions during unit tests despite workarounds HOT 2
- Is it worth compiling in math functions by default? HOT 3
- Inconsistent behavior of sin() math function on x86 (musl / alpine)
- High suspended process count on linux
- Segmentation fault in Ubuntu 18.04 with GLIBC_2.34 HOT 1
- 【ERROR】Windows use winlibs HOT 1
- Panic while using sqlite rows.Next() - fatal error: unexpected signal during runtime execution
- sqlite3-binding.c use after free HOT 4
- Generic PRAGMA URI parameters HOT 9
- Restore in-memory database failed by using Online Backup API HOT 2
- vtable example broken HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-sqlite3.