UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Questioned Paths
    • Shortest Paths
    • Cheapest Paths
    • K-Hop Traversal
    • Graph Patterns
    • Overview
    • Open Graphs
    • Closed Graphs
    • Graph Types
    • Constraints
    • Projections
    • Storage Maintenance
    • Node and Edge IDs
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • MERGE
    • SET
    • REMOVE
    • DELETE
    • FOREACH
    • LOAD CSV
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Element Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Null Functions
    • Utility Functions
    • Type Conversion Functions
    • Table Functions
  • Operators
  • Predicates
    • Overview
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Expressions
    • Current Values
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Execution Plan
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Naming Conventions
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Functions

Path Functions

Example Graph

GQL
INSERT (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)

path_length()

Returns the number of edges in a path. length() is a synonym.

Syntaxpath_length(<pathVar>)
ArgumentsNameTypeDescription
<pathVar>PATHPath variable reference
Return TypeUINT
GQL
MATCH p = ()->{1,3}()
RETURN p, path_length(p) AS length

Result:

plength
2
1
1

elements()

Returns a list containing the nodes and edges that make up a path, interleaved in order.

Syntaxelements(<pathVar>)
ArgumentsNameTypeDescription
<pathVar>PATHPath variable reference
Return TypeLIST
GQL
MATCH 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}}
]

pnodes()

Returns the nodes of a path as a list. nodes() is a synonym.

Syntaxpnodes(<pathVar>)
ArgumentsNameTypeDescription
<pathVar>PATHPath variable reference
Return TypeLIST
GQL
MATCH 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"}
  }
]

pedges()

Returns the edges of a path as a list. relationships() is a synonym.

Syntaxpedges(<pathVar>)
ArgumentsNameTypeDescription
<pathVar>PATHPath variable reference
Return TypeLIST
GQL
MATCH p = ({_id: "P1"})->()
RETURN pedges(p)

Result:

JSON
[
  {
    "id": "e:1",
    "label": "Cites",
    "fromNodeId": "P1",
    "toNodeId": "P2",
    "properties": {"weight": 2}
  }
]

node_ids()

Collects the _id values of nodes in a path into a list. pnodeIds() is a synonym.

Syntaxnode_ids(<pathAlias>)
ArgumentsNameTypeDescription
<pathAlias>PATHPath alias reference
Return TypeLIST
GQL
MATCH p = ({_id: "P1"})-[]->{1,2}()
RETURN node_ids(p)

Result:

node_ids(p)
["P1","P2"]
["P1","P2","P3"]

edge_ids()

Collects the _id values of edges in a path into a list. pedgeUuids() is a synonym.

Syntaxedge_ids(<pathAlias>)
ArgumentsNameTypeDescription
<pathAlias>PATHPath alias reference
Return TypeLIST
GQL
MATCH p = ({_id: "P1"})-[]->{1,2}()
RETURN edge_ids(p)

Result:

edge_ids(p)
["e:1"]
["e:1","e:2"]

ids()

Generic ID accessor that works on a path, a single node/edge, or a list of nodes/edges. Returns:

  • For a path: a flat list of _id values, with nodes and edges interleaved in path order.
  • For a single node or edge: the element's _id as a string.
  • For a list of nodes/edges: a list of their _id values (preserving null slots).
Syntaxids(<expr>)
ArgumentsNameTypeDescription
<expr>PATH, NODE, EDGE, or LIST<NODE|EDGE>The input expression
Return TypeSTRING or LIST<STRING>
GQL
MATCH p = ({_id: "P1"})-[]->()
RETURN ids(p)

Result:

ids(p)
["P1","e:1","P2"]