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
  • Query Management
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Querying

LET

Overview

The LET statement allows you to define new variables and adds corresponding columns to the intermediate result table. Each variable is assigned a value using the = operator.

Syntax
<let statement> ::= 
  "LET" <let variable definition> [ { "," <let variable definition> }... ]

<let variable definition> ::= 
    <binding variable> "=" <value expression>
  | <value variable definition>
    
<value variable definition> ::=
  "VALUE" <binding variable> [ "TYPED" ] <value type> "=" <value expression>

Details

  • LET does not change the number of records in the intermediate result table.
  • LET does not modify existing columns in the intermediate result table unless you re-define existing variables within LET.
  • You cannot define a new variable and reference it within the same LET.

Example Graph

CREATE GRAPH myGraph { 
  NODE Paper ({title string, score uint32, author string}),
  EDGE Cites ()-[{}]->()
} PARTITION BY HASH(Crc32) SHARDS [1]

Defining Variables

GQL
LET threshold = 6
MATCH (p:Paper) WHERE p.score > threshold
RETURN p.title, p.score - threshold

Result:

p.titlep.score - threshold
Optimizing Queries3

Defining Value Variables

You can define a value varible with a specified type. The engine will then validate whether the assigned value is either already of that type or can be safely cast to it. If the value cannot be cast to the specified type, an exception will be thrown at runtime.

GQL
LET VALUE x TYPED INT = 28
RETURN 28

Result:

x
28

This approach ensures type safety in your queries and helps catch incorrect data types early during execution.

Referencing Variables in LET

If any variable is referenced within LET, it will evaluate row by row over the records of that variable.

This query references x in LET and determines whether its score property is greater than 7:

GQL
MATCH (x:Paper)
LET recommended = x.score > 7
RETURN x.title, recommended

It is equivalent to:

GQL
MATCH (x:Paper)
CALL (x) {
  LET recommended = x.score > 7
  RETURN x, recommended
}
RETURN x.title, recommended

Result:

x.titlerecommended
Optimizing Queriestrue
Efficient Graph Searchfalse
Path Patternsfalse

This query references p in LET to compute the length of each path:

GQL
MATCH p = ()->{1,2}()
LET length = path_length(p)
RETURN p, length

Result:

plength
1
1
2