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
    • Graph Patterns
    • Overview
    • Open Graph
    • Closed Graph
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • 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
    • 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
    • AI & Vector Functions
    • Database Functions
  • Operators
  • Predicates
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Comprehension
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Backup and Restore
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Expressions

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 in <list> in turn.
  • WHERE|FILTER <condition>: optional filter; only elements that meet the condition are included.
  • <expr> transforms each element. If omitted, returns the original element.

Examples

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]