cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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.

1 ACCEPTED SOLUTION

12kunal34
Graph Fellow

I think you want to create below pattern:

(dummy)-[:PARENT_OF]->(s0)-[:PARENT_OF]->(s1)

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

View solution in original post

1 REPLY 1

12kunal34
Graph Fellow

I think you want to create below pattern:

(dummy)-[:PARENT_OF]->(s0)-[:PARENT_OF]->(s1)

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