The LET value expression allows you to define variables and use them immediately in an expression. It can be used for improving readability and simplifying more complex expressions.
<let value expression> ::=
"LET" <let variable definition list> "IN" <value expression> "END"
<let variable definition list> ::=
<let variable definition> [ { "," <let variable definition> }... ]
<let variable definition> ::= <binding variable> "=" <value expression>
Example Graph
The following examples run against this graph:
To create this graph, run the following query against an empty graph:
INSERT (p1:Paper {_id:'P1', title:'Efficient Graph Search', score:6, author:'Alex', publisher:'PulsePress'}),
(p2:Paper {_id:'P2', title:'Optimizing Queries', score:9, author:'Alex'}),
(p3:Paper {_id:'P3', title:'Path Patterns', score:7, author:'Zack', publisher:'BrightLeaf'}),
(p1)-[:Cites {weight:2}]->(p2),
(p2)-[:Cites {weight:1}]->(p3)
Examples
RETURN LET x = 2, y = 1 IN x^2+y END AS result
Result:
result |
---|
5 |
MATCH (n:Paper)
RETURN n.title, LET plus = 1 IN n.score + plus END AS newScore
Result:
n.title | newScore |
---|---|
Optimizing Queries | 10 |
Efficient Graph Search | 7 |
Path Patterns | 8 |