UPSERT EDGE¶
UPSERT EDGE <src_vid> -> <dst_vid> [@rank] OF <edge_type> SET <update_properties> [WHEN <condition>] [YIELD <properties>]
update_propertiesis the properties of the edge to be updated. For example,e1.col1 = $^.e1.col2 + 1means to updatee1.col1toe1.col2+1.NOTE:
$^indicates the edge to be updated.
conditionis some constraints. Only when theconditionis met,UPSERTis executed successfully.conditionsupports expression operations.propertiesspecifies the properties to be returned,YIELDreturns 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
UPSERTfor scenarios with highly concurrent writes.
- If the edge does not exist, a new edge is created no matter whether the condition in the
WHENclause is met or not. The properties not specified by theSETstatement use the default property values. If there are no default values, an error is returned. - If the edge exists and the
WHENcondition is met, the edge is updated. - If the edge exists and the
WHENcondition 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