The insert().overwrite() statement either (1) overwrites existing nodes and edges, or (2) inserts new nodes and edges into a single schema in a graphset.
Syntax// Overwrites or inserts nodes insert().overwrite().into(@<schema>).nodes([ {<property1?>: <value1?>, <property2?>: <value2?>, ...}, {<property1?>: <value1?>, <property2?>: <value2?>, ...}, ... ]) // Overwrites or inserts edges insert().overwrite().into(@<schema>).edges([ {_from: <fromValue>, _to: <toValue>, <property1?>: <value1?>, <property2?>: <value2?>, ...}, {_from: <fromValue>, _to: <toValue>, <property1?>: <value1?>, <property2?>: <value2?>, ...}, ... ])
Method | Param | Description |
|---|---|---|
overwrite() | / | Enables overwriting. Edge overwriting is allowed only when an EDGE KEY constraint is defined. |
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 overwritten or inserted into the specified schema, with each property specification wrapped in {}. |
A node is overwritten when an existing _id value is provided in the property specification. An edge is overwritten when an existing EDGE KEY constraint value is specified along with the corresponding _from and _to values.
When a node or edge is overwritten:
null.A new node is inserted when a new _id value is provided or when it is missing. A new edge is inserted when no overwriting (as described above) takes place. Note that edge properties _from and _to must be provided to specify the source and destination nodes of the edge.
When a node or edge is inserted:
null._id is generated by the system if not provided. Node or edge _uuid is always generated by the system and cannot be manually assigned.
To create the graph, execute each of the following UQL queries sequentially in an empty graphset:
UQLcreate().node_schema("user").edge_schema("follow") create().node_property(@user, "name").node_property(@user, "age", int32).edge_property(@*, "time", datetime).edge_property(@*, "weight", int32).edge_property(@*, "flag") 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", weight:2, flag: "green"}, {_from:"U003", _to:"U001", time:"2020-3-12", weight:1, flag: "green"}, {_from:"U004", _to:"U002", time:"2023-7-30", weight:3, flag: "red"}])
To overwrite or insert nodes into @user:
UQLinsert().overwrite().into(@user).nodes([ {_id: "U001", name: "John"}, {_id: "U005", name: "Alice"}, {age: 12} ]) as n return n{*}
_id U001 already exists in the graph, so the corresponding node is overwritten._id U005 is new, so a new node is inserted._id is not provided, so a new node is inserted.Result: n
_id | _uuid | schema | values |
|---|---|---|---|
| U001 | Sys-gen | user | {name: "John", age: null} |
| U005 | Sys-gen | user | {name: "Alice", age: null} |
| Sys-gen | Sys-gen | user | {name: null, age: 12} |
When there is no EDGE KEY constraint defined, this query throws an error:
UQLinsert().overwrite().into(@follow).edges([ {_from: "U004", _to: "U001", time: "2021-9-10"}, {_from: "U001", _to: "U004", time: "2021-10-3", weight: 2} ])
To create a single-property EDGE KEY constraint on the edge property time:
UQLCREATE CONSTRAINT key_time FOR ()-[e]-() REQUIRE e.time IS EDGE KEY OPTIONS { type: {time: "datetime"} }
To overwrite or insert edges into @follow:
UQLinsert().overwrite().into(@follow).edges([ {_from: "U004", _to: "U001", time: "2021-9-10"}, {_from: "U001", _to: "U004", time: "2021-10-3", weight: 2} ]) as e return e{*}
time) with the value 2021-9-10 already exists in the graph, and both _from and _to match, so the corresponding edge is overwritten.time) with the value 2021-10-3 is new, so a new edge is inserted.Result: e
_uuid | _from | _to | _from_uuid | _to_uuid | schema | values |
|---|---|---|---|---|---|---|
| Sys-gen | U004 | U001 | UUID of U004 | UUID of U001 | follow | {time: "2021-09-10 00:00:00", weight: null, flag: null} |
| Sys-gen | U001 | U002 | UUID of U001 | UUID of U002 | follow | {time: "2021-10-03 00:00:00", weight: 2, flag: null} |
To create a composite EDGE KEY constraint on the edge properties time and weight:
UQLCREATE CONSTRAINT key_time_weight FOR ()-[e]-() REQUIRE (e.time, e.weight) IS EDGE KEY OPTIONS { type: {time: "datetime", weight: "int32"} }
To overwrite or insert edges into @follow:
UQLinsert().overwrite().into(@follow).edges([ {_from: "U004", _to: "U001", time: "2021-9-10", weight: 2}, {_from: "U003", _to: "U001", time: "2020-3-12", weight: 2}, {_from: "U001", _to: "U004", time: "2021-10-3", weight: 1, flag: "green"} ]) as e return e{*}
time, weight) with the combined value (2021-9-10, 2) already exists in the graph, and both _from and _to match, so the corresponding edge is overwritten.time, weight) with the combined value (2020-3-12, 2) is new, so a new edge is inserted.time, weight) with the combined value (2021-10-3, 1) is new, so a new edge is inserted.Result: e
_uuid | _from | _to | _from_uuid | _to_uuid | schema | values |
|---|---|---|---|---|---|---|
| Sys-gen | U004 | U001 | UUID of U004 | UUID of U001 | follow | {time: "2021-09-10 00:00:00", weight: 2, flag: null} |
| Sys-gen | U003 | U001 | UUID of U003 | UUID of U001 | follow | {time: "2020-03-12 00:00:00", weight: 2, flag: null} |
| Sys-gen | U001 | U004 | UUID of U001 | UUID of U004 | follow | {time: "2021-10-03 00:00:00", weight: 1, flag: "green"} |