【发布时间】:2021-03-16 15:11:10
【问题描述】:
我正在尝试在我的 MSSQL 中创建此表
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=LAPTOP;'
'Database=DB;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE logging.t_history (
id serial,
tstamp timestamp DEFAULT now(),
schemaname text,
tabname text,
operation text,
who text DEFAULT current_user,
new_val json,
old_val json
)
''')
conn.commit() cursor = conn.cursor()
但我得到了错误 -
pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Column, parameter, or variable #7: Cannot find data type json. (2715) (SQLExecDirectW)')
这也发生在时间戳为“DEFAUT now()”的情况下。我该如何解决这个问题?
【问题讨论】:
-
您确实必须查看数据类型。 docs.microsoft.com/en-us/sql/t-sql/data-types/…我怀疑时间戳不是你的想法,你可能想要 datetime default getdate()
-
看着你的
create table,我不相信这是给SQL Server的
标签: sql-server database pyodbc