Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-16-2022 03:53 AM - edited 08-16-2022 04:12 AM
Hi,
I run query as below but it shows (no changes, no records). Am i doing something wrong? i RETURN * and it shows some values but it does not record to graph.
Thank you for your help!
LOAD CSV WITH HEADERS FROM "file:///rel_company_to_account.csv" AS line
Solved! Go to Solution.
08-16-2022 06:28 AM - edited 08-16-2022 06:29 AM
Try this. I am assuming the account and company nodes already exist in your database. If not, change the 'match' clauses to 'merge' clause to create them when they do not.
:auto LOAD CSV WITH HEADERS FROM "file:///rel_company_to_account.csv" AS line
CALL {
WITH line
MATCH (a:Company {company_number: line.company_number})
MATCH (b:Accounts {account_number: line.account_number})
MERGE (a)-[c:REPORTED{date: date(line.date)}]->(b)
ON CREATE SET c.date= date(line.date)
return a, b
} IN TRANSACTIONS OF 10000 ROWS
return a, b
To address the error you received, you need to return the nodes 'a' and 'b' from the inner query so they are visible in the outer query.
08-16-2022 04:22 AM
From what is shown, your query does not return any nodes, so you will not get the ‘graph’ button in the results section. You can return ‘a’ and ‘b’ if you want to see them. You can also query after to see them.
Is there more to your query not shown that gives the output shown? It seems to be returning ‘line?’
I noticed in the few rows of ‘line’ being displayed that company_number and account_number repeat across lines and the different is the date. If this is accurate, then your query should result in only one relationship between a pair off company and accounts, where the relation date should equal the last date imported. Is this the behavior you want, or do you want a separate relationship for each date? If you want a new relationship for each date, you need to update your merge to look for relationship ‘c’ where ‘c.date = date(line.date)’, so it doesn’t match if the date is new and creates a new relationship. Also, you would not need to set the date on a match, as the relation has the existing date and you are not updating other properties.
08-16-2022 04:57 AM
thank you very much for your help. i had nodes updated, Company and Accounts nodes are both updated
the dates are corrected and i want separate relationship for each date. I am very new to neo4j so i very much appreciate if you can guide me little bit more detail. when i return a, it says as below
08-16-2022 06:28 AM - edited 08-16-2022 06:29 AM
Try this. I am assuming the account and company nodes already exist in your database. If not, change the 'match' clauses to 'merge' clause to create them when they do not.
:auto LOAD CSV WITH HEADERS FROM "file:///rel_company_to_account.csv" AS line
CALL {
WITH line
MATCH (a:Company {company_number: line.company_number})
MATCH (b:Accounts {account_number: line.account_number})
MERGE (a)-[c:REPORTED{date: date(line.date)}]->(b)
ON CREATE SET c.date= date(line.date)
return a, b
} IN TRANSACTIONS OF 10000 ROWS
return a, b
To address the error you received, you need to return the nodes 'a' and 'b' from the inner query so they are visible in the outer query.
08-16-2022 06:36 AM
it works now, thank you very much! my CSV file have rows with empty date, i deleted the rows and it works.
,company_number,account_number,date
0,106623,,
1,10892853,10892853,2020-12-31
2,10892853,10892853,2021-12-31
3,11454668,11454668,2020-12-31
4,11454668,11454668,2021-12-31
5,11454694,11454694,2019-10-31
6,11454694,11454694,2020-10-31
7,11454694,11454694,2021-10-31
8,11454702,11454702,2021-04-30
9,11454702,11454702,2022-04-30
10,11467412,11467412,2021-03-31
11,11467412,11467412,2022-03-31
12,11467514,11467514,2021-03-31
13,11502600,,
14,11502632,,
15,11502940,,
08-16-2022 06:42 AM
That is great. BTW- you can modify the query to skip the lines that have missing data.
08-16-2022 06:47 AM
yesss i add to the query. thank you so much!!!
All the sessions of the conference are now available online