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
    • Count 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

List 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)

head()

Returns the first element in a list.

Syntaxhead(<list>)
ArgumentsNameTypeDescription
<list>LISTThe target list
Return TypeSTRING
GQL
LET myList = ["a", 1, 2]
RETURN head(myList)

Result: "a"

last()

Returns the last element of a list.

Syntaxlast(<list>)
ArgumentsNameTypeDescription
<list>LISTThe input list
Return TypeType of the last element
GQL
RETURN last([1, 2, 3])

Result: 3

tail()

Returns all elements of a list except the first.

Syntaxtail(<list>)
ArgumentsNameTypeDescription
<list>LISTThe input list
Return TypeLIST
GQL
RETURN tail([1, 2, 3, 4])

Result: [2, 3, 4]

size()

Returns the number of elements in a list.

Syntaxsize(<list>)
ArgumentsNameTypeDescription
<list>LISTThe target list
Return TypeUINT
GQL
LET myList = [1, 2, null, 3]
RETURN size(myList)

Result:

size(myList)
4

reverse()

Returns a list with elements in reversed order.

Syntaxreverse(<list>)
ArgumentsNameTypeDescription
<list>LISTThe input list
Return TypeLIST
GQL
RETURN reverse([1, 2, 3])

Result: [3, 2, 1]

append()

Adds an element to the end of a list and returns the new list.

Syntaxappend(<list>, <elem>)
ArgumentsNameTypeDescription
<list>LISTThe target list
<elem>AnyThe element to be added
Return TypeLIST
GQL
LET myList = ["a", 1, 2]
RETURN append(myList, "b")

Result: ["a",1,2,"b"]

range()

Generates a list of integers from start to end (inclusive), with an optional step.

Syntaxrange(<start>, <end> [, <step>])
ArgumentsNameTypeDescription
<start>INTStart value (inclusive)
<end>INTEnd value (inclusive)
<step>INTStep increment (default: 1)
Return TypeLIST<INT>
GQL
RETURN range(1, 5), range(0, 10, 3)

Result: [1, 2, 3, 4, 5], [0, 3, 6, 9]

list_contains()

Returns true if a value exists in a specified list.

Syntaxlist_contains(<list>, <value>)
ArgumentsNameTypeDescription
<list>LISTThe list to be checked
<value>AnyThe value to look for in <list>
Return1 or 0
GQL
LET myList = ["a", 1, 2]
RETURN list_contains(myList, "b")

Result: false

list_union()

Returns the union of two lists, producing a new list of elements from either input list. Duplicates are removed.

Syntaxlist_union(<list_1>, <list_2>)
ArgumentsNameTypeDescription
<list_1>LISTThe first list
<list_2>LISTThe second list
Return TypeLIST
GQL
LET l1 = [1,2,2,3], l2 = [3,4,5]
RETURN list_union(l1, l2)

Result: [1,2,3,4,5]

intersection()

Returns the intersection of two lists, producing a new list of elements common to both. Duplicates are removed.

Syntaxintersection(<list_1>, <list_2>)
ArgumentsNameTypeDescription
<list_1>LISTThe first list
<list_2>LISTThe second list
Return TypeLIST
GQL
LET l1 = [1,2,3,3], l2 = [3,3,4,5]
RETURN intersection(l1, l2)

Result: [3]

difference()

Returns the difference between two lists, producing a new list of elements found in the first list but not in the second. Duplicates are removed.

Syntaxdifference(<list_1>, <list_2>)
ArgumentsNameTypeDescription
<list_1>LISTThe first list
<list_2>LISTThe second list
Return TypeLIST
GQL
LET l1 = [1,2,2,3], l2 = [3,4,5]
RETURN difference(l1, l2)

Result: [1,2]

list_sort()

Sorts a list.

Syntaxlist_sort(<list> [, <order> [, <nullOrder>]])
ArgumentsNameTypeDescription
<list>LISTThe input list
<order>STRING"asc" (default) or "desc"
<nullOrder>STRING"first" or "last"
Return TypeLIST
GQL
RETURN list_sort([3, 1, 4, 1, 5])

Result: [1, 1, 3, 4, 5]

list_filter()

Filters a list of records, nodes, or edges by checking a property against a value using an operator.

Syntaxlist_filter(<list>, <propertyName>, <operator>, <value>)
ArgumentsNameTypeDescription
<list>LISTA list of maps, nodes, or edges
<propertyName>STRINGThe property name to filter on
<operator>STRINGComparison operator: `"="`, `">"`, `"<"`, `">="`, `"<="`, `"<>"`
<value>AnyThe value to compare against
Return TypeLIST
GQL
LET papers = VALUE { MATCH (n:Paper) RETURN collect_list(n) }
RETURN list_filter(papers, "score", ">", 7)

Result:

JSON
[
  {"id": "P2", "labels": ["Paper"], "properties": {"title": "Optimizing Queries", "score": 9, "author": "Alex"}}
]

reduce()

Performs a calculation iteratively using each element in a list. With a specified intital value, the defined calculation takes the first element in the list as input.

Syntaxreduce(<resAlias> = <initVal>, <elemAlias> in <list> | <calcExp>)
ArgumentsNameTypeDescription
<resAlias>/The alias representing the initial, intermediate and final calculation result
<initVal>/The initial value assigned to <resAlias>
<elemAlias>/The alias representing each element in the list
<list>LISTThe target list
<calcExp>/The calculation expression
Return TypeSTRING
GQL
LET myList = [1,3,5]
RETURN reduce(_sum = 0, item in myList | _sum + item) AS listSum

Result: 9

GQL
MATCH p = ({_id: "P1"})-[edges]->{2}()
RETURN reduce(total = 0, edge in edges | total + edge.weight)

Result: 3