INSERT INTO
StatementINSERT INTO
statement adds edges or vertices to the graph. When the ID value(s) for the inserted vertex/edge match those of an existing vertex/edge, then the new values will overwrite the old values. To insert an edge, its endpoint vertices must already exist, either before running the query or inserted earlier in that query. The INSERT INTO
statement can be used as a query-body-level statement or a DML-sub statement.INSERT
statement can either be set statically (vertexType
or edgeType
), or it can be written as a string variable (name
), with the value being set at run time, to make a Dynamic DML query.
INSERT INTO
(vertexType | name) ...
Note that to INSERT an edge type dynamically, the keyword EDGE is required:
INSERT INTO
(edgeType |
EDGE
name) ...
PRIMARY_ID
. To insert an edge, the first two attribute names must be FROM
and TO
._
, which means the default value for that attribute type. The optional name which follows the first two (id) values is to specify the source vertex type and target vertex type, if the edge type had been defined with wildcard vertex types.insertEx
illustrates query-body level INSERT
statements: insert new company
vertices and worksFor
edges into the workNet
graph.whoWorksForCompany
can be used to check the effect of query insertEx
. Prior to running insertEx
, running whoWorksForCompany("gsql")
will find 0 companies
called "gsql"
and 0 worksFor
edges for company "gsql"
. If we then run the query insertEx("tic", "tac", "toe", "gsql")
, then insertEx("gsql")
will find a company called "gsql"
and another one called "gsql_jp"
. Moreover, it will find 3 edges, tic, tac, and toe, with different values for the startMonth
, startYear
, and fullTime parameters.company3
. List all the Japan-based companies before and after the insertion.UPDATE
statement updates the attributes of vertices or edges.UPDATE
statements are not supported in syntax V2. To update vertex or edge attributes in syntax v2, use assignment statements in the ACCUM
and POST-ACCUM
clauses of a SELECT
statement. For more details, see Data Modification in Syntax V2. FROM
clause, following the same rules as the FROM
clause in a SELECT
statement. In the SET
clause, the dmlSubStmtList
contains assignment statements to update the attributes of a vertex or edge. Both simple base type attributes and collection type attributes can be updated. These assignment statements use the vertex or edge aliases declared in the FROM
clause. The optional WHERE
clause supports boolean conditions to filter the items in the vertex set or edge set.UPDATE
statement can only be used as a query-body-level statement. However, DML-sub level updates are still possible by using other statement types. A vertex attribute's value can be updated within the POST-ACCUM
clause of a SELECT
block by using the assignment operator (=
); An edge attribute's value can be updated within the ACCUM
clause of a SELECT
block by using the assignment operator. In fact, the UPDATE
statement is equivalent to a SELECT
statement with ACCUM
and/or POST-ACCUM
to update the vertex or edge attribute values. ACCUM
clause is not allowed, because the update can occur multiple times in parallel, and possibly result in a non-deterministic value. If the vertex attribute value update depends on an edge attribute value, use the vertex-attached accumulators to save the value and update the vertex attribute's value in the POST-ACCUM
clause.SELECT
statement instead of an UPDATE
statement and performs the same update as the query above. Query updateEx2
reverses the locationId
change made by updateEx
.UPDATE
statements and SELECT
statements, a simple assignment statement at the query-body level can be used to update the attribute value of a single vertex or edge, if the vertex or edge has been assigned to a variable or parameter.