User-defined variables¶
User-defined variables allows passing the result of one statement to another.
OpenCypher variables¶
In openCypher, when you refer to a variable of vertex, edge or path, you need to name it first. The name you give to the pattern is a variable. For example:
nebula> MATCH (v:player{name:"Tim Duncan"}) RETURN v;
+----------------------------------------------------+
| v |
+----------------------------------------------------+
| ("player100" :player{name: "Tim Duncan", age: 42}) |
+----------------------------------------------------+
The user-defined variable in the preceding query is v
.
nGQL extensions¶
User-defined variables are written as $var_name
. The var_name
consists of letter, number or underline characters. Any other characters are not permitted.
User-defined variables can only be used in one execution. For example, you can use user-defined variables in composite queries separated by semicolon ;
or pipe |
. Details about composite queries, see Composite queries.
NOTE: A user-defined variable is valid only at the current session and execution.
A user-defined variable in one statement CANNOT be used in either other clients or other executions. The statement that defines the user-defined variable and the statement that uses it must be submitted together. When this session ends, the user-defined variable is automatically expired.
NOTE: User-defined variables are case-sensitive.
Example¶
nebula> $var = GO FROM "player100" OVER follow YIELD follow._dst AS id; \
GO FROM $var.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+---------+-------------+
| Team | Player |
+---------+-------------+
| Nuggets | Tony Parker |
+---------+-------------+