Sometimes you need to either insert a new object or
update an existing one identified with some key
(possibly something other than the main id
). This is
typical of situations like this tutorial, where an
object may or may not already exist and needs to be
reset back to some specific state. This kind of
operation is often called an "upsert" - a portmanteau of
"update or insert". In EdgeQL this is achieved by
appending UNLESS CONFLICT
clause to a regular INSERT
:
Let's make sure that we've ended up with the right user:
Now, just to prove that this "upsert" operation doesn't create a new user every time, let's run it again to update the name:
See that although the user's name
is updated, the id
is the same as before: