Merge: Bounding Relationships

How should I bound relationships in merge? For example, the following query works fine.

MERGE (dummy{name:'dummy'})-[r0:PARENT_OF]->(s0)
MERGE (dummy)-[:PARENT_OF]->(s0)-[:PARENT_OF]->(s1)

But it adds two relationships between dummy and s0.
When I add r0 to the second merge it gives me "Variable r0 already declared":

MERGE (dummy{name:'dummy'})-[r0:PARENT_OF]->(s0)
MERGE (dummy)-[r0:PARENT_OF]->(s0)-[:PARENT_OF]->(s1)

Also, the same error if I remove :PARENT_OF from it:

MERGE (dummy{name:'dummy'})-[r0:PARENT_OF]->(s0)
MERGE (dummy)-[r0]->(s0)-[:PARENT_OF]->(s1)

The nodes "dummy" and "s0" are bound correctly.

I think you want to create below pattern:


so for this simply , you can write below query

MERGE (dummy{name:'dummy'})-[r0:PARENT_OF]->(s0)
MERGE (s0)-[:PARENT_OF]->(s1)

you getting above errors because you using variables incorrectly .It will create ambiguity.
for avoiding that best practice is always use lable name with variable

1 Like