Use WITH to make a smaller, more easily understood question

In one question, a poster had all this complex Cypher code to set up his problem about dealing with an expression.

After some pondering, I realized it would be much easier to use a WITH statement to assign a variable instead of having a ton of Cypher code to extract the variable and then try to get an answer.

For example, a person might ask, "how do you convert a string to a float"?

It's easier to set it up this way:

WITH "3.1415" AS pi  // Note that this doesn't work: SET pi = "3.1415" 
RETURN toFloat(pi) // The answer
1 Like

Comes in handy in a number of situations, e.g. when you need to test processing of a JSON object:

WITH apoc.convert.fromJsonMap('{"a":1, "b":2, ...}') as payload
RETURN payload.a

Comes in handy in other situations too when you want to chain things together.

MATCH (x:MyThing)
WITH x.myThing as inputValue
CALL myCustomProcedure(inputValue)
1 Like