Skip to content


UPSERT EDGE <src_vid> -> <dst_vid> [@rank] OF <edge_type> SET <update_properties> [WHEN <condition>] [YIELD <properties>]
  • update_properties is the properties of the edge to be updated. For example, e1.col1 = $^.e1.col2 + 1 means to update e1.col1 to e1.col2+1.

    NOTE:  $^ indicates the edge to be updated.

  • condition is some constraints. Only when the condition is met, UPSERT is executed successfully. condition supports expression operations.
  • properties specifies the properties to be returned, YIELD returns the latest updated values.

UPSERT is a combination of UPDATE and INSERT. Use UPSERT EDGE to update properties on an edge if it exists or insert a new edge if it does not exist. The UPDATE EDGE statement updates only one edge at a time.

The performance of UPSERT is much lower than that of INSERT, because UPSERT is a read-modify-write serialization operation at the partition level.

DON'T: DO NOT use UPSERT for scenarios with highly concurrent writes.

  • If the edge does not exist, a new edge is created no matter whether the condition in the WHEN clause is met or not. The properties not specified by the SET statement use the default property values. If there are no default values, an error is returned.
  • If the edge exists and the WHEN condition is met, the edge is updated.
  • If the edge exists and the WHEN condition is not met, Nebula Graph does nothing.

Consider the following example:

//Insert a new edge.
nebula> INSERT EDGE serve(start_year, end_year) VALUES "player100" -> "team200":(1997, 2016);  -- 

nebula> UPSERT EDGE "player100" -> "team200" OF serve SET start_year = serve.start_year + 2 WHEN serve.end_year == 2016 YIELD serve.start_year AS Start, serve.end_year AS End;
| Start | End  |
| 1999  | 2016 |

nebula> FETCH PROP ON serve "player100" -> "team200";
| edges_                                                                |
| [:serve "player100"->"team200" @0 {end_year: 2016, start_year: 1999}] |

Last update: January 26, 2021
Back to top