3
votes

In Cypher (Neo4j), I am able to delete relationship using id. But When I try to delete self relationship, query is running for long time and relationship is not deleted.

I have tried following many ways:

  1. start r=rel(5828) delete r;

  2. MATCH (p:Person{fid:'60'})-[r:IS_RELATED_TO]->(p:Person{fid:'60'}) delete r

  3. match (a:Person)-[rel:IS_RELATED_TO]->(b:Person) where a.fid="60" and ID(rel)=5828 delete rel

But not able to delete from any above way.

Screenshot to delete self relationship using id:

enter image description here

1
What version of Neo4j are you using?Bruno Peres
I tried here with create (node:Node {name : "Bruno"}), (node)-[:rel]->(node) then match (a:Node {name:"Bruno"})-[r:rel]->(b:Node {name:"Bruno"}) delete r and the relationships was deleted. Using Neo4j 3.3.1 here.Bruno Peres
Thanks @Bruno Peres. You done it by changing a to b. Thats working fine.AzarEJ
But i would like to know why it cannot be deleted using ID (start r=rel(5828) delete r;) ?AzarEJ
AzarEJ - Well, I don't know exactly, but note that START clause is deprecated.Bruno Peres

1 Answers

2
votes

It looks like the relationship you want to delete does not actually have the native ID 5828. And it also looks like Person node with that relationship does not actually have the fid value "60".

If you just want to delete all self-relationships involving Person labels and IS_RELATED_TO types, this should work (assuming that Person nodes have unique fid values):

MATCH (a:Person)-[rel:IS_RELATED_TO]->(a) 
DELETE rel;