Neo.ClientError.Statement.SemanticError: Cannot merge node using null property value for Id

Viewed 2914

Im using this query to create some relations , but i need to create node if it doesnt exist but the merge property creates for some and for other records it gives null on id for merge.

Basically if the record exists it should merge else it should create how do i do it?

MATCH (p:person{username:'abc.com'})-[hc:HAS_RELATION]->(pp:person{username:'xyz.com'}) 
    MERGE (con:ContactInfo{Id:hc.ContactInfoId})
    ON MATCH SET con.Updated=timestamp(),hc.ContactInfoId=ID(con) 
    ON CREATE SET con:PersonContact,con.Created =timestamp(),con.Id=ID(con),hc.ContactInfoId=ID(con) 
    WITH con

Please help

1 Answers

You are doing MERGE (con:ContactInfo{Id:hc.ContactInfoId}), but if the hc.ContactInfoIdis NULL, you will obtain yours error.

So this mean that you have a relationship HAS_RELATION in your graph without a ContactInfoId property.

To avoid your error, you can use the coalesce function in cypher. This function takes 2 args : if the first one is NULL, ten the function returns the second.

So perhaps you can use this merge : MERGE (con:ContactInfo{Id:coalesce(hc.ContactInfoId, id(hc))})

Related