Cypher/Neo4j –在全局范围内存储括号内的变量
以下密码查询在最后一行失败,因为 p2
仅在 EXISTS
之后的范围内定义,但是有没有办法以某种方式将其带出该范围(例如将其设置为到一个全局变量)并返回它?
MATCH (p:Person)
WHERE EXISTS {
MATCH (p{name: 'José'})<-[:CHILD_OF]-(p2:Person)
WHERE p2.name IN ['Roberto', 'Gustavo']
}
RETURN (p), (p2) // fails
PS:我知道最简单的解决方案就是首先不使用范围,我的问题是我正在寻找的功能是否存在。
The following cypher query fails at the last line because p2
is only defined within scope after EXISTS
, but is there a way to bring it out of that scope somehow (e.g. set it to a global variable) and return it?
MATCH (p:Person)
WHERE EXISTS {
MATCH (p{name: 'José'})<-[:CHILD_OF]-(p2:Person)
WHERE p2.name IN ['Roberto', 'Gustavo']
}
RETURN (p), (p2) // fails
P.S.: I know that the easiest solution is to just NOT use the scope in the first place, my question is whether the functionality I'm looking for exists.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
EXISTS
中使用的存在查询无法返回值。如果您想对子查询的结果进行后处理,则需要使用CALL
。看起来您想尝试:
CALL 中的WITH 使外部查询中的p 可用于内部查询。
Existential queries used in
EXISTS
cannot return values. You need to useCALL
if you want to do post processing of a sub query's results.It looks like you want to try:
The WITH in the CALL makes the p from the outer query available to the inner query.
我会这样做:
I would have done this:
您可以删除 where contains 子句,直接对 Jose 和他的父母进行查询。
You can remove the where exists clause and directly do the query on Jose and his parents.