Aries On The Cusp
Aries On The Cusp

Reputation: 419

Merge & Create unique fail in one statement

Why can't I use a create unique in a Merge ? Neo4j returns "unknown error "

Merge (o:Ot {name:"md2"} )
MERGE (pd:PD { p:"23"})
MERGE (tg:Ot {name:"XXX"})
MERGE (pi:PI { id:"123"}) 
WITH o,pi,target,pd
Create UNIQUE (o)-->(pi)-->(pd) , (pi)-->(tg)
RETURN o,pi,pd,tg

Upvotes: 0

Views: 46

Answers (1)

cybersam
cybersam

Reputation: 66977

  1. You have target in your WITH clause. It should probably be tg.
  2. Whenever you CREATE a relationship between 2 nodes, you have to specify at least the relationship type.

This query, for example, will work:

MERGE (o:Ot {name:"md2"})
MERGE (pd:PD { p:"23"})
MERGE (tg:Ot {name:"XXX"})
MERGE (pi:PI { id:"123"}) 
WITH o,pi,tg,pd
CREATE UNIQUE (o)-[:x]->(pi)-[:y]->(pd), (pi)-[:z]->(tg)
RETURN o,pi,pd,tg

Upvotes: 2

Related Questions