在寻找一个好的查询作为Side effects while combining two statements using Cypher的答案时,我试图在DELETE的一部分查询中创建一个CASE,我得到了一个奇怪的错误...
MERGE (p1:C5{userId:'1234'})
mERGE (p2:C5{userId:'555'})
MERGE (p3:C5{userId:'1234'})
mERGE (p4:C5{userId:'6969'})
MERGE (p1)-[r1:follow]->(p2)
MERGE (p2)-[t1:follow]->(p1)
MERGE (p3)-[r2:follow]->(p4)
MERGE (p4)-[t2:follow]->(p3)
SET r1.type='mirror',
t1.type='real',
r2.type='real',
t2.type='mirror'
MATCH (n:C5 { userId: '1234' })<-[r]-(),
(g:C5{userId:'1234'})-[y]->()
DELETE
CASE
WHEN r.type = 'mirror' THEN r
WHEN y.type = 'real' THEN y END
Neo.DatabaseError.Statement.ExecutionFailure: Relationship 3499 has been deleted
我在Mac Yosemite 10.10.5上使用Neo4j 2.2.5并且已经使用以下方法清空了一个空数据库:
Match (a)-[b]-(c), (d) delete a,b,c,d
答案 0 :(得分:1)
您的查询无法正常运行的原因有多种。
MATCH
子句正在查找y
和r
关系的对,这意味着相同的关系实例(让我们称之为&{ #34; y1&#34;)将出现在多个结果对中(例如,&#34; y1 / r1&#34;和&#34; y1 / r2&#34;)。因此,您的查询尝试多次删除相同的关系。CASE
测试成功,您的y.type = 'real'
子句将跳过r.type = 'mirror'
测试。因此,并非所有适当的y
关系都会被删除。这是一个简单的查询,可以过滤掉重复项并删除所有适当的关系。
MATCH ()<-[y { type:'real' }]-(:C5 { userId: '1234' })<-[r { type:'mirror' }]-()
WITH COLLECT(DISTINCT r) AS rs, COLLECT(DISTINCT y) AS ys
FOREACH (r IN rs | DELETE r)
FOREACH (y IN ys | DELETE y);
答案 1 :(得分:1)
当我在过去遇到Relationship XXX has been deleted
或类似内容时,我使用WITH
然后执行DELETE
来解决此问题。
要获得精确的Cypher并使其正常工作,您需要做的就是:
MATCH (n:C5 { userId: '1234' })<-[r]-(),
(g:C5{userId:'1234'})-[y]->()
WITH
CASE
WHEN r.type = 'mirror' THEN r
WHEN y.type = 'real' THEN y END as rel
DELETE rel