Overview
The insert()
statement inserts new nodes and edges into a single schema in a graphset.
// Inserts nodes
insert().into(<schema>).nodes([
{<property1?>: <value1?>, <property2?>: <value2?>, ...},
{<property1?>: <value1?>, <property2?>: <value2?>, ...},
...
])
// Inserts edges
insert().into(<schema>).edges([
{_from: <fromValue>, _to: <toValue>, <property1?>: <value1?>, <property2?>: <value2?>, ...},
{_from: <fromValue>, _to: <toValue>, <property1?>: <value1?>, <property2?>: <value2?>, ...},
...
])
Method |
Param |
Description |
---|---|---|
into() |
<schema> |
Specifies the node or edge schema (e.g., @user ). |
nodes() or edges() |
List of property specifications | Defines the node(s) or edge(s) to be inserted into the specified schema, with each property specification wrapped in {} . |
In the property specifications, each provided property will be assigned its given value, while any missing custom properties will default to null
.
Please note:
- Node
_id
values will be generated by the system if not provided, though custom unique values can be assigned if desired. - Node and edge
_uuid
values are always generated by the system and cannot be manually assigned. - Edge properties
_from
and_to
must be provided to specify the source and destination nodes of the edge.
Properties in Schema-Free Graphs
In a schema-free 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 |
Example Graph

To create the graph, execute each of the following UQL queries sequentially in an empty graphset:
create().node_schema("user").edge_schema("follow")
create().node_property(@user, "name").node_property(@user, "age", int32).node_property(@user, "location", point).node_property(@user, "isBlocked", bool).node_property(@user, "permissionCodes", "set(uint32)").edge_property(@follow, "time", datetime)
insert().into(@user).nodes([{_id:"U001", name:"Jason", age:30}, {_id:"U002", name:"Tim"}, {_id:"U003", name:"Grace", age:25}, {_id:"U004", name:"Ted", age:26}])
insert().into(@follow).edges([{_from:"U004", _to:"U001", time:"2021-9-10"}, {_from:"U003", _to:"U001", time:"2020-3-12"}, {_from:"U004", _to:"U002", time:"2023-7-30"}])
Inserting a Single Node/Edge
To insert a @user
node:
insert().into(@user).nodes({_id: "U005", name: "Alice"})
To insert a @follow
edge:
insert().into(@follow).edges({_from: "U002", _to: "U001", time: "2023-8-9"})
When inserting a single node or edge, the outer brackets
[]
innodes()
oredges()
can be omitted.
Inserting Multiple Nodes/Edges
To insert three @user
nodes:
insert().into(@user).nodes([
{_id: "U006", name: "Lee", age: 12},
{name: "Alex"},
{}
])
To insert two @follow
edges:
insert().into(@follow).edges([
{_from: "U001", _to: "U002"},
{_from: "U004", _to: "U003", time: "2023-9-10"}
])
Returning Inserted Data
To insert two @follow
edges and return all the information of the inserted edges:
insert().into(@follow).edges([
{_from: "U001", _to: "U004"},
{_from: "U001", _to: "U003", time: "2022-2-7"}
]) as e
return e{*}
Result: e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U001 | U004 | UUID of U001 | UUID of U004 | follow | {time: null } |
Sys-gen | U001 | U003 | UUID of U001 | UUID of U003 | follow | {time: "2022-02-07 00:00:00"} |
Inserting Boolean Values
A property of the bool
type accepts only 1
(or true
) or 0
(or false
).
Any positive integer other than
0
will be automatically converted to1
. Assigning other values may result in unpredictable behavior.
To insert a @user
node with a value for the property isBlocked
of type bool
:
insert().into(@user).nodes({isBlocked: 0})
Inserting Point Values
Use the point()
function to assign a value to a property of type point
.
To insert a @user
node with a value for the property location
of type point
:
insert().into(@user).nodes([
{location: point({latitude: 132.1, longitude: -1.5})}
]) as n
return n.location
Result:
n.location |
---|
POINT(132.1 -1.5) |
Inserting List Values
To insert a @user
node with a value for the property interests
of type string[]
:
insert().into(@user).nodes([
{interests: ["violin", "tennis", "movie"]}
])
Inserting Set Values
To insert a @user
node with a value for the property permissionCodes
of type set(uint32)
:
insert().into(@user).nodes([
{permissionCodes: [1002, 1002, 1003, 1004]}
]) as n
return n.permissionCodes
Result:
n.permissionCodes |
---|
[1003,1004,1002] |
Element values within a set are automatically deduplicated.