0

我尝试了一堆密码查询,大部分来自这个问题,但没有一个有效。

例如:

postgres=# match (a)<-[r]-() where r is null return *;
 a | r
---+---
(0 rows)

我尝试的最后一个是这样的:

match (n) where not (n)<-[]-() return *

获得语法错误:

postgres=# match (n) where not (n)<-[]-() return *;
ERROR:  syntax error at or near ")"
LINE 1: match (n) where not (n)<-[]-() return *;

我终于启动了 Neo4j,发现上面提到的密码查询在那里工作。

AgensGraph (2.1.3) Cypher 中的等价物是什么?

笔记

在等待正确的解决方案时,我使用以下查询序列解决了这个问题:

  1. 将所有具有传出关系的节点标记为子节点 match (a)<-[]-(b) SET b.child=true;
  2. 查找所有非子节点match(a) where a.child is null return a;
  3. 删除标记match(a) where a.child is not null remove a.child;

最终包装在事务中,以免更改图形属性。

4

1 回答 1

1

您的查询match (n) where not (n)<-[]-() return *;已接近,但是您需要再添加 2 个元素才能使查询正常工作。

  1. 您的模式 (n)<-[]-() 需要用括号括起来。
  2. 你需要在你的模式前加上 EXISTS

所以我运行了这个查询:MATCH (a) WHERE NOT EXISTS ((a)<-[]-()) RETURN *;它起作用了。

于 2021-04-14T17:16:49.323 回答