The insert().into() clause facilitates the insertion of new nodes or edges within a single schema.
Syntax// Insert nodes insert().into(@<schema>).nodes([ {<property1>: <value1>, <property2>: <value2>, ...}, {<property1>: <value1>, <property2>: <value2>, ...} ]) // Insert edges insert().into(@<schema>).edges([ {<property1>: <value1>, <property2>: <value2>, ...}, {<property1>: <value1>, <property2>: <value2>, ...} ])
into() method.nodes() or edges() method.
{ }.[ ] can be omitted.Inserting nodes:
_id or _uuid is missing, its value will be generated by the system.null.Inserting edges:
_from and _to (or _from_uuid and _to_uuid) are mandatory to be provided to specify the start and end nodes of the edge. Other properties are optional._uuid is missing, its value will be automatically generated by the system.null.
Run these UQLs row by row in an empty graphset to create this graph:
UQLcreate().node_schema("user").edge_schema("follow") create().node_property(@user, "name").node_property(@user, "age", int32).edge_property(@follow, "time", datetime)Click to expand
UQLinsert().into(@user).nodes({_id: "U005", name: "Alice"})
A new node is inserted with the following properties:
| _id | _uuid | name | age |
|---|---|---|---|
| U005 | 5 | Alice | null |
UQLinsert().into(@follow).edges({_from: "U002", _to: "U001", time: "2023-8-9"})
A new edge is inserted with the following properties:
| _uuid | _from | _to | _from_uuid | _to_uuid | time |
|---|---|---|---|---|---|
| 4 | U002 | U001 | 2 | 1 | 2023-08-09 00:00:00 |
UQLinsert().into(@user).nodes([ {name: "Lee", age: 12}, {_uuid: 10, name: "Alex"}, {} ])
Three new nodes are inserted with the following properties:
_id | _uuid | name | age |
|---|---|---|---|
| ULTIPA8000000000000009 | 6 | Lee | 12 |
| ULTIPA8000000000000005 | 10 | Alex | null |
| ULTIPA800000000000000B | 7 | null | null |
UQLinsert().into(@follow).edges([ {_from_uuid: 1, _to_uuid: 2}, {_uuid: 9, _from: "U004", _to: "U003", time: "2023-9-10"}, {_from: "U002", _to: "U003"} ])
Three new edges are inserted with the following properties:
| _uuid | _from | _to | _from_uuid | _to_uuid | time |
|---|---|---|---|---|---|
| 5 | U001 | U002 | 1 | 2 | null |
| 9 | U004 | U003 | 4 | 3 | 2023-09-10 00:00:00 |
| 6 | U002 | U003 | 2 | 3 | null |
UQLinsert().into(@user).nodes([ {_id: "U006", name: "Joy"}, {_id: "U007", age: 41} ]) as n return n{*}
Result:
| _id | _uuid | name | age |
|---|---|---|---|
| U006 | 8 | Joy | null |
| U007 | 9 | null | 41 |
Use the point() function to specify the value of a point-type property.
UQLinsert().into(@city).nodes([ { location: point({latitude: 132.1, longitude: -1.5}) } ])
Use the castToRaw() function to specify the value of a blob-type property.
UQLinsert().into(@city).nodes([ {profile_img: castToRaw("data:image/png;base64,iVBO0KGf8/9hAHNCSVQI=")} ])
Provide a list with elements enclosed in [ ] and separated with ,. The data type of each element should correspond to the type of the list.
Here's an example of inserting a node while providing the value for a list-type (float[]) property ratings:
UQLinsert().into(@city).nodes([ {ratings: [3.2, 6.7, 5.6, 5.6]} ])
Provide a set with elements enclosed in [ ] and separated with ,. The data type of each element should correspond to the type of the set.
Here's an example of inserting a node while providing the value for a set-type (set(string)) property tags:
UQLinsert().into(@city).nodes([ {tags: ["hot", "art", "food"]} ])
_id, _uuid) already exist in the graph.