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?

Answers


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)

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


match (n1)-[old:`Start`]->(n2)
create (n1)-[new:StartDate {propName:old.propName, ...}]->(n2)
delete old

Need Your Help

How to check if an assembly was built using Debug or Release configuration?

c# assemblies build-process release-mode debug-mode

I'm starting deployment of my web application and I need to guarantee that all the assemblies that are going to be deployed were built using Release configuration. Our system was developed using C#...

Is it possible to remove ExecutionContext and Thread allocations when using SocketAsyncEventArgs?

c# multithreading sockets allocation asyncsocket

If you profile a simple client application that uses SocketAsyncEventArgs, you will notice Thread and ExecutionContext allocations.