> Le 30 juin 2016 à 11:01, Simon Slavin <slav...@bigfraud.org> a écrit :
> 
>> Of course writing straight code in C/C++ it's rather simple to emulate 
>> situations where you want to update some values in an existing row, creating 
>> the row if needed.
> 
> The standard way of doing this is to do two commands:
> 
> 1) INSERT without the REPLACE
> 2) UPDATE
> 
> When step 1 fails because the key values already exist you trap this and 
> explicitly ignore it in your code (commented, because you're being nice to 
> other programmers).  Then it's always the UPDATE which updates the fields you 
> care about.

So
INSERT OR IGNORE ...
followed by
UPDATE ...

The (possibly) annoying thing behind this is that the most logical use case of 
an "UPDATE OR INSERT"/"UPSERT"/whatever-name is to update a row and in the rare 
case it might not already exist, to insert it.

I have not yet deep enough knowledge of inner details and optimizations inside 
sqlite.c but I tend to think it might be more costly to attempt insert first, 
having it fail (ignored) most of the times, and then only do the update.

-- 
Meilleures salutations, Met vriendelijke groeten, Best Regards,
Olivier Mascia, integral.be/om



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to