insert+upsert在sqlite3控制台中工作,但在python上它显示语法

2024-04-25 17:35:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是sqlite 3.25.1版。 当我在sqlite控制台中执行以下查询时,它会起作用:

insert into cases (bi, age, shape, margin, density, severity) 
values (5, 67, 3, 5, 3, 1)
on conflict(bi, age, shape, margin, density, severity) 
DO UPDATE SET frequency=frequency+1;

但当我在python上执行它时,它会说:

sqlite3.OperationalError: near "on": syntax error

下面是我在python上的代码:

^{pr2}$

我不知道该怎么做。在


Tags: marginsqliteageondensitydoinsertvalues
1条回答
网友
1楼 · 发布于 2024-04-25 17:35:22

python加载的sqlite3版本中可能没有包含UPSERT。从sqlite3 doc

UPSERT syntax was added to SQLite with version 3.24.0 (2018-06-04).

要在python中查找sqlite版本,请执行以下操作:

>>> import sqlite3
>>> sqlite3.sqlite_version

相关问题 更多 >