Upsert means to update values of properties other than UUID and ID; only properties carried in the data will be updated, while those are not will remain unchanged.
Upsertion will insert or update one or multiple nodes/edges in the current graphset:
- Upsert nodes: specify existent UUID or ID in the GraphSet, or both that match the correspondence in the GraphSet; the operation fails when the specified UUID and ID pair violates the mapping relationship in the GraphSet; when either the specified UUID or ID or neither does not exist in the GraphSet, or neither of them is specified, the insertion operation will be triggered.
- Upsert edges: specify UUID; when the specified UUID does not exist in the GraphSet, or UUID is not specified, the insertion operation will be triggered; the operation fails if the start/end node of edge is not included or not existent.
Syntax:
- Command:
upsert().into(@<schema>)
- Parameter:
nodes()
oredges()
, custom alias not supported - Statement Alias: Custom alias supported, structure type is NODE or EDGE
It is not suggested to execute upsertion operation after streaming return of an algorithm, see details on
stream()
in document Ultipa Graph Analytics & Algorithms - Using Algorithms - Execution Method.
// To upsert nodes of a certain schema in the current graphset
upsert().into(@<schema>)
.nodes([ // Square brackets can be omitted if upserts only one node
{<property1>:<value1>, <property2>:<value2>, ...},
{<property1>:<value1>, <property2>:<value2>, ...},
...
])
// To upsert edges of a certain schema in the current graphset, must carry _from and _to, or must carry _from_uuid and _to_uuid
upsert().into(@<schema>)
.edges([ // Square brackets can be omitted if upserts only one edge
{<property1>:<value1>, <property2>:<value2>, ...},
{<property1>:<value1>, <property2>:<value2>, ...},
...
])
Example: Given an account U001 with name "test", update the account if it already exists, otherwise insert the account; check the account information after the operation
upsert().into(@account)
.nodes({_id: "U001", name: "test"}) as nodes
return nodes{*}
Example: Update transaction edge of UUID = 1 with transaction No. TRX001 and from C001 to C003, or insert such an edge if not existing; insert another transaction edge with No. TRX003 and from C003 to C001 in the same UQL
upsert().into(@transaction)
.edges([
{no: "TRX001", _from: "C001", _to: "C003", _uuid: 1},
{no: "TRX003", _from: "C003", _to: "C001"}
])