Database Reference
In-Depth Information
Working with MERGE
MERGE is used to match a given element and return a value if it exists or create a new one
if it does not exist. MERGE internally performs two sequential operations of first matching
the given set of elements using MATCH , and if it does not exist, using CREATE to create the
missing elements.
Another benefit of MERGE is that it avoids loading duplicate data. MERGE works on exact
matches and follows the principle of all or nothing . It will either perform an exact match or
create the complete pattern, but in any case, it will not be executed on partial elements of
the provided pattern.
MERGE (actor:Actor {Name: "Russell Crowe", Age: 50}) return
actor;
The preceding statement will first check the existence of the node with the given label and
properties and will then return or create and return based on the results of the MATCH state-
ment.
MERGE is accompanied and followed with ON CREATE and ON MATCH . These allow us
to perform additional changes to the nodes, properties, and relationships depending upon
the result of the MERGE command:
MERGE (actor:Actor {Name: "Russell Crowe", Age: 50})
ON CREATE set actor.created_at = timestamp()
ON MATCH set actor.last_seen = timestamp()
return actor;
Search WWH ::




Custom Search