Skip to content

INSERT EDGE

The INSERT EDGE statement inserts an edge from a source vertex (given by src_vid) to a destination vertex (given by dst_vid) with a specific rank.

When inserting an edge that already exists, INSERT VERTEX overrides the edge.

Syntax

INSERT EDGE <edge_type> ( <prop_name_list> ) {VALUES | VALUE}
<src_vid> -> <dst_vid>[@<rank>] : ( <prop_value_list> )
[, <src_vid> -> <dst_vid>[@<rank>] : ( <prop_value_list> ), ...]

<prop_name_list> ::=
  [ <prop_name> [, <prop_name> ] ...]

<prop_value_list> ::=
  [ <prop_value> [, <prop_value> ] ...]
  • <edge_type> denotes the edge type, which must be created before INSERT EDGE. Only one edge type can be specified in this statement.
  • <prop_name_list> is the property name list in the given <edge_type>.
  • <prop_value_list> must provide the value list according to <prop_name_list>. If the property values do not match the data type in the edge type, an error is returned. When the NOT NULL constraint is set for a given property, an error is returned if no property is given. When the default value for a property is NULL, you can omit to specify the property value.
  • rank is optional. It specifies the edge rank of the same edge type. If not specified, the default value is 0. You can insert many edges with the same edge type for two vertices by using different rank values.

    OpenCypher compatibility

    OpenCypher has no such a concept as rank.

Examples

nebula> CREATE EDGE e1();                    -- create edge type t1 with empty property
nebula> INSERT EDGE e1 () VALUES "10"->"11":();    -- insert an edge from vertex "10" to vertex "11" with empty property
nebula> INSERT EDGE e1 () VALUES "10"->"11"@1:();  -- insert an edge from vertex "10" to vertex "11" with empty property, the edge rank is 1
nebula> CREATE EDGE e2 (name string, age int);                     -- create edge type e2 with two properties
nebula> INSERT EDGE e2 (name, age) VALUES "11"->"13":("n1", 1);          -- insert edge from "11" to "13" with two properties
nebula> INSERT EDGE e2 (name, age) VALUES \
"12"->"13":("n1", 1), "13"->"14":("n2", 2);                           -- insert two edges
nebula> INSERT EDGE e2 (name, age) VALUES "11"->"13":("n1", "a13");      -- ERROR. "a13" is not int

An edge can be inserted/written multiple times. Only the last written values can be read.

-- insert edge with the new values.
nebula> INSERT EDGE e2 (name, age) VALUES "11"->"13":("n1", 12);
nebula> INSERT EDGE e2 (name, age) VALUES "11"->"13":("n1", 13);
nebula> INSERT EDGE e2 (name, age) VALUES "11"->"13":("n1", 14);

// Only the last write can be read
nebula> FETCH PROP ON e2 "11"->"13";
+-------------------------------------------+
| edges_                                    |
+-------------------------------------------+
| [:e2 "11"->"13" @0 {age: 14, name: "n1"}] |
+-------------------------------------------+

Last update: April 22, 2021