All technological notes.
MERGE command
CREATE and MATCH 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})
used to indicate whether the node is created or matched. Whenever, we execute a merge query, a node is either matched or created.
Syntax
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})
MATCH (a:Country), (b:Tournament)
WHERE a.name = "India" AND b.name = "ICC Champions Trophy"
MERGE (a)-[r:WINNERS_OF]->(b)
RETURN a, b