DETACH DELETE Neo4j 2.3.x/Cypher
Asked Answered
C

2

14

What is the behaviour and purpose of the new Cypher operator DETACH DELETE added in Neo4j 2.3.x?

Chilcote answered 15/10, 2015 at 4:26 Comment(1)
If you are coming here from a search engine to try to find the difference between detach and delete: detach removes the relationships of a node. delete deletes a node. You will need to detach a node before you delete it if it has any relationships.Equinox
A
25

If you want to delete nodes, you need to delete the relationships as well. In previous versions you would need to do:

MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n, r

Now you can simply say:

MATCH (n)
DETACH DELETE n
Aulea answered 15/10, 2015 at 5:32 Comment(0)
D
6

I could not comment on Brian's answer so here it is:

This command:

MATCH n
DETACH DELETE n

Gives to following error:

WARNING: Parentheses are required to identify nodes in patterns, i.e. (n) (line 1, column 7 (offset: 6))
"MATCH n"
       ^

Thus the correct command is:

MATCH (n)
DETACH DELETE n
Dimitry answered 17/7, 2016 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.