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 a new Account
:
Now, just to prove that this "upsert" operation doesn't
create a new Account
every time, let's run it again to
update the watchlist
:
See that although the watchlist
is updated, the id
is the same as before: