I have a sqlite3 database:
import sqlite3
import pandas as pd
from datetime import datetime
batch_size = 10
con = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cur = con.cursor()
table = """CREATE TABLE my_table(DateCreated DATETIME);"""
cur.execute(table)
DateCreated = [datetime(2020, 12, 1, 1, 1)] * batch_size
x = list(pd.DataFrame({'DateCreated':DateCreated}).to_records(index=False))
query = """INSERT INTO my_table (DateCreated) values (?);"""
cur.executemany(query, x)
When I want to retrieve my datetimes, sqlite3 returns a byte string instead of a datetime object:
cur.execute("SELECT * FROM my_table;")
cur.fetchone()
>> (b'\x00\xf8\xea\x08\xf4qL\x16',)
What am I doing wrong? I have checked this issue but it is not really applicable for my problem. I also tried changing the sqlite datatype from DATETIME to TIMESTAMP, but received ValueError: not enough values to unpack (expected 2, got 1)
. I am using Python 3.8.10.