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.

Allow null when create relations

jzhou002
Node Link

I need to create company and parent company relations from a json file, however some companies do not have parent companies, like this example
{ "company_id" : 2032,
"parent_company_id" : 343
}
{ "company_id" : 2332,
"parent_company_id" :
}

It is possible to create company-paranet company relation when a company has parent company, skip the company if it does not have parent company or substitute null with some characters?
Thanks.

2 REPLIES 2

Hi @jzhou002 ,

Welcome to the Graph Community.

I tried this with the below sample data and query :

{
"company_id" : 2032,
"parent_company_id" : 343
}
{
"company_id" : 2332,
"parent_company_id" :0
}

QUERY :

call apoc.load.json("file:///testjson.json")
yield value AS row
WITH row where row.parent_company_id<>0
MERGE(c:Company{companyId:row.company_id})-[:HAS_PARENT]->(pc:Company{companyId:row.parent_company_id})
RETURN c,pc

Below is the output :

3X_6_b_6bed3e0391ffabef761d7b57a972d3830d312209.png

Please let me know if this is what you need or did I miss anything.

jzhou002
Node Link

Oh cool. Thank you very much. I am new to cypher, a lot to learn.