Insert operation means to insert one or multiple nodes/edges into the current GraphSet; commands insert()
, insert().overwrite()
and upsert()
all can trigger an insert operation. This article introduces the insert operation triggered by command insert()
.
When executing insert()
:
- An insert operation is triggered if ID is not provided, or the provided ID does not exist in the graph;
- The operation fails if the provided ID already exists in the graph;
- Other cases of failure: FROM or TO not provided when inserting edges, or provided but the nodes they represent do not exist in the graph.
When insert operation is triggered by insert()
:
- IDs that are not provided will be generated by system;
- Custom properties provided in the correct data type will be inserted;
- Custom properties that are not provided, or provided in the wrong data type will be inserted as empty string (for string, text, datetime), 0 (for int32, int64, uint32, uint64, float, double), or "1970-01-01 08:00:00 +08:00" (for timestamp).
It is not suggested to execute insertion operation after streaming return of an algorithm, see details on
stream()
in document Ultipa Graph Analytics & Algorithms - Using Algorithms - Execution Method.
Syntax:
- Statement alias: supported (NODE or EDGE)
// To insert nodes of a certain schema in the current graphset
insert().into(@<schema>)
.nodes([ // Square brackets can be omitted if inserts only one node
{<property1>:<value1>, <property2>:<value2>, ...},
{<property1>:<value1>, <property2>:<value2>, ...},
...
])
// To insert edges of a certain schema in the current graphset, must carry _from and _to, or must carry _from_uuid and _to_uuid
insert().into(@<schema>)
.edges([ // Square brackets can be omitted if inserts only one edge
{<property1>:<value1>, <property2>:<value2>, ...},
{<property1>:<value1>, <property2>:<value2>, ...},
...
])
Example: Insert two nodes into @account with names "Graph", "Database" and account No. U001, U002; check the UUID generated by the system
insert().into(@account)
.nodes([{_id: "U001", name: "Graph"}, {_id: "U002", name: "Database"}]) as nodes
return nodes._uuid
Note: In the above node insertion operation, account No. is a string and can be stored in ID.
Example: Insert an edge into @transaction with transaction No. TRX001, amount 100, transaction time 2021-01-01 09:00:00, from card C001 to card C002; check the UUID generated by the system
insert().into(@transaction)
.edges({no: "TRX001",
_from: "C001",
_to: "C002",
amount: 100,
time: "2021-01-01 09:00:00"
}) as edges
return edges._uuid
Note: In the above edge insertion operation, the transaction No. is a string and needs to be stored in a user-defined string-type property no, because ID is not supported by edges; query for user-defined properties can be sped up via index or LTE.