我有一个带DATE列的sqlite数据库,我无法通过python中的SQL进行匹配。 我从https://docs.python.org/3/library/sqlite3.html#module-functions-and-constants阅读了文档,并在下面尝试过:
import sqlite3
import datetime
con = sqlite3.connect(":memory:",detect_types=sqlite3.PARSE_DeclTYPES|sqlite3.PARSE_COLNAMES)
cur = con.cursor()
cur.execute("create table test(d date,ts timestamp)")
today = datetime.date.today()
now = datetime.datetime.now()
cur.execute("insert into test(d,ts) values (?,?)",(today,now))
cur.execute('select current_date as "d [date]" from test') #No errors
cur.execute('select current_date as "d [date]" from test where current_date = ?',today ) #ValueError: parameters are of unsupported type
r = cur.fetchall()
print(r)
con.close()
有人可以解释为什么我在第二条SQL语句中收到“ ValueError:参数类型不受支持”的情况吗?