Reputation: 703
Hi Have a CSV file and I want to create nodes and relationships simultaneously
Im using below query to create nodes
using PERIODIC COMMIT 1000
load csv from "file:///home/gaurav/sharing/dataframe6.txt" as line fieldterminator" "
MERGE (A :concept{name:line[0]})
WITH line, A
MERGE (B :concept{name:line[1]})
WITH line, A, B
create (A)-[:line[3]]->(B); // This is trouble part
but when I try to create relationship between imported nodes then I get error
Invalid input '[': expected an identifier character, whitespace, '|', a length specification, a property map or ']' (line 7, column 18 (offset: 218))
"create (A)-[:line[3]]->(B);"
Upvotes: 2
Views: 676
Reputation: 11216
If you truly want to create relationship in a dynamic fashion you need to use an APOC procedure, specifically apoc.create.relationship
.
using PERIODIC COMMIT 1000
load csv from "file:///home/gaurav/sharing/dataframe6.txt" as line fieldterminator" "
MERGE (A :concept{name:line[0]})
WITH line, A
MERGE (B :concept{name:line[1]})
WITH line, A, B
CALL apoc.create.relationship(A, line[3], {}, B) YIELD rel
RETURN A,B,rel
Upvotes: 4
Reputation: 6251
A relationship can not contain square brackets as its type name. You're trying to create a "line[3]" relationship between the nodes A and B.
Upvotes: 0