cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

How to create a node only if a property exist in csv import

farrukhjalali
Node Link

I am a newbie to Neo4j. I am importing data from a CSV file and want to create a nodes for Email and Phone number separately only if these columns are not null. So if I am creating say

load csv with headers from "file:///af_20211014.csv" as csv merge (e : Email {email: csv.email})

It is generating an error when the email column is empty. How to overcome that?

Extending on the above, how can I use a cypher to not create a field in a node if the value is not present in CSV column. To be specific, here is the query I am currently using to create a Person node from same above file and I don't want to use coalesce, in case of null, jus don't create the property ; merge (p : Person {full_name: coalesce(csv.full_name,'BLANK'), dob: coalesce(date(csv.dob),'No DOB')})

1 REPLY 1

ameyasoft
Graph Maven
Try this:

load csv with headers from "file:///af_20211014.csv" as csv 

FOREACH(ignoreMe IN CASE WHEN csv.email is not null THEN [1] ELSE [] END|

	merge (e : Email {email: csv.email})
	
)	

FOREACH(ignoreMe IN CASE WHEN csv.full_name is not null and csv.dob is not null THEN [1] ELSE [] END|

	 merge (p : Person {full_name: csv.full_name, dob: date(csv.dob})
	
)	

FOREACH(ignoreMe IN CASE WHEN csv.full_name is not null and csv.dob is null THEN [1] ELSE [] END|

	 merge (p : Person {full_name: csv.full_name}
	
)	

FOREACH(ignoreMe IN CASE WHEN csv.full_name is null and csv.dob is not null THEN [1] ELSE [] END|

	 merge (p : Person {dob: date(csv.dob})
	
)