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.
<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 withinLET
.- 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]
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:6, author:'Zack'}),
(p1)-[:Cites]->(p2),
(p2)-[:Cites]->(p3)
Defining Variables
LET threshold = 6
MATCH (p:Paper) WHERE p.score > threshold
RETURN p.title, p.score - threshold
Result:
p.title | p.score - threshold |
---|---|
Optimizing Queries | 3 |
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.
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:
MATCH (x:Paper)
LET recommended = x.score > 7
RETURN x.title, recommended
It is equivalent to:
MATCH (x:Paper)
CALL (x) {
LET recommended = x.score > 7
RETURN x, recommended
}
RETURN x.title, recommended
Result:
x.title | recommended |
---|---|
Optimizing Queries | true |
Efficient Graph Search | false |
Path Patterns | false |
This query references p
in LET
to compute the length of each path:
MATCH p = ()->{1,2}()
LET length = path_length(p)
RETURN p, length
Result:
p | length |
---|---|
![]() |
1 |
![]() |
1 |
![]() |
2 |