Why is the datetime
type lost after inserting them in a Sqlite database?
import sqlite3, datetime
dbconn = sqlite3.connect(':memory:')
c = dbconn.cursor()
c.execute('create table mytable(title text, t timestamp)')
c.execute('insert into mytable (title, t) values (?, ?)', ("hello2", datetime.datetime(2018,3,10,12,12,00)))
c.execute("select * from mytable")
for a in c.fetchall():
print a[0] # hello2
print type(a[0]) # <type 'unicode'>
print a[1] # 2018-03-10 12:12:00
print type(a[1]) # <type 'unicode'>
Shouldn't the datetime type remain after an insertion and a query?
PS: I lost nearly one hour because of this problem, so I'll post the answer now with the "Answer your own question – share your knowledge, Q&A-style" SO feature.
Note: this is not a duplicate of this neighbour question because it doesn't deal about how datetimes are stored/retrieved.