Skip to content

INSERT VERTEX

The INSERT VERTEX statement inserts one or more vertices into a graph space in Nebula Graph.

When inserting a vertex with a VID that already exists, INSERT VERTEX overrides the vertex.

Syntax

INSERT VERTEX <tag_name> (<prop_name_list>) [, <tag_name> (<prop_name_list>), ...]
     {VALUES | VALUE} VID: (<prop_value_list>[, <prop_value_list>])

prop_name_list:
  [prop_name [, prop_name] ...]

prop_value_list:
  [prop_value [, prop_value] ...]
  • tag_name denotes the tag (vertex type), which must be created before INSERT VERTEX.
  • prop_name_list contains the names of the properties on the tag.
  • VID is the vertex ID. In Nebula Graph 2.X, string and integer VID types are supported. The VID type is set when a graph space is created. For detail information on the maximum VID length, see CREATE SPACE.
  • prop_value_list must provide the property values according to the prop_name_list. If the property values do not match the data type in the tag, 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. For details, see CREATE TAG.

Examples

nebula> CREATE TAG t1();                   -- Create tag t1 with no property
nebula> INSERT VERTEX t1() VALUE "10":();    -- Insert vertex "10" with no property
nebula> CREATE TAG t2 (name string, age int);                -- Create tag t2 with two properties
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n1", 12);     -- Insert vertex "11" with two properties
nebula> INSERT VERTEX t2 (name, age) VALUES "12":("n1", "a13");  -- Failed. "a13" is not int
nebula> INSERT VERTEX t2 (name, age) VALUES "13":("n3", 12), "14":("n4", 8);    -- Insert two vertices
nebula> CREATE TAG t3(p1 int);
nebula> CREATE TAG t4(p2 string);
nebula> INSERT VERTEX  t3 (p1), t4(p2) VALUES "21": (321, "hello");   -- Insert vertex "21" with two tags.

A vertex can be inserted/written multiple times. Only the last written values can be read.

// Insert vertex "11" with the new values.
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n2", 13);
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n3", 14);
nebula> INSERT VERTEX t2 (name, age) VALUES "11":("n4", 15);

// Only the last version can be read
nebula> FETCH PROP ON t2 "11";
+---------------------------------+
| vertices_                       |
+---------------------------------+
| ("11" :t2{age: 15, name: "n4"}) |
+---------------------------------+
nebula> CREATE TAG t5(p1 fixed_string(5) NOT NULL, p2 int, p3 int DEFAULT NULL);
nebula> INSERT VERTEX t5(p1, p2, p3) VALUES "001":("Abe", 2, 3);
nebula> INSERT VERTEX t5(p1, p2, p3) VALUES "002":(NULL, 4, 5);
[ERROR (-8)]: Storage Error: The not null field cannot be null.
nebula> INSERT VERTEX t5(p1, p2) VALUES "003":("cd", 5);

// The value for p3 is the default NULL.
nebula> FETCH PROP ON t5 "003";
+--------------------------------------------+
| vertices_                                  |
+--------------------------------------------+
| ("003" :t5{p1: "cd", p2: 5, p3: __NULL__}) |
+--------------------------------------------+
nebula> INSERT VERTEX t5(p1, p2) VALUES "004":("shalalalala", 4);

// The allowed maximum length for property p1 is 5.
nebula> FETCH PROP on t5 "004";
+-----------------------------------------------+
| vertices_                                     |
+-----------------------------------------------+
| ("004" :t5{p1: "shala", p2: 4, p3: __NULL__}) |
+-----------------------------------------------+

Last update: April 13, 2021