liveBook · Manning

On match set clause

As explained in Graph Algorithms for Data Science

The ON MATCH SET clause is a Cypher MERGE subclause that assigns properties when MERGE matches an existing element.

ON MATCH SET is an optional MERGE subclause that assigns properties when the merged pattern already exists. It is useful for recording changes without creating a duplicate node. Use a unique identifier in MERGE, then place properties that should change on a match in ON MATCH SET. section 3.1.7

Update a matched Person

MERGE (t:Person{name:"Amy"}) ON CREATE SET t.location = "Taj Mahal", t.createdAt = datetime() ON MATCH SET t.updatedAt = datetime() If Amy does not exist, MERGE creates the node and ON CREATE SET adds its initial properties. If Amy already exists, no node is created; ON MATCH SET records the current time in updatedAt. section 3.1.7

Listing 3.31 Cypher query that merges a node on its unique identifier property and then adds additional properties to the node
MERGE (t:Person{name:"Amy"})
ON CREATE SET t.location = "Taj Mahal", t.createdAt = datetime()
ON MATCH SET t.updatedAt = datetime()

Open the complete Cypher listing for a MERGE that uses ON CREATE SET and ON MATCH SET together. section 3.1.7

How Graph Algorithms for Data Science covers it

How deep it goes
Explains matching behavior, contrasts ON CREATE SET, and demonstrates a timestamp update with datetime().
Examples
Demonstrates merging an Amy Person node, setting creation properties, and updating updatedAt when the node matches.
What it assumes
Assumes familiarity with MERGE and unique node identifiers while distinguishing creation from matching.
What you can do after
Operate MERGE imports that update existing nodes without creating duplicates.
How it connects
Connects MERGE, ON CREATE SET, unique identifiers, node properties, and the datetime() function.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.