cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

clem
Graph Steward

The documentation for FOREACH seems incomplete:

FOREACH - Neo4j Cypher Manual. e.g. it's missing REMOVE as a possible command inside FOREACH.

I was doing trial and error with FOREACH and I discovered a bad syntax error message.

(don't laugh...). I tried out this code:

MATCH (boo:Bucket {Name:"boo"}) 
MATCH (b:Bucket) 
FOREACH (key in keys(boo) | toUpper(b[key]))
RETURN 2

and I got this error msg:

Invalid input 'toUpper': expected 
  "RETURN"
  "CREATE"
  "DELETE"
  "SET"
  "REMOVE"
  "DETACH"
  "MATCH"
  "WITH"
  "UNWIND"
  "USE"
  "CALL"
  "LOAD"
  "FROM"
  "FOREACH"
  "MERGE"
  "OPTIONAL" (line 3, column 31 (offset: 85))
"FOREACH (key in keys(boo) | toUpper(b[key]))"

but I know that list is wrong for FOREACH because I've seen in a number of places where people are warning that MATCH cannot be used inside FOREACH. (The documentation should probably make that explicit.)

When I tweak the code:

MATCH (boo:Bucket {Name:"boo"}) 
MATCH (b:Bucket) 
FOREACH (key in keys(boo) | RETURN toUpper(b[key]))

I get Neo.ClientError.Statement.SyntaxError with a pointer to RETURN.

So, the first error message is wrong in claiming RETURN and MATCH are possible.

In this post, it is noted that REMOVE (which is not mentioned in the documentation) is allowed but that APOC CALLs are not.

I presume if DELETE is allowed then DETACH should be.

Now I am not sure what the complete list of allowed commands inside a FOREACH actually is.

So, the error message needs to be updated to include only the allowed commands inside FOREACH as well as the documentation.

(I'm not sure why there such restrictions on FOREACH.)