微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 AgensGraph 中搜索没有传入边/关系的节点?

如何解决如何在 AgensGraph 中搜索没有传入边/关系的节点?

我尝试了大量密码查询,大部分来自 this question,但都没有奏效。

例如:

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. 将所有具有传出关系的节点标记children 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;

最终包装在一个事务中,以免改变图形属性

解决方法

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

  1. 您的模式 (n)
  2. 你需要在你的模式前加上 EXISTS

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。