3 ms·
This implementation of upsert is especially nice because it is atomic [1]: <literal>ON CONFLICT DO UPDATE</literal> guarantees an atomic <command>INSER
by ryanjshaw 11y ago
This implementation of upsert is especially nice because it is atomic [1]:
<literal>ON CONFLICT DO UPDATE</literal> guarantees an atomic
<command>INSERT</command> or <command>UPDATE</command> outcome - provided
there is no independent error, one of those two outcomes is guaranteed,
even under high concurrency.
I don't know about Oracle or MySQL, but the SQL Server implementation of MERGE requires you to carefully consider which locks to use and it's very easy to shoot yourself in the foot with.
[1] http://git.postgresql.org/gitweb/?p=postgresql.git;a=blobdiff;f=doc/src/sgml/ref/insert.sgml;h=c88d1b7b50a30dacf4c1809e73e84eacf2ca3611;hp=a3cccb9f7c79a5bac71ed35a96d171e9b9587041;hb=168d5805e4c08bed7b95d351bf097cff7c07dd65;hpb=2c8f4836db058d0715bc30a30655d646287ba509 http://git.postgresql.org/gitweb/?p=postgresql.git;a=blobdif...