Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Create edges and their labels from LOAD CSV

Node Link

I want to create a set of edges using LOAD CSV. I want their labels to be parameters from the file. I naively tried this:

LOAD CSV WITH HEADERS FROM "file:///edges.csv" AS row
MATCH(node1:row.tag1 {name:row.name1}),(node2:row.tag2 {name:row.name2}) CREATE (node1)-[:edge {carries:row.carries}]->(node2);

This is the error I get:

# ERROR Neo.ClientError.Statement.SyntaxError
# Invalid input '.': expected "$", ")" or "{" (line 2, column 16 (offset: 70))
# "MATCH(node1:row.tag1 {name:row.name1}),(node2:row.tag2 {name:row.name2}) CREATE (node1)-[:edge {carries:row.carries}]->(node2);"
#                 ^

Can someone suggest a way to label edges using LOAD CSV? Thanks!



Per Parameters - Neo4j Cypher Manual

Parameters cannot be used for the following constructs, as these form part of 
the query structure that is compiled into a query plan:

* property keys; so, MATCH (n) WHERE n.$param = 'something' is invalid
* relationship types
* labels

so the failure you encounter is expected. And also to allow for parameters to be used for labels would prove challenging from a query planner perspective. If row1 of the csv had a row.tag1 of :Person and this label had 4 indexes on properties, a,b,c,d but row 2 of the csv had a row.tag1 of :Movie and this label had 2 indexes on properties x and y I'm not sure how the planner would ever figure out how to plan.

Thank you. Is there a suggested or commonly accepted work around?