Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rename relationships in Neo4j?

I realized only after importing a ton of nodes that I had created relationships called START, which is a reserved keyword. Querying the DB through the Cypher console hence always complains about the reserved keywords:

SyntaxException: reserved keyword "start n=node(0) match n<-[:START]-r return count(r)"

The only workaround that comes to mind is creating new copy relationships with a different name and then deleting the old ones.

Is there an easy way to rename all of these relationships or some way to escape reserved keywords in Cypher?

like image 749
ulkas Avatar asked Dec 11 '12 08:12

ulkas


People also ask

How do I change my relationship name in Neo4j?

You cannot rename an already existing relationship. You'd have to run through all relationships, create the new one in parallel (including all properties) and then remove the old one.

How do I rename my Neo4j database?

There is currently (in neo4j 4.1. 1) no support for renaming a database. You may want to open a feature request for that capability.

What is label name in Neo4j?

Label is a name or identifier to a Node or a Relationship in Neo4j Database. We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node.

How do you add a relationship type in Neo4j?

Creating Relationships We can create a relationship using the CREATE clause. We will specify relationship within the square braces “[ ]” depending on the direction of the relationship it is placed between hyphen “ - ” and arrow “ → ” as shown in the following syntax.


2 Answers

To do the equivalent of a rename, you can create a new one and delete the old one like so:

match (n1)-[old:`Start`]->(n2)
create (n1)-[new:StartDate]->(n2)
delete old

n.b. use backticks like those around `Start` to escape reserved keywords

like image 62
JobJob Avatar answered Oct 24 '22 12:10

JobJob


You are right. You cannot rename an already existing relationship. You'd have to run through all relationships, create the new one in parallel (including all properties) and then remove the old one.

You may also want to consider quoting the reserved word START in your cypher queries with backticks and leave the relationships as they are:

start n=node(0) match n<-[:`START`]-r return count(r)
like image 31
James Avatar answered Oct 24 '22 10:10

James