Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-20-2022 02:54 AM
Hi, Using Cypher Query, may I know to create a relationship like in the image below while importing csv?
Solved! Go to Solution.
09-28-2022 12:13 AM
LOAD CSV WITH HEADERS FROM 'file:///distance.csv' AS row FIELDTERMINATOR ','
MERGE (a:Country {name: row.`Country 1`})
MERGE (b:Country {name: row.`Country 2`})
MERGE (a)-[r:HAS_DISTANCE]->(b)
SET r.distance = row.`Distance (km)`
09-20-2022 03:53 AM
Hi @mochalla ,
If you want to create a relationship starting and ending in the same node you could do something like this:
MATCH (n:Node {id: "1"})
CREATE (n)-[:RELANTIONSHIP]->(n)
Note: you should use your own property on Node. You should also change the relationship name to a more according one.
Regards
09-20-2022 04:01 AM
For Example If my node label is Airport
And I have distance from one airport to another airport.
Now I want to show this in the format I mentioned
LOAD CSV WITH HEADERS FROM '///filename.csv' AS row
WITH row
MATCH (a:airport {name:row.`Airport Name```)
CREATE (a)-[:DISTANCE]->(a)
09-20-2022 12:20 PM
What error do you see?
09-27-2022 11:49 PM
I see no changes and no records.
09-27-2022 11:58 PM - edited 09-28-2022 12:05 AM
Here is the example data I am sharing.
In the node all the countries are included. Now I want to connect the distance of each country with the relationship. I don't want to create two nodes here.
Example Data
09-28-2022 12:13 AM
LOAD CSV WITH HEADERS FROM 'file:///distance.csv' AS row FIELDTERMINATOR ','
MERGE (a:Country {name: row.`Country 1`})
MERGE (b:Country {name: row.`Country 2`})
MERGE (a)-[r:HAS_DISTANCE]->(b)
SET r.distance = row.`Distance (km)`
09-28-2022 12:27 AM
Getting this error
Invalid input 'r': expected whitespace, '.', node labels or rel types, '[', '^', '*', '/', '%', '+', '-', "=~", IN, STARTS, ENDS, CONTAINS, IS, '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR or AS (line 2, column 198 (offset: 221))
"LOAD CSV WITH HEADERS FROM ''file:///distance.csv''row FIELDTERMINATOR ','"
^
09-28-2022 12:31 AM
I tested the query with your data and it works on my side.
Can you show your query?
09-28-2022 12:42 AM
09-28-2022 12:47 AM
Read all the details here to check if you have the right configuration to import files remotely.
All the sessions of the conference are now available online