Overview
The LET
statement allows you to add columns to the working table by defining new variables. Each variable is assigned a value using the =
operator.
<let statement> ::=
"LET" <variable definition> [ { "," <variable definition> }... ]
<variable definition> ::=
<binding variable> "=" <value expression>
Details
LET
does not change the number of records in the working table.LET
does not modify existing columns in the working 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 with Constants
LET s = 6, a = "Alex"
MATCH (p:Paper) WHERE p.score = s AND p.author = a
RETURN p.title, s, a
Result:
p.title | s | a |
---|---|---|
Efficient Graph Search | 6 | Alex |
Referencing Variables in LET
If any variable is referenced within LET
, the LET
statement is effectively replaced by the following CALL
statement:
"CALL" "(" <referenced variables> ")" "{"
<let statement>
"RETURN" <all variables>
"}"
Details
<referenced variables>
is the comma-separated list of all variables referenced within theLET
statement.<all variables>
is the comma-separated list of all variables contained in theLET
statement.
This query references x
in LET
and determines whether its score
property grater 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 | 1 |
Efficient Graph Search | 0 |
Path Patterns | 0 |
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 |