pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.78k stars 298 forks source link

Datetime column strange behaviour #241

Closed Davte closed 4 years ago

Davte commented 6 years ago

At least with sqlite, datetime columns are treated as datetime objects by table.find() method (which is great!) but as strings by db.query() method (which is bad to me). I can't figure out why, can anybody help me understand?

with dataset.connect(DATABASE) as db:
    print("table.find() method")
    for x in db["myTable"].find():
        print(type(x['endTime']))
    print("db.query() method")
    for x in db.query("SELECT * FROM myTable"):
        print(type(x['endTime']))

---> <class datetime.datetime> for the first cycle, <class str> for the second one

pudo commented 4 years ago

Looks like the answer here is "SQLite doesn't really do datetimes":

https://stackoverflow.com/questions/44781320/dates-as-strings-when-submitting-raw-sql-with-sqlalchemy

Use a different database?