cn0047
cn0047

Reputation: 17091

Variable in neo4j query

Is it possible to use variable in query?

For example :

SET @id = 1;
SELECT @id;
+------+
| @id  |
+------+
|    1 |
+------+

Is it possible to do something similar in , 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

Answers (1)

cybersam
cybersam

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

Related Questions