neo4jcypherneo4j-apoc

How to stack consecutive APOC statements in Neo4j Cypher


I stumbled on the following syntax for setting labels during a LOAD CSV operation in Neo4j with Cypher. It works but I don't understand why, and all of the following modifications break it:

Can anyone enlighten me? I'm a relative newcomer to Cypher and APOC and I'd love to understand how to make repeated APOC calls properly.

LOAD CSV WITH HEADERS FROM 'file:///myfile.csv' AS row
MERGE (n:Person{id:row.ID,name:row.Name}) 
WITH n,row
CALL apoc.create.addLabels(id(n), [row.Title,row.Position] YIELD node
WITH n,row
CALL apoc.create.addLabels(id(n), split(row.Roles, ',')) YIELD node 
WITH n,row
CALL apoc.create.addLabels(id(n), split(row.Aliases, ',')) YIELD node

Solution

  • You should read the documentation for CALL, WITH, and UNION.

    Here are answers to your specific questions: