Reputation: 2712
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?
Upvotes: 3
Views: 2141
Reputation: 41676
Not sure how you would deal with the condition that you already have two nodes, one with test1
and another one with test2
in your graph. You would have to merge the two nodes, e.g. also moving the relationships from test2 to test1.
In general I'd try something like this (like cybersam suggested):
OPTIONAL MATCH (n:Node { key: 'test2' })
SET n.key = 'test1'
MERGE (m:Node { key: "test1" })
RETURN m
Upvotes: 0
Reputation: 66999
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;
Upvotes: 3