How do I rename relationships in Neo4j?

ulkas picture ulkas · Dec 11, 2012 · Viewed 8k times · Source

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?

Answer

JobJob picture JobJob · Feb 20, 2014

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