Hi,
I am trying to run following cypher query in Neo4j (version 4.4.5)
CALL
{
MATCH (n:NEO_OBJECT) RETURN n.name
}
WITH n.name
WHERE n.name = 'Test Object 8'
RETURN n.name
However I get the error - "Variable `n` not defined (line 5, column 6 (offset: 54))
"WITH n.name"
I am aware that this problem can be resolved by using “as” with the return clause like “ RETURN n.name as newname” and then use newname with WITH clause.
But if I do not want to use an alias, then is there a way to use WITH clause with a dot(.) as above?
Thanks!
Hi, you can escape the variable in your with/where/return clauses
CALL
{
MATCH (n:NEO_OBJECT) RETURN n.name
}
WITH `n.name`
WHERE `n.name` = 'Test Object 8'
RETURN `n.name`
and then I believe it should work to have the . in the variable name without renaming it explicitly (there is an implicit AS `n.name` in the RETURN in the CALL)
/Therese
This will work:
CALL
{
MATCH (n:NEO_OBJECT) RETURN n
}
WITH n
WHERE n.name = 'Test Object 8'
RETURN n.name
But there is no need to use a call subquery. The following is the proper way:
MATCH (n:NEO_OBJECT)
WHERE n.name = 'Test Object 8'
RETURN n.name
OR, with implied ‘where’ clause:
MATCH (n:NEO_OBJECT {name: 'Test Object 8'})
RETURN n.name
A call subquery is great if you want to run a complex operation on each line of a match result and return just the result. The result can be one or more lines and will be appended with the row of data that involved the call.