Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cypher: variable not define in apoc.do.case

I am trying to use apoc.do.case to create some relationship, depending if a row in a file exist using the WITH after reading the CSV

However, it seems like the "row" cannot be passed into the case

My attempt:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

LOAD CSV WITH HEADERS FROM 'url' AS row
MERGE (i:Investor {Name: row.Investor_Name})
MERGE (ir:Investment_Round {id: row.Deal_ID})
 WITH row, i, ir
CALL apoc.do.case([
        row.Funds_Used IS NULL,
    'MERGE (i)-[r:INVESTED_IN]->(ir) SET r.Investment_Size_million_GBP=toFloat(row.Investment_Size_million_GBP), r.Investment_Size_million_EUR=toFloat(row.Investment_Size_million_EUR)',
    row.Funds_Used IS NOT NULL, 'MERGE (f:Fund {Name: row.Funds_Used}) WITH row, f, i, ir MERGE (i)-[r:HAS_FUND]->(f) MERGE (f)-[r2:INVESTED_IN]->(ir) SET r2.Investment_Size_million_GBP = row.Investment_Size_million_GBP, r2.Investment_Size_million_EUR = row.Investment_Size_million_EUR;'])
YIELD value RETURN value;

The error:

Failed to invoke procedure `apoc.do.case`: Caused by: org.neo4j.exceptions.SyntaxException: Variable `row` not defined (line 1, column 75 (offset: 74))
"MERGE (i)-[r:INVESTED_IN]->(ir) SET r.Investment_Size_million_GBP=toFloat(row.Investment_Size_million_GBP), r.Investment_Size_million_EUR=toFloat(row.Investment_Size_million_EUR)"
                                                                         

>Solution :

You are not passing the row variable as a parameter. Try this:

LOAD CSV WITH HEADERS FROM 'url' AS row
MERGE (i:Investor {Name: row.Investor_Name})
MERGE (ir:Investment_Round {id: row.Deal_ID})
WITH row, i, ir
CALL apoc.do.case([
     row.Funds_Used IS NULL,
    'MERGE (i)-[r:INVESTED_IN]->(ir) 
     SET r.Investment_Size_million_GBP=toFloat(row.Investment_Size_million_GBP), r.Investment_Size_million_EUR=toFloat(row.Investment_Size_million_EUR)',
     row.Funds_Used IS NOT NULL, 
    'MERGE (f:Fund {Name: row.Funds_Used}) WITH row, f, i, ir MERGE (i)-[r:HAS_FUND]->(f) MERGE (f)-[r2:INVESTED_IN]->(ir) SET r2.Investment_Size_million_GBP = row.Investment_Size_million_GBP, r2.Investment_Size_million_EUR = row.Investment_Size_million_EUR;'],
    '', 
    {row: row, i: i, ir: ir}) // The parameters are passed here
YIELD value RETURN value;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading