apoc.refactor.rename.labelProcedureDeprecated in Cypher 25
| Syntax | 
 | ||
| Description | Renames the given label from  | ||
| Input arguments | Name | Type | Description | 
| 
 | 
 | The label to rename. | |
| 
 | 
 | The new name to give the label. | |
| 
 | 
 | The nodes to apply the new name to. If this list is empty, all nodes with the old label will be renamed. The default is:  | |
| Return arguments | Name | Type | Description | 
| 
 | 
 | The number of batches the operation was run in. | |
| 
 | 
 | The total number of renamings performed. | |
| 
 | 
 | The time taken to complete the operation. | |
| 
 | 
 | The total number of committed operations. | |
| 
 | 
 | The total number of failed operations. | |
| 
 | 
 | The total number of failed batches. | |
| 
 | 
 | The total number of retries. | |
| 
 | 
 | The collected error messages. | |
| 
 | 
 | 
 | |
| 
 | 
 | 
 | |
| 
 | 
 | Constraints associated with the given label or type. | |
| 
 | 
 | Indexes associated with the given label or type. | |
Setting and removing labels using Cypher
Labels can be referenced dynamically in Cypher without using APOC.
SET n:$(label)
REMOVE n:$(label)The dynamically calculated label must evaluate to a STRING or LIST<STRING>.
For more information, see the Cypher Manual → Dynamically setting a label and
Cypher Manual → Dynamically removing a label.
Usage Examples
The examples in this section are based on the following sample graph:
CREATE (mark:Engineer {name: "Mark", city: "London"})
CREATE (jennifer:Engineer {name: "Jennifer", city: "St Louis"})
CREATE (michael:Engineer {name: "Michael", city: "Dresden"})
CREATE (jim:Engineer {name: "Jim", city: "London"})
CREATE (alistair:Engineer {name: "Alistair", city: "London"})
MERGE (jim)-[:COLLEAGUES {since: date("2006-05-01")}]->(alistair)
MERGE (mark)-[:COLLEAGUES {since: date("2018-02-01")}]->(jennifer)
MERGE (mark)-[:COLLEAGUES {since: date("2013-05-01")}]->(michael);The following changes the label on Mark, Jennifer, and Michael from Engineer to DevRel using both APOC and Cypher:
MATCH (person:Engineer)
WHERE person.name IN ["Mark", "Jennifer", "Michael"]
WITH collect(person) AS people
CALL apoc.refactor.rename.label("Engineer", "DevRel", people)
YIELD total
RETURN totalMATCH (person:Engineer)
WHERE person.name IN ["Mark", "Jennifer", "Michael"]
SET person:DevRel
REMOVE person:Engineer
RETURN count(*) AS total| total | |
|---|---|
| 3 | 
After this query has run, we’ll have the following graph:
