Can not write relationship, (no changes, no records)

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

                CALL {

                    WITH line

                    MATCH (a:Company {company\_number: line.company\_number}), (b:Accounts {account\_number: line.account\_number})

                    MERGE (a)-\[c:REPORTED\]->(b)

                        ON CREATE 

                            SET c.date\= date(line.date)

                        ON MATCH

                            SET c.date\= date(line.date)

                    } IN TRANSACTIONS OF 10000 ROWS

maiadsp_0-1660647015226.png

maiadsp_0-1660648342002.png

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.

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

maiadsp_0-1660650803379.png

maiadsp_1-1660651047910.pngmaiadsp_2-1660651069049.png

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.

Screen Shot 2022-08-16 at 9.29.31 AM.png

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,,

That is great. BTW- you can modify the query to skip the lines that have missing data.

yesss i add to the query. thank you so much!!!

AS line WITH line WHERE NOT {self._add_caster(right_identifier)} IS NULL