A quantified path is a variable-length path where the complete path or a part of it is repeated a specified number of times.
Quantified paths are useful when you:
A quantifier is written as a postfix to either an edge pattern or a parenthesized path pattern to specify how many times the pattern should repeat.
Quantifier | Description |
|---|---|
{m,n} | Between m and n repetitions. |
{m} | Exactly m repetitions. |
{m,} | m or more repetitions. |
{,n} | Between 0 and n repetitions. |
* | Between 0 and more repetitions. |
+ | Between 1 and more repetitions. |

CREATE GRAPH myGraph { NODE User ({name string}), NODE Device (), EDGE Owns ()-[{}]->(), EDGE Flows ()-[{packets int32}]->() } SHARDS [1]
When writing a quantified path to its full form:
AND.Edge patterns can be directly followed by a quantifier, and both the full and abbreviated edge patterns are supported.

You can enclose the entire path pattern in parentheses () and append a quantifier.

When a quantifier is applied to an entire path pattern, a step count of 0 produces no result.
You can enclose part of a path pattern in parentheses () and append a quantifier for it.

Another example:

GQLMATCH p = ({name: 'Jack'})->()-[f:Flows WHERE f.packets > 15]->{1,3}()<-({name: 'Mike'}) RETURN p
Result: p

GQLMATCH p = ((:Device)->(:Device)){2} RETURN p
Result: p

GQLMATCH ({_id: 'Comp1'})->{2,}(n) RETURN COLLECT_LIST(n._id)
Result:
| COLLECT_LIST(n._id) |
|---|
| ["Comp4","Comp3","Comp4"] |
GQLMATCH p = ({_id: 'Comp1'})-[f:Flows WHERE f.packets > 20]->*() RETURN p
Result: p

GQLMATCH p = ({_id: 'Comp1'})-[f:Flows WHERE f.packets > 20]->+() RETURN p
Result: p

GQLMATCH p = ({name: 'Jack'})->(()-[f:Flows WHERE f.packets > 15]->()){,2}<-({name: 'Mike'}) RETURN p
Result: p

Element variables declared within the repeatable part of a quantified path are bound to a list of nodes or edges, known as group variables or group list.

CREATE GRAPH myGraph { NODE User ({name string, age uint32}), EDGE Follows ()-[{score uint32}]->() } SHARDS [1]
Whenever a group variable is referenced outside the repeatable part of the quantified path where it is declared, it refers to a list of nodes or edges.
In this query, variables a and b represent lists of nodes encountered along the matched paths, rather than individual nodes:
GQLMATCH p = ((a)-[]->(b)){1,2} RETURN p, a, b
Result:
| p | a | b |
|---|---|---|
![]() | [(:User {_id:"U2", name:"Quasar92", age:29})] | [(:User {_id:"U3", name:"claire", age:35})] |
![]() | [(:User {_id:"U1", name:"rowlock", age:24})] | [(:User {_id:"U2", name:"Quasar92", age:29})] |
![]() | [(:User {_id:"U1", name:"rowlock", age:24}), (:User {_id:"U2", name:"Quasar92", age:29})] | [(:User {_id:"U2", name:"Quasar92", age:29}), (:User {_id:"U3", name:"claire", age:35})] |
To aggregate the group variables, use the FOR statement to expand it into individual records:
GQLMATCH path = ()-[edges]->{1,2}() CALL (path, edges) { FOR edge IN edges RETURN sum(edge.score) AS scores } FILTER scores > 2 RETURN path, scores
Result:
| p | scores |
|---|---|
![]() | 3 |
![]() | 5 |
The following query throws syntax error since a and b are lists:
GQL - Syntax ErrorMATCH p = ((a)-[]->(b)){1,2} WHERE a.age < b.age RETURN p
A group variable has a singleton reference only when it is referenced within the repeatable part of the quantified path where it is declared.
In this query, a and b are treated as singletons that represent individual nodes. The condition a.age < b.age is evaluated for each pair of nodes a and b as the path is matched:
GQLMATCH p = ((a)-[]->(b) WHERE a.age < b.age){1,2} RETURN p
Result: p
