age icon indicating copy to clipboard operation
age copied to clipboard

Cypher query to exlude subpaths (or return only full paths)

Open FrancescoSillani opened this issue 2 years ago • 2 comments

Hello all,

I have the following (simplified) scenario:

A -> [R] -> B B -> [R] -> C

where A, B, C are vertex of my graph, and R is a relation.

With the following query:

MATCH p = (t1)-[R*]->(t2)

the following paths are returned:

A -> B, B->C, A -> B -> C

Is it possible to build a query that returns only the following path: A -> B -> C?

I was thinking about

  • adding a WHERE clause similar to "WHERE not t2 -> [R] -> ()"
  • adding a MATCH similar to "MATCH NOT (p1 = (t2)-[R]->())"

but I'm not able to obtain a valid query...

Could you please me give any advice?

Thanx a lot in advance

FrancescoSillani avatar Dec 28 '23 16:12 FrancescoSillani

@FrancescoSillani

Given your scenario, does this path A -> B -> C exist?

rafsun42 avatar Jan 10 '24 18:01 rafsun42

@FrancescoSillani

Assuming, your scenario is- A -> [R] -> B -> [R] -> C, please refer to the documentation on variable length edges. You can MATCH paths with exactly 2 edges using (t1)-[:R*2]->(t2).

rafsun42 avatar Jan 10 '24 18:01 rafsun42

This issue is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 11 '24 00:05 github-actions[bot]

This issue was closed because it has been stalled for further 7 days with no activity.

github-actions[bot] avatar May 19 '24 00:05 github-actions[bot]