No. Insert or replace will delete any and all records that violate constraints, 
and then insert a new record. This may cause ON DELETE CASCADE foreign key 
constraints to fire.

Do it in code as you suggested yourself.

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von Robert M. Münch
Gesendet: Freitag, 16. März 2018 11:25
An: SQLite mailing list <sqlite-users@mailinglists.sqlite.org>
Betreff: [EXTERNAL] [sqlite] UPSERT

Hi, is there an elegant way to simulate a dynamic UPSERT in SQLite since it 
doesn’t has an UPSERT?

So, if I have a table with 30 columns and my code updates sub-sets out of these 
columns, I don’t want to write queries that manually retrieve the old values 
one by one.

insert or replace into Book (ID, Name, TypeID, Level, Seen) values (
        (select ID from Book where Name = "SearchName"),
   "SearchName",
    5,
    6,
    (select Seen from Book where Name = "SearchName"));

So, for every column I don’t want to change I need to add a sub-select 
statement. If I need to build this statement dynamically, IMO it would be 
better to handle this code directly in code:

if(record-exists?){
        UPDATE …
} else {
        INSERT …
}

Any suggestions / feedback?

Viele Grüsse.

--

Robert M. Münch, CEO
M: +41 79 65 11 49 6

Saphirion AG
smarter | better | faster

http://www.saphirion.com
http://www.nlpp.ch


___________________________________________
 Gunter Hick | Software Engineer | Scientific Games International GmbH | 
Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 
1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to