Search
ctrl/
Ask AI
Light
Dark
System

Upsert

Subtopics

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:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input

Let's make sure that we've ended up with a new Account:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input

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:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input

See that although the watchlist is updated, the id is the same as before:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input