Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge where alternative and multiple conditions

Tags:

neo4j

cypher

So as far as I can tell, it is not possible to use where in a merge statement. Then how do I do multiple conditions?

What I want to achieve, but cannot work:

MERGE (n:Node) 
WHERE n.key = "test1" OR n.key = "test2"
ON CREATE n.key = "test1"
return n

So how do I create an or condition on my merge statement? Or is there a better way to do it?

like image 863
Jens Mikkelsen Avatar asked Dec 07 '25 11:12

Jens Mikkelsen


1 Answers

It does not look like MERGE supports the WHERE clause. However, you can specify ONE test value per property; for example:

MERGE (n:Node {key:'test1'})
RETURN n;

In your case, since you want to test for multiple values per property, there is no way to do that with MERGE

Also, if I understand what you are trying to do, it does not look like MERGE was the right thing to use anyway. I think the following Cypher code should give you the results that you are looking for:

MATCH (n:Node { key: "test1" })
RETURN n
UNION
OPTIONAL MATCH (n:Node { key: 'test2' })
SET n.key = 'test1'
RETURN n;
like image 69
cybersam Avatar answered Dec 09 '25 01:12

cybersam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!