UltipaDocs
Try Playground
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Closed Graph
    • Open Graph
    • Graph Sharding and Storage
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • SET
    • REMOVE
    • DELETE
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Scalar Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Type Conversion Functions
    • Table Functions
    • AI & Vector Functions
    • Database Functions
  • Operators
  • Predicates
  • Expressions
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
    • Process
    • Job
    • Execution Plan
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Functions

List Functions

Example Graph

The following examples run against this graph:

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:

append(myList, "b")
["a",1,2,"b"]

difference()

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

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:

difference(l1, l2)
[1,2,2]

elements()

Returns a list containing the nodes and edges that make up a path.

Syntaxelements(<path>)
ArgumentsNameTypeDescription
<path>PATHThe target path
Return TypeLIST
GQL
MATCH p = ()->()
LET items = elements(p)
FOR item IN items WITH ORDINALITY index
FILTER index %2 = 1
RETURN item

Result: item

_id
_uuidschema
values
P2Sys-genCourse{title: "Optimizing Queries", author: "Alex", score: 9}
P3Sys-genCourse{title: "Path Patterns", author: "Zack", score: 7}
P1Sys-genCourse{title: "Efficient Graph Search", author: "Alex", score: 6}
P2Sys-genCourse{title: "Optimizing Queries", author: "Alex", score: 9}

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:

head(myList)
a

intersection()

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

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:

intersection(l1, l2)
[3,3]

listContains()

Checks whether a specified element exists in a list, returning 1 for true and 0 for false.

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

Result:

listContains(myList, "b")
0

listUnion()

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

SyntaxlistUnion(<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 listUnion(l1, l2)

Result:

listUnion(l1, l2)
[1,2,3,4,5]

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:

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

Result:

totalWeights
3

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

trim()

Removes a specified number of elements from the right end of the list.

Syntaxtrim(<list>, <num>)
ArgumentsNameTypeDescription
<list>LISTThe list to be trimmed
<num>UINTAn integer specifying the number of elements to be removed from the list
Return TypeLIST
GQL
LET myList = [1, 2, null, 3]
RETURN trim(myList, 2)

Result:

TRIM(myList, 2)
[1,2]