cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Query to update/add data from csv file after bulk insertion

Hi,
I have a same dataset using
"""LOAD CSV WITH HEADERS FROM 'file:///{}' AS row
CREATE(n:{})
SET n=row;""".format(source_path+file_name,table_name)
the above query i have done initial load of dataset.

for the second load (in which i have few new records+updated records) from existing table,
how could i load the second set of data into the same table.

I tried to use match and merge query.
"""LOAD CSV WITH HEADERS FROM 'file:///{}' AS row
WHERE row.customer_id IS NOT NULL
MERGE(c:initial_load_customer
{customer_id:row.customer_id})""".format(source_path+file_name)

i got an error message as
Traceback (most recent call last):
File "C:/Users/lenovo/PycharmProjects/header comparison/csv_neo4j.py", line 27, in
MERGE(c:initial_load_customer {customer_id:row.customer_id})""".format(source_path+file_name)
KeyError: 'customer_id'

Do my second load query is wrong or else is there any way i can create a node if id doesnt exist, else if node exist update(update all the columns with values in recent file) the node with property available in csv file.

1 REPLY 1

amsilf
Node Clone

Merge actually creates a node if it doesn't exists; in the merge statement you also can specify data modification on required action, please check neo4j merge documentation - https://neo4j.com/docs/cypher-manual/current/clauses/merge/
Your last query seems arises from pandas, but not from neo4j insertion. Could you please confirm it?