sten
sten

Reputation: 7486

MERGE the edges even if the values differ?

the following query will create (n1)->(n2) pair. If the nodes already exists they will be reused.

   match (n1:X),(n2:X) where n1.val = 11 and n2.val = 12 
   merge (n1)-[x:q {val: 0 }]->(n2)

the problem is that if the edge with x.val that is different will create new connection.

Is there a way to disregard it ?

I want a single Query, which sets the value first time its called and afterwards ignore the value... OR I have to have two different queries one to set the pair and second w/o x.val that will just merge ?


this seem to work, but i would hear other possibilities :

        on create set x.val = 0.001

Upvotes: 1

Views: 40

Answers (1)

Christophe Willemsen
Christophe Willemsen

Reputation: 20185

MERGE has a ON CREATE clause that you can use :

MATCH (n1:X),(n2:X) WHERE n1.val = 11 and n2.val = 12 
MERGE (n1)-[x:q]->(n2)
ON CREATE SET x.val = 0

Upvotes: 1

Related Questions