I am testing around with SQL at the Moment. I noticed that getting values out of the DB and messing around in python is pretty slow. So i try to calculate inside my SQL update function. Way faster. Now i have the problem that i have a date, created with datetime.utcnow()
, in my DB and i want to calculate/update the Age inside the update function.
This is the error message i get with my Code:
ValueError: parameters are of unsupported type
Date is as Text in my DB, maybe this is my mistake?
Here is my Code so far:
import sqlite3
from datetime import datetime
def database_create():
conn = sqlite3.connect('Age_Calculation_in_SQL.db')
c = conn.cursor()
c.execute("INSERT into Test (ID, Date, Age) values (?, ?, ?)",
("1", datetime.utcnow(), 1))
conn.commit()
def database_calculate():
conn = sqlite3.connect('Age_Calculation_in_SQL.db')
c = conn.cursor()
c.execute("UPDATE Test SET Age = Date-? Where ID = 1", (datetime.utcnow()))
conn.commit()
database_calculate()