3 ms·
A better way to look at it, imho: you can check for the unexpected condition in the client, or in the database. With ON CONFLICT .. DO, it's in the database, w
by samatman 6y ago
A better way to look at it, imho: you can check for the unexpected condition in the client, or in the database.
With ON CONFLICT .. DO, it's in the database, which has advantages sometimes: it's typical to have multiple clients, and one database.
Even better, you can treat conflict as an expected condition, and specify what to DO when it arises.
An example in SQLite which I happened to be working on this week: I have a table with a (foreign key, ordinal) tuple as the primary key of the table. Bad things happen to the client code if there are duplicate ordinals, but the row itself is mutable, so: on conflict, update.
There's nothing left to check, this is simply a compact way for me to specify the correct behavior. The client can simply write new rows, without having to delete the old ones.