
GQLINSERT (p1:Paper {_id:'P1', title:'Efficient Graph Search', score:6, author:'Alex'}), (p2:Paper {_id:'P2', title:'Optimizing Queries', score:9, author:'Alex'}), (p3:Paper {_id:'P3', title:'Path Patterns', score:7, author:'Zack'}), (p1)-[:Cites {weight:2}]->(p2), (p2)-[:Cites {weight:1}]->(p3)
Returns the number of edges in a path.
| Syntax | path_length(<pathVar>) | ||
| Arguments | Name | Type | Description |
<pathVar> | PATH | Path variable reference | |
| Return Type | UINT | ||
GQLMATCH p = ()->{1,3}() RETURN p, path_length(p) AS length
Result:
| p | length |
|---|---|
![]() | 2 |
![]() | 1 |
![]() | 1 |
Returns a list containing the nodes and edges that make up a path, interleaved in order.
| Syntax | elements(<pathVar>) | ||
| Arguments | Name | Type | Description |
<pathVar> | PATH | Path variable reference | |
| Return Type | LIST | ||
GQLMATCH p = ()->() LET items = elements(p) FOR item IN items WITH ORDINALITY index FILTER index %2 = 1 RETURN item
Result:
JSON[ {"id": "P2", "labels": ["Paper"], "properties": {"title": "Optimizing Queries", "author": "Alex", "score": 9}}, {"id": "P3", "labels": ["Paper"], "properties": {"title": "Path Patterns", "author": "Zack", "score": 7}}, {"id": "P1", "labels": ["Paper"], "properties": {"title": "Efficient Graph Search", "author": "Alex", "score": 6}}, {"id": "P2", "labels": ["Paper"], "properties": {"title": "Optimizing Queries", "author": "Alex", "score": 9}} ]
Returns the nodes of a path as a list. nodes() is a synonym.
| Syntax | pnodes(<pathVar>) | ||
| Arguments | Name | Type | Description |
<pathVar> | PATH | Path variable reference | |
| Return Type | LIST | ||
GQLMATCH p = ({_id: "P1"})->() RETURN pnodes(p)
Result:
JSON[ { "id": "P1", "labels": ["Paper"], "properties": {"score": 6, "author": "Alex", "title": "Efficient Graph Search"} }, { "id": "P2", "labels": ["Paper"], "properties": {"title": "Optimizing Queries", "score": 9, "author": "Alex"} } ]
Returns the edges of a path as a list. relationships() is a synonym.
| Syntax | pedges(<pathVar>) | ||
| Arguments | Name | Type | Description |
<pathVar> | PATH | Path variable reference | |
| Return Type | LIST | ||
GQLMATCH p = ({_id: "P1"})->() RETURN pedges(p)
Result:
JSON[ { "id": "e:1", "label": "Cites", "fromNodeId": "P1", "toNodeId": "P2", "properties": {"weight": 2} } ]
Collects the _id values of nodes in a path into a list.
| Syntax | pnodeIds(<pathAlias>) | ||
| Arguments | Name | Type | Description |
<pathAlias> | PATH | Path alias reference | |
| Return Type | LIST | ||
GQLMATCH p = ({_id: "P1"})-[]->{1,2}() RETURN pnodeIds(p)
Result:
| pnodeIds(p) |
|---|
| ["P1","P2"] |
| ["P1","P2","P3"] |
Collects the _id values of edges in a path into a list.
| Syntax | pedgeUuids(<pathAlias>) | ||
| Arguments | Name | Type | Description |
<pathAlias> | PATH | Path alias reference | |
| Return Type | LIST | ||
GQLMATCH p = ({_id: "P1"})-[]->{1,2}() RETURN pedgeUuids(p)
Result:
| pedgeUuids(p) |
|---|
| ["e:1"] |
| ["e:1","e:2"] |