I ran into a problem with the UPSERT statement in SQLite.
I have a master and a slave database, the updates to the slave database should be merged into the master database. I would like to use the UPSERT clause. This works for inserting values()
but not for inserting from a subquery.
The documentation (at least the diagram) shows that it should work: https://www.sqlite.org/lang_insert.html
But I'm getting an error. Am I missing something?
sqlite> create table orig (id int unique, a int);
sqlite> create table copy (id int unique, a int);
sqlite> insert into orig values (1,0);
sqlite> insert into copy values (1,0);
sqlite> insert into orig values (1,1) on conflict do update set a=1;
sqlite> select * from orig;
1|1
sqlite> insert into orig select * from copy on conflict do update set a=2;
Parse error: near "do": syntax error
insert into orig select * from copy on conflict do update set a=2;
error here ---^
I also have tried different expressions, but no avail:
sqlite> insert into orig select * from copy on conflict do nothing;
Parse error: near "do": syntax error
insert into orig select * from copy on conflict do nothing;
error here ---^
sqlite> insert into orig select * from copy on conflict (id) do update set a=2;
Parse error: near "do": syntax error
ert into orig select * from copy on conflict (id) do update set a=2;
error here ---^
sqlite3 --version 3.40.1 2022-12-28