Cypher temp relationship

浪子不回头ぞ 提交于 2021-02-08 08:24:08

问题


I'm trying to combine / merge a path into a new relationship. The problem is that I'm not interested in storing it but rather return it as a result of a cypher query.

Lets say I have something like this:

(a)-[:CALLS_METHOD]->(b)-[:RETURNS_TYPE]->(c)

How can I create a temporary relationship like this one:

(a)-[:DEPENDS_ON]->(c)

Only for a result of that particular query, so that I don't have to store it. Because I'm really only interested in the dependency from a to c and not the details about of that dependency.


回答1:


You can't return a relationship from the database that doesn't exist. The purpose of the queries is to return stuff that does exist.

Perhaps what you're interested in is inferred pairs, rather than a relationship. Something like:

MATCH (a)-[r:CALLS_METHOD|RETURNS_TYPE*]->(b)
RETURN a, "depends on", b

Your other alternative is to materialize/save the relationship, and then query for it:

MATCH (a)-[r:CALLS_METHOD|RETURNS_TYPE*]->(b)
CREATE a-[newRel:DEPENDS_ON]->b
RETURN newRel;

But this has the side-effect of creating it.



来源:https://stackoverflow.com/questions/23645257/cypher-temp-relationship

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!