SQL MERGE is quite distinct from UPSERT
postgresql.org
postgresql.org
On the HN side, this is the sort of experiment we'd like to do more of, and this seemed like a great place to try it, since there's clearly unsatisfied curiosity in the community (including us!) about how upsert was implemented.
Is it really? If an upsert can race, deadlock or trigger constraint violation there's no point to having it, existing construct can race, deadlock or violate constraints just fine.
Obviously if you run out of disk space or something like that, that will throw an error aborting the transaction.
update [table] set ...; if @@ROWCOUNT = 0 insert into [table] ...There are other ways to emulate upserts, but they tend to have performance and/or concurrency considerations.
For example: http://www.postgresql.org/docs/current/static/plpgsql-contro...
This is ugly an inefficient.
https://news.ycombinator.com/item?id=9541362
MERGE is ANSI standard SQL, and so far as I know it's the only upsert-like syntax supported by both Oracle and MS SQL. (Please correct me if I'm wrong.)
Even if the MERGE command isn't what we're looking for, we really should make an effort to come up with something that can be implemented in a uniform way across databases.
Let's consider whether to use the MySQL syntax (http://dev.mysql.com/doc/refman/5.6/en/insert-on-duplicate.h...) instead of inventing something new.