Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Cypher - Merge Command

Back


Merge Command

Syntax Desc
MERGE (node:label) Merge a node with label
MERGE (node:label {key1:value, key2:value, key3:value}) Merge a Node with Properties

CREATE (sachin:player{name: "Sachin Tendulkar", YOB: 1968, POB: "Mumbai"})
CREATE (Ind:Country {name: "India"})
CREATE (sachin)-[r:BATSMAN_OF]->(Ind)


// ======== Merge a Node with a Label =========
MERGE (Sehwag:player) RETURN Sehwag
// (:player {POB: "Mumbai",name: "Sachin Tendulkar",YOB: 1968})
// return only one node "Sachin Tendulkar"

// ======== Merge a Node with Properties ========
MERGE (CT:Tornament{name: "ICC Champions Trophy"})
RETURN CT, labels(CT)
// (:Tornament {name: "ICC Champions Trophy"})│["Tornament"]
// will create new node and return


MERGE (Sehwag:player {name: "Virendra Sehwag", YOB: 1978, POB: "Najafgarh"})
RETURN Sehwag
// (:player {POB: "Najafgarh",name: "Virendra Sehwag",YOB: 1978})



OnCreate and OnMatch

MERGE (node:label {properties . . . . . . . . . . .})
ON CREATE SET property.isCreated ="true"
ON MATCH SET property.isFound ="true"
MERGE (Sehwag:player {name: "Virendra Sehwag", YOB: 1978, POB: "Najafgarh"})
ON CREATE SET Sehwag.isCreated = "true"
ON MATCH SET Sehwag.isFound = "true"
RETURN Sehwag
// (:player {isFound: "true",POB: "Najafgarh",name: "Virendra Sehwag",YOB: 1978})

Merge a Relationship

MATCH (a:Country), (b:Tournament)
   WHERE a.name = "India" AND b.name = "ICC Champions Trophy"
   MERGE (a)-[r:WINNERS_OF]->(b)
RETURN a, b

TOP