Overview
The INSERT
statement allows you to add new nodes and edges into the graph using patterns.
Ultipa supports both open graphs and typed graphs:
Open Graph
For an open graph, you can directly insert nodes and edges, and the labels and properties are created on the fly.
You may assign zero, one, or multiple labels to a node or edge in an open graph. Below are the examples of property values you may give to nodes and edges:
Value Example | Description | Equivalent 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 |
point3d({x:10, y:3.2, z:5}) |
Values returned by the point3d() function |
POINT3D |
["tennis", "football", "swimming"] |
Constructed lists | LIST |
Learn more about open graphs →
Typed Graph
For a typed graph, any node or edge inserted must conform to its defined schemas and properties - nodes or edges with undefined schemas or properties cannot be added.
You must assign exactly one schema to a node or edge in a typed graph. Any given property value will be checked against the defined value type; any properties not explicitly provided will default to null
.
Learn more about typed graphs →
Example Graphs
To create an open graph:
CREATE GRAPH gOpen ANY
To create a typed graph:
CREATE GRAPH gTyped {
NODE User ({name STRING, gender STRING}),
NODE Club ({since INT32}),
EDGE Follows ()-[{createdOn DATE}]->(),
EDGE Joins ()-[{memberNo UINT32}]->()
}
Inserting Nodes
Nodes are inserted using node patterns, each of which consists of:
- Variable declaration (Optional): Declares a variable for the inserted node in order to use it later.
- Label expression:
- Optional for open graphs; you may assign zero, one, or multiple labels to a node.
- Required for typed graphs; you must assign exactly one schema to a node.
- Property specification (Optional): Provides property values. Note that:
- If
_id
is missing, it will be generated by the system; however, you may assign a custom unique value if desired. _uuid
is always generated by the system and cannot be manually assigned.
- If
To insert a User
node:
INSERT (n:User {_id: "U01", name: "mochaeach", gender: "female"})
RETURN n
To insert multiple nodes:
INSERT (:User {_id: "U02", name: "Quasar92"}),
(:Club {_id: "C01"}),
(:Club)
In an open graph, you may also assign empty or multiple labels to a node:
INSERT (n) RETURN n
INSERT (n:Person&Employee {name: "Bob"})
RETURN n
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): Declares a variable for the inserted edge in order to use it later.
- Label expression:
- Optional for open graphs; you may assign zero, one, or multiple labels to an edge.
- Required for typed graphs; you must assign exactly one schema to an edge.
- Property specification (Optional): Provides property values. Note that:
_uuid
is always generated by the system and cannot be manually assigned._from
,_to
,_from_uuid
, and_to_uuid
values are derived from the specified source and destination nodes. They cannot be manually assigned.
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 a Joins
edge, with its source and destination nodes being found by the preceding MATCH
statement:

MATCH (n1:User {_id: 'U01'}), (n2:Club {_id: 'C01'})
INSERT (n1)-[e:Joins {memberNo: 1}]->(n2)
RETURN e
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)