hnnn
hnnn

Reputation: 504

neo4j invalid syntax in conditional

I want to delete node if the node has no relationshops and return true, otherwise return false

match (p:Type {id:72})-->(x)
RETURN 
CASE count(x)
WHEN 0 THEN DELETE p 'true'
ELSE 'false'
END AS deleted;

i always get invalid syntax. Is this possible in cypher?

Upvotes: 0

Views: 127

Answers (2)

Michael Hunger
Michael Hunger

Reputation: 41706

Or

match (p:Type {id:72})
where not exists ((p)--())
delete p

Upvotes: 1

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

To find nodes having no relationships you need to use OPTIONAL MATCH and check for null after a WITH:

match (p:Type {id:72})
optional match (p)-[r]-()
with p, r
where r IS null
delete p

Upvotes: 0

Related Questions