Upsert
The "upsert" is only one possible use of the conditional insert
command. In reality there are several other
useful usages of unless conflict
construct. In its most
basic form, it allows to simply ignore conflicting insert
commands rather than causing an error. This is
useful if we want the insert
to be idempotent, such as
in the case of trying to create composable
initialization scripts. Here's an example of such an insert
:
Firstly, notice that the most basic form of unless conflict
has no condition or an else
part.
Secondly, see that only the first insert
produced an
object, while the following ones resulted in empty sets.
Lastly, we encourage you to experiment and see what
happens if unless conflict
is omitted in the above
example.