Reputation: 17091
Is it possible to use variable in neo4j query?
For example mysql:
SET @id = 1;
SELECT @id;
+------+
| @id |
+------+
| 1 |
+------+
Is it possible to do something similar in neo4j, like:
SET @id = 1;
WITH @id as id RETURN id;
PS: Reason - I have big and complicated query and to run this query couple times with different params I have to manually replace values in query, which is not efficient.
With these variables I wouldn't need to change query, just update variables values...
Upvotes: 0
Views: 765
Reputation: 67044
You can pass parameters to a Cypher query. For example, if id
is passed in as a parameter:
:param id => 1
RETURN $id
[UPDATE]
If a parameter (say, propName
) specifies a property name, then you can use the n[$propName]
syntax to get the specified property from n
. But to set the property value you could use APOC procedures like apoc.create.setProperty.
Upvotes: 2