Overview
The INSERT
statement allows you to add new nodes and edges into the graph using patterns.
In an open graph, you can directly insert nodes and edges, and the corresponding schemas and properties will be automatically created on the fly. When a property is created, its value type is inferred from the first value provided. See the examples below:
Value Example | Description | Inferred Property Value Type |
---|---|---|
-20 , 1315 |
Any integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,806 |
INT64 |
100000000000000001 |
Any integer from 9,223,372,036,854,775,807 to 18,446,744,073,709,551,614 |
UINT64 |
18.25 |
Any decimal with up to 15 significant digits | DOUBLE |
"graph database" |
Any string with a length up to 60,000 bytes |
STRING |
"graph database is ..." |
Any string exceeding 60,000 bytes in length |
TEXT |
date("1993-05-09") |
Values returned by the date() function |
DATE |
local_datetime("1993-05-09 03:02:11") |
Values returned by the local_datetime() function |
LOCAL DATETIME |
local_time("03:02:11") |
Values returned by the local_time() function |
LOCAL TIME |
zoned_datetime("1993-05-09T03:02:11-0600") |
Values returned by the zaoned_datetime() function |
ZONED DATETIME |
zoned_time("03:02:11-06:00") |
Values returned by the zoned_time() function |
ZONED TIME |
TRUE , FALSE |
Boolean values | BOOL |
point({latitude:39.9, longitude:116.3}) |
Values returned by the point() function |
POINT |
["tennis", "football", "swimming"] |
Constructed lists | LIST |
On the other hand, in a typed graph, any node or edge inserted must conform to its graph type - nodes or edges with undefined schemas or properties cannot be added.
Preparing a Graph
We will use an open graph to demonstrate node and edge insertion. To create an open graph named myGraph
:
CREATE GRAPH myGraph ANY
In a typed graph, the syntax for inserting nodes and edges is the same as in an open graph, but you must ensure that the specified node and edge schemas and properties are already defined in the graph.
Inserting Nodes
Nodes are inserted using node patterns, each of which consists of:
- Variable declaration (Optional): If needs to return the inserted node or reference it in subsequent queries, you can declare a variable for it.
- Label expression (Required): Each node must have exactly one label (i.e., its schema name).
- Property specification (Optional): Assign values to the node’s properties. Note that:
- If a node
_id
is not provided, it will be automatically generated by the system; however, you may assign a custom unique value if desired. - Node
_uuid
values are always generated by the system and cannot be manually assigned. - For an existing label, any properties not explicitly provided will default to
null
.
- If a node
To insert a User
and two Club
nodes and return them:
INSERT (n1:User {_id: "U01", name: "Quasar92"}), (n2:Club {_id: "C01"}), (n3:Club {since: 2007})
RETURN n1, n2, n3
Result:
+-----+---------------------+--------+----------+
| _id | _uuid | Schema | name |
+-----+---------------------+--------+----------+
| U01 | 9223375335389659138 | User | Quasar92 |
+-----+---------------------+--------+----------+
+-----+---------------------+--------+-------+
| _id | _uuid | Schema | since |
+-----+---------------------+--------+-------+
| C01 | 4755803405526499330 | Club | null |
+-----+---------------------+--------+-------+
+--------------------------+----------------------+--------+-------+
| _id | _uuid | Schema | since |
+--------------------------+----------------------+--------+-------+
| 68ad5fa400000001d4000005 | 11961562809319292931 | Club | 2007 |
+--------------------------+----------------------+--------+-------+
To insert anther User
node:
INSERT (:User {_id: "U02", name: 'mochaeach', gender: 'female'})
Until now, two node schemas have been created behind the scenes:
User
node schema with two properties:name
(STRING
type) andgender
(STRING
type)Club
node schema with one property:since
(INT64
type)
Inserting Edges
Edges are inserted using path patterns where the edge pattern has node patterns on both sides and must include a direction to indicate its source and destination nodes. Each edge pattern consists of:
- Variable declaration (Optional): If needs to return the inserted edge or reference it in subsequent queries, you can declare a variable for it.
- Label expression (Required): Each edge must have exactly one label (i.e., its schema name).
- Property specification (Optional): Assign values to the edge’s properties. Note that:
- Edge
_uuid
values are always generated by the system and cannot be manually assigned. - Edge
_from
,_to
,_from_uuid
, and_to_uuid
values are automatically derived from the specified source and destination nodes. They cannot be manually assigned. - For an existing label, any properties not explicitly provided will default to
null
.
- Edge
When inserting edges, you either connect them to existing nodes in the graph or insert the source and destination nodes along with the edges.
Inserting Nodes Along with Edges
To insert three User
nodes and two Follows
edges between them:

INSERT (:User {name: 'rowlock'})-[:Follows {createdOn: date('2024-01-05')}]->(:User {name: 'Brainy', gender: 'male'})<-[:Follows {createdOn: date('2024-02-01')}]-(:User {name: 'purplechalk', gender: 'female'})
Connecting to Existing Nodes
To insert and return a Joins
edge, with its source and destination nodes being found by the preceding MATCH
statement and bound to variables n1
and n2
:

MATCH (n1:User {_id: 'U01'}), (n2:Club {_id: 'C01'})
INSERT (n1)-[e:Joins {memberNo: 1}]->(n2)
RETURN e
Result: e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
3 | U01 | C01 | 9223375335389659138 | 4755803405526499330 | Joins | {memberNo: 1} |
Inserting Connected Paths
To insert two paths that intersect at a node by reusing the variable c02
:

INSERT (:User {_id: 'U06', name: 'waveBliss'})-[:Joins {memberNo: 1}]->(c02:Club {_id: 'C02'})<-[:Joins {memberNo: 2}]-(:User {_id: 'U07', name: 'bella', gender: 'female'}),
(:User {_id: 'U08', name: 'Roose'})-[:Joins {memberNo: 3}]->(c02)