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.
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 0
(true) or 1
(false). Any other value provided will be automatically converted to 0
.
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.