In a multi-threaded / async program, the order of events is not predictable, so it is safer to able to use upsert instead of insert or update.
e.g. in the blog example, if there are two threads and they both want to create a tag "danger", this will result in an unique constraint violation in the insert operation for one of them. Doing a query for the tag "danger" to determine whether to insert can help, but the query+insert it isnt atomic so another thread could have created the tag between the query and the insert operations .
In a multi-threaded / async program, the order of events is not predictable, so it is safer to able to use
upsert
instead ofinsert
orupdate
.e.g. in the
blog
example, if there are two threads and they both want to create a tag "danger", this will result in an unique constraint violation in theinsert
operation for one of them. Doing a query for the tag "danger" to determine whether to insert can help, but the query+insert it isnt atomic so another thread could have created the tag between the query and the insert operations .