0

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.

1 Answers1

3

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
DinoCoderSaurus
  • 6,110
  • 2
  • 10
  • 15