6.8.3.2 Unnesting of Variable-Length Path Queries
Unnesting of variable-length path queries (such as, SHORTEST
or
CHEAPEST
paths) to obtain a separate row for each vertex or edge
along a path is supported.
You can unnest a path aggregation using one of the following options:
ONE ROW PER MATCH
(default option)ONE ROW PER VERTEX(vertex_variable)
ONE ROW PER EDGE(edge_variable)
Note:
Visualization of variable-length path queries using the Graph Visualization application is not supported.For example, the following PGQL query uses ONE ROW PER EDGE
option:
SELECT k.TXN_AMOUNT
FROM MATCH ALL SHORTEST (a:Accounts) -[e:transfers]->* (b:Accounts)
ONE ROW PER EDGE( k )
WHERE a.ACCT_ID = 284 AND b.ACCT_ID = 616
On execution, the preceding query retrieves one row per edge along a path:
+------------+
| TXN_AMOUNT |
+------------+
| 1000.0 |
| 1000.0 |
| 1000.0 |
+------------+
An example for a query with ONE ROW PER VERTEX
option is as follows:
SELECT k.ACCT_ID AS id, k.ACCT_NAME AS name
FROM MATCH ANY SHORTEST (a:Accounts) ((src:Accounts)-[e:transfers]->){1,3}(b:Accounts)
ONE ROW PER VERTEX(k)
WHERE a.ACCT_ID=284 AND b.ACCT_ID=616
On execution, the preceding query retrieves one row per vertex along a path:
+----------------------+
| ACCT_ID | ACCT_NAME |
+----------------------+
| 616 | Account4 |
| 744 | Account3 |
| 772 | Account2 |
| 284 | Account1 |
+----------------------+
Parent topic: PGQL Features Supported in the Graph Server (PGX)