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 Graph
    • Closed Graph
    • Graph Type
    • Constraints
    • Projections
    • Storage Maintenance
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • MERGE
    • SET
    • REMOVE
    • DELETE
    • FOREACH
    • 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
    • Database Functions
  • Operators
  • Predicates
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Expressions
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Execution Plan
  • Backup and Restore
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Naming Conventions
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Expressions

List Expressions

GQL has two expression forms that iterate over a list. They share the <variable> IN <list> shape but produce different things:

FormReturns
List comprehensionA new list
List quantifierA single boolean

List Comprehension

A list comprehension creates a new list by iterating over an existing list, optionally filtering elements and transforming them.

Syntax
<list comprehension> ::=
  "[" <variable> "IN" <list> [ < "WHERE" | "FILTER" > <condition> ] [ "|" <expr> ] "]"

Details

  • <variable>: the iteration variable, bound to each element of <list> in turn.
  • WHERE|FILTER <condition>: optional filter; only elements that meet the condition are included.
  • <expr>: optional transformation. if omitted, the original element is emitted.

Transform each element:

GQL
RETURN [x IN [1, 2, 3, 4, 5] | x * 10]

Result: [10, 20, 30, 40, 50]

Filter elements:

GQL
RETURN [x IN [1, 2, 3, 4, 5] WHERE x > 2]

Result: [3, 4, 5]

Filter and transform:

GQL
RETURN [x IN [1, 2, 3, 4, 5] WHERE x > 2 | x * 10]

Result: [30, 40, 50]

List Quantifiers

Quantifiers reduce a list to a single boolean by testing a condition against its elements.

Syntax
<list quantifier> ::=
  < "ANY" | "ALL" | "NONE" | "SINGLE" > "(" <variable> "IN" <list> "WHERE" <condition> ")"
QuantifierReturns true when …
ANYThe condition holds for at least one element
ALLThe condition holds for every element
NONEThe condition holds for no element
SINGLEThe condition holds for exactly one element
GQL
RETURN ANY(x IN [1, 2, 3] WHERE x > 2),   // true
       ALL(x IN [1, 2, 3] WHERE x > 2),   // false
       NONE(x IN [1, 2, 3] WHERE x > 5),  // true
       SINGLE(x IN [1, 2, 2] WHERE x = 2) // false