Skip to content

Instantly share code, notes, and snippets.

@systay
Last active December 29, 2015 19:38
Show Gist options
  • Save systay/7718178 to your computer and use it in GitHub Desktop.
Save systay/7718178 to your computer and use it in GitHub Desktop.
Description of the three flavours of MERGE
= Merge Examples =
:neo4j-version: 2.0.0-RC1
:author: Andrés Taylor
:twitter: @andres_taylor
:tags: domain:example
//setup
[source,cypher]
----
CREATE (a:Label {name:'A'}), (b:Label {name:'B'}), (c:Label {name:'C'})
RETURN a,b,c
----
This is the start data:
// graph
//table
Now we run this query
//output
[source,cypher]
----
MERGE (a:Label {name:'A'})
MERGE (a)-[:KNOWS]->(b:Label {name:'B'})
RETURN a,b
----
The graph now looks like:
//graph
Next, we run the other variant of MERGE, one where both ends are bound:
Now we run this query
//output
[source,cypher]
----
MERGE (a:Label {name:'A'})
MERGE (c:Label {name:'C'})
MERGE (a)-[:KNOWS]->(c)
RETURN a, c
----
Finally, the graph now looks like:
//graph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment