I want to run the below query for numbers 1 through 14 i.e quantity1 to quantity14 -
LOAD CSV WITH HEADERS FROM '<path>' AS row
WITH row WHERE row.quantity1 IS NOT NULL
MATCH (m:main {main_id: row.main})
MERGE (q:quantity {quantity : row.quantity1})
MERGE (m)-[:main_has_quantity]->(q);
What the command does : The command reads a csv, creates the quantity node if it is not null and if doesn't already exist and then creates a relationship between the quantity node and it's corresponding main node. I want to do this for columns quantity1 through quantity14 in the csv.
I tried to use UNWIND and FOREACH and both commands throw errors :
LOAD CSV WITH HEADERS FROM '<path>' AS row
UNWIND range(1,14) as i
WITH row WHERE row.quantity+toString(i) IS NOT NULL
MATCH (m:main {main_id: row.main})
MERGE (q:quantity {quantity : row.quantity+toString(i)})
MERGE (m)-[:main_has_quantity]->(q);
I got the error "Variable i
not defined (line 5, column 37 (offset: 246))
"MERGE (q:quantity {quantity : row.quantity+toString(i)})" "
I used FOREACH in place of UNWIND. That did not work because I cannot use WITH clause inside FOREACH.
How best to achieve the result I am looking for?
P.S I am using the Neo4j community version.
Regards,
AK