Hello all,
I'm using neo4j desktop version 1.6.1 and I want to import data from a SQL database into Neo4J. I exported some tables into CSV format and tried to ingest the data into Neo4j Desktop. Below are a couple of samples from those files:
-
Sample of 'companies.csv':
id,name,country_id
1,AAA,2
2,BBB,3
3,CCC,1 -
Sample of 'countries.csv':
id,name,currency_code,country_code
1,Sweden,SEK,SE
2,Denmark,DKK,DK
3,United States of America,USD,US
I have no problems creating the nodes with the following code:
// ==================== Load Country's nodes ====================
LOAD CSV WITH HEADERS FROM "file:///countries.csv" AS row
WITH
toInteger(row.id) as id,
row.name as name,
row.currency_code as currency_code,
row.country_code as country_code
MERGE (country:Country {countryID:id})
ON CREATE SET
country.name = name,
country.currency_code = currency_code,
country.country_code = country_code
RETURN COUNT(country);
// ==============================================================
// ================ Load Company's nodes ========================
LOAD CSV WITH HEADERS FROM "file:///companies.csv" AS row
WITH
toInteger(row.id) as id,
row.name as name
MERGE (company:Company {companyID:id})
ON CREATE SET
company.name = name,
RETURN COUNT(company);
// ==============================================================
My problem starts when trying to create the relationship between them as:
// ==== Create relationships between Companies and Countries ====
LOAD CSV WITH HEADERS FROM "file:///companies.csv" AS row
WITH toInteger(row.country_id) as country_id
MATCH (company:Company)
MATCH (country:Country {countryID: country_id})
MERGE (company)-[:LOCATED_IN]->(country);
// ==============================================================
The result is that all companies are "LOCATED_IN" in all countries
What am I doing wrong, and how should I fix this? Thanks in advance for your help.
Boris