liveBook · Manning

Unique identifier

As explained in Graph Algorithms for Data Science

A unique identifier is a value or attribute that distinguishes one entity or graph element from all others within its scope.

A unique identifier is a property value that distinguishes each node from every other node with the same label. Defining one prevents ambiguous matches during graph imports. section 3.1.7

Use the identifier inside MERGE so Cypher can find an existing node or create it when no matching pattern exists. Avoid treating a nonunique combination, such as name and location, as the identifier: different nodes can result. section 3.1.7

A reliable import pattern separates identity from other properties:

  • MERGE the node using its label and unique identifier. section 3.1.7
  • Use ON CREATE SET for properties assigned only when the node is new. section 3.1.7
  • Use ON MATCH SET for properties updated when the node already exists. section 3.1.7

Merging Amy

MERGE (t:Person{name:"Amy"}) identifies the Person node by name. ON CREATE SET records location and createdAt for a new node; ON MATCH SET records updatedAt for an existing one. 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()

Inspect a complete Cypher example that merges a node by its identifier and handles creation and matching separately. section 3.1.7

How Graph Algorithms for Data Science covers it

How deep it goes
Explains identifier-based MERGE, duplicate results, and conditional property updates, but does not detail database constraints.
Examples
Uses Alicia, Amy, Jane, Samay, Alex, and Andrea as Person-node and relationship examples.
What you can do after
Apply it via Cypher to merge nodes by identity and update properties according to creation or matching.
How it connects
Connects unique identifiers with MERGE, node labels, properties, ON CREATE SET, and ON MATCH SET.

Also explained in

Compare how 9 books explain unique identifier →

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.