5.4 Vertex and Edge Identifiers
You can uniquely identify each vertex and edge in a SQL property graph with
the VERTEX_ID
and EDGE_ID
operators, respectively, in a
SQL graph query.
Graph element identifiers are based on the key value defined for the graph element tables. Therefore, it is important to note the following:
- Graphs in
TRUSTED
mode may produce duplicate identifiers for different vertices if some key columns do not have aUNIQUE
constraint. - Graphs in
ENFORCED
mode are guaranteed to always produce unique identifiers.
The VERTEX_ID
and EDGE_ID
operators can be
used in any expression appearing in the COLUMNS
or
WHERE
clause in a SQL graph query.
Note:
In order to use theVERTEX_ID
and EDGE_ID
operators, you must ensure
that you have the READ
or SELECT
privilege on both the
property graph object and its underlying database tables.
The input to the VERTEX_ID
operator is a single vertex
graph pattern variable coming from a matched vertex pattern as shown:
MATCH (v) COLUMNS(VERTEX_ID(v) AS v_id)
Similarly, the EDGE_ID
operator takes as input a single
edge graph pattern variable coming from a matched edge pattern as shown:
MATCH (v1)-[e]->(v2) COLUMNS(EDGE_ID(e) AS e_id)
The output of these operators is a vertex or an edge identifier of JSON data type. The following shows an example of a JSON output describing the vertex identifier:
{
"GRAPH_OWNER": "GRAPHUSER",
"GRAPH_NAME": "STUDENTS_GRAPH",
"ELEM_TABLE": "PERSONS",
"KEY_VALUE": {
"PERSON_ID": 1
}
}
In the preceding JSON output:
GRAPH_OWNER
: Owner of the property graph objectGRAPH_NAME
: Name of the property graph objectELEM_TABLE
: Name of the vertex tableKEY_VALUE
: Name and value of the key column
The same list of JSON output fields apply to an edge identifier also.
However, the ELEM_TABLE
field represents the name of an edge table.
Also, all operations that can be performed on a JSON data type can be performed on the
vertex and edge identifiers.
See Example 5-20 for more information.
VERTEX_EQUAL
and
EDGE_EQUAL
Predicates
The VERTEX_EQUAL
and EDGE_EQUAL
predicates can be used to, respectively, compare two vertex and edge identifiers and
return TRUE
if they are equal.
The inputs to the VERTEX_EQUAL
predicate are two vertex
graph pattern variables. Similarly for EDGE_EQUAL
, both inputs must
be edge graph pattern variables. These predicates can be used in the
WHERE
clause in a SQL graph query.
See Example 5-21 for more information.
Parent topic: SQL Graph Queries