2 ms·
To do upserts correctly in a case of concurrent write access to the database is a real pain in the ass to get right and in the end always boils down to locking
by pilif 11y ago
To do upserts correctly in a case of concurrent write access to the database is a real pain in the ass to get right and in the end always boils down to locking or retrying in loops with random sleep times interspersed in order to not conflict over and over again.
Having the ability to tell the database the data to insert together with a conflict resolution rule and then having the guarantee that either the record will be created or the conflict resolution will be applied is very handy.
No more looping, no more deadlocks, no more retrying the same insert multiple times.
Yes, you can do it manually, but it's painful.
See also http://www.depesz.com/2012/06/10/why-is-upsert-so-complicated/ http://www.depesz.com/2012/06/10/why-is-upsert-so-complicate...