How to query hops using PGQL?

152 Views Asked by At

We are trying to write PGQL query to get multiple hop(s) for selected node.

To get nodes and edge for the selected node, SELECT n0.id as n0id, e0.id as e0id, n1.id as n1id FROM MATCH (n0)->[e0]->(n1) WHERE n0.id=12345

To increase nodes and edges result, example 2 hops, ... FROM MATCH (n0)->[e0]->(n1)->[e1]->(n3) ... However in this case, nodes with 1 hop will not be return.

I wonder if there is any way query required hop(s) for selected node?

Any solution would be appreciated.

1

There are 1 best solutions below

0
Ryota Yamanaka On

It seems you are looking for the PGQL syntax for variable-length paths:

https://pgql-lang.org/spec/1.4/#variable-length-paths

Among these patterns, I suppose the reachability syntax is useful in your case.

SELECT n0.id as n0id, e0.id as e0id, n1.id as n1id
FROM MATCH (n0)->/:edge-label{1,3}/->(n1)
WHERE n0.id=12345

https://pgql-lang.org/spec/1.4/#between-n-and-m

Thanks!