Skip to content

Instantly share code, notes, and snippets.

@tekiegirl
Last active December 30, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekiegirl/7788213 to your computer and use it in GitHub Desktop.
Save tekiegirl/7788213 to your computer and use it in GitHub Desktop.
Does MERGE work the same for relationships as CREATE UNIQUE did?

Merge for relationships

Does MERGE work the same for relationships as CREATE UNIQUE did?

It doesn’t seem to, and the way it is supposed to work causes an error (see query 4) This is based upon this blog post: http://blog.neo4j.org/2013/11/neo4j-200-rc1-final-preparations.html

Setup

CREATE (p1:Person{name:'Sam'}), (p2:Person{name:'Julie'})-[:HAS_ADDRESS]->(a1:Address{postcode:'bar'}), (p3:Person{name:'Bob'}), (p4:Person{name:'Sally'})-[:HAS_ADDRESS]->(a2:Address{postcode:'foo'}), (p5:Person{name:'Chris'}), (p6:Person{name:'Felicity'})-[:HAS_ADDRESS]->(a3:Address{postcode:'foo bar'})

CREATE UNIQUE, 2 relationships

MATCH (p1:Person{name:'Bob'}), (p2:Person{name:'Sally'}), (a:Address{postcode:'foo'})
CREATE UNIQUE (p1)-[:HAS_ADDRESS]->(a), (p2)-[:HAS_ADDRESS]->(a)
RETURN p1,p2,a

MERGE, 2 relationships

MATCH (p1:Person{name:'Sam'}), (p2:Person{name:'Julie'}), (a:Address{postcode:'bar'})
MERGE (p1)-[:HAS_ADDRESS]->(a), (p2)-[:HAS_ADDRESS]->(a)
RETURN p1,p2,a

MERGE, 1 relationship

This is how it was demoed in the blog post, but it just freezes if you uncomment the MERGE line! To see the error for this one, run query 1 in the console, then edit query 4 in the console, uncomment the MERGE line and run.

MATCH (p1:Person{name:'Chris'}), (a:Address{postcode:'foo bar'})
//MERGE (p1)-[:HAS_ADDRESS]->(a)
RETURN p1,a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment