Bentaiba Miled Basma
Bentaiba Miled Basma

Reputation: 587

insert + upsert works in sqlite3 console, but on python it shows syntax error

I'm using sqlite version 3.25.1. When I execute the following query in sqlite console, it works:

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;

But when I execute it on python, it says:

sqlite3.OperationalError: near "on": syntax error

Here is my code on python:

C.execute('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', ())

I don't know how to make it work.

Upvotes: 0

Views: 2643

Answers (1)

DinoCoderSaurus
DinoCoderSaurus

Reputation: 6520

It's possible UPSERT is not included in the sqlite3 version that python loads. From the sqlite3 doc:

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

To find the sqlite version in python:

>>> import sqlite3
>>> sqlite3.sqlite_version

Upvotes: 3

Related Questions