6.4 Vertex and Edge Labels with PGQL
Labels are a way of attaching type information to edges and nodes in a graph, and can be used in constraints in graphs where not all nodes represent the same thing. For example:
SELECT p.name
FROM MATCH (p:person) -[e1:likes]-> (m1:movie),
MATCH (p) -[e2:likes]-> (m2:movie)
WHERE m1.title = 'Star Wars'
AND m2.title = 'Avatar'
The example queries a graph which contains a set of vertices with the label
person
, a set of vertices with the label movie
, and a set
of edges with the label likes
. A label predicate can start with either a
colon (:
) or the keyword IS
followed by one or more labels.
If more than one label is used, then the labels are separated by a vertical bar
(|
).
The following query shows the preceding example query with the keyword
IS
for the label predicate:
SELECT p.name
FROM MATCH (p IS person) -[e1 IS likes]-> (m1 IS movie),
MATCH (p IS person) -[e2 IS likes]-> (m2 IS movie)
WHERE m1.title = 'Star Wars'
AND m2.title = 'Avatar'
See Also:
- Label Expressions section in the PGQL specification
- Label Predicates section in the PGQL specification
Parent topic: Property Graph Query Language (PGQL)