cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Change property name

Hello
I need to change the name of the property in a relationship between nodes
I have node A and B and R as a relationship between them. In R there is a NAME property and I need to change NAME to OCCURRENCE. I tried to use this syntax to overwrite NAME but it doesn't work, It creates a new property

Match (a), (b) Merge (a)-[r]->(b) Set r.Occurrence="8" Return r

3 REPLIES 3

yyyguy
Graph Buddy

Hey @almeidagabriel016,

You will be able to create a new relationship property, and then delete the old relationship property.

Use one of the following approaches once you have created the new relationship property:

DELETE r.NAME
or
SET r.NAME = NULL

-yyyguy

For this case, you want REMOVE instead of DELETE. REMOVE and SET are reserved for properties, while DELETE and CREATE are reserved for nodes/relationships/patterns.

You're doing too much here, it's generating a cartesian product between a and b.

If you want to find existing relationships and change the property, you can use this:

MATCH (a)-[r]->(b)
SET r.Occurrence = r.Name
REMOVE r.Name

Make sure you have the casing correct on the property name since those are case sensitive, and you provided conflicting information in your post (OCCURRENCE in your description vs Ocurrence in your query.

Also if this only applies to relationships of a certain type, or off of nodes of a certain label, add those into your query, as right now this is looking at all relationships of all nodes, which is fine for a small graph, but won't scale well if you only need to do this to a subset of relationships instead of all of them.