apoc.refactor.rename.typeProperty
Syntax |
|
||
Description |
Renames the given property from |
||
Input arguments |
Name |
Type |
Description |
|
|
The property to rename. |
|
|
|
The new name to give the property. |
|
|
|
The relationships to apply the new name to. If this list is empty, all relationships with the old properties name 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 properties using Cypher
Properties can be referenced dynamically in Cypher without using APOC.
SET n[key] = <expr>
REMOVE n[key]
The dynamically calculated key must evaluate to a STRING
value.
For more information, see the Cypher Manual → Dynamically set or update a property and
Cypher Manual → Dynamically removing a property.
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 query changes the relationship property since
to from
for all relationships using both APOC and Cypher:
MATCH ()-[rel]->()
WITH collect(rel) AS rels
CALL apoc.refactor.rename.typeProperty("since", "from", rels)
YIELD total
RETURN total
MATCH ()-[rel]->()
SET rel.from = rel.since
REMOVE rel.since
RETURN count(*) AS total
total | |
---|---|
3 |
The following query returns all the paths in our graph after this refactoring has been done:
MATCH path = ()-[]->()
RETURN path
path |
---|
[{"name":"Mark","location":"London"},{"from":"2018-02-01"},{"name":"Jennifer","location":"St Louis"}] |
[{"name":"Mark","location":"London"},{"from":"2013-05-01"},{"name":"Michael","location":"Dresden"}] |
[{"name":"Jim","city":"London"},{"from":"2006-05-01"},{"name":"Alistair","city":"London"}] |
This procedure does not rename the property; it creates a new property with the new name and copies the value from the original property, which is then deleted. |