Skip to content

Path variables

Prefix a pattern with p = to bind its complete path value. A path preserves traversal order and graph identity.

MATCH p = (a {name: 'Alice'})-[:Knows]->(b)-[:Knows]->(c)
RETURN p, PATH_LENGTH(p) AS hops;

This returns a path of two edges. A zero-hop path has one node and no edges. A missing path from OPTIONAL MATCH is null, so its PATH_LENGTH is null.

PATH_LENGTH counts edges. ELEMENTS returns alternating node/edge references that FOR can expand. Path result fields are described in Arrow results.

The parser also recognizes explicit PATH [...] constructors; constructing a path that way is not implemented in query execution. Matched paths are the executable source of path values.