1BEGIN;
2BEGIN
3SET client_min_messages TO NOTICE;
4SET
5--q00
6SELECT * FROM pgr_dijkstraVia(
7    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
8    ARRAY[1, 3, 9]
9);
10 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
11-----+---------+----------+-----------+---------+------+------+------+----------+----------------
12   1 |       1 |        1 |         1 |       3 |    1 |    1 |    1 |        0 |              0
13   2 |       1 |        2 |         1 |       3 |    2 |    4 |    1 |        1 |              1
14   3 |       1 |        3 |         1 |       3 |    5 |    8 |    1 |        2 |              2
15   4 |       1 |        4 |         1 |       3 |    6 |    9 |    1 |        3 |              3
16   5 |       1 |        5 |         1 |       3 |    9 |   16 |    1 |        4 |              4
17   6 |       1 |        6 |         1 |       3 |    4 |    3 |    1 |        5 |              5
18   7 |       1 |        7 |         1 |       3 |    3 |   -1 |    0 |        6 |              6
19   8 |       2 |        1 |         3 |       9 |    3 |    5 |    1 |        0 |              6
20   9 |       2 |        2 |         3 |       9 |    6 |    9 |    1 |        1 |              7
21  10 |       2 |        3 |         3 |       9 |    9 |   -2 |    0 |        2 |              8
22(10 rows)
23
24-- q0
25SELECT * FROM pgr_dijkstraVia(
26    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
27    ARRAY[1, 3, 9], false, strict:=true, U_turn_on_edge:=false
28);
29 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
30-----+---------+----------+-----------+---------+------+------+------+----------+----------------
31   1 |       1 |        1 |         1 |       3 |    1 |    1 |    1 |        0 |              0
32   2 |       1 |        2 |         1 |       3 |    2 |    2 |    1 |        1 |              1
33   3 |       1 |        3 |         1 |       3 |    3 |   -1 |    0 |        2 |              2
34   4 |       2 |        1 |         3 |       9 |    3 |    3 |    1 |        0 |              2
35   5 |       2 |        2 |         3 |       9 |    4 |   16 |    1 |        1 |              3
36   6 |       2 |        3 |         3 |       9 |    9 |   -2 |    0 |        2 |              4
37(6 rows)
38
39-- q1
40SELECT * FROM pgr_dijkstraVia(
41    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
42    ARRAY[1, 5, 3, 9, 4]
43);
44 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
45-----+---------+----------+-----------+---------+------+------+------+----------+----------------
46   1 |       1 |        1 |         1 |       5 |    1 |    1 |    1 |        0 |              0
47   2 |       1 |        2 |         1 |       5 |    2 |    4 |    1 |        1 |              1
48   3 |       1 |        3 |         1 |       5 |    5 |   -1 |    0 |        2 |              2
49   4 |       2 |        1 |         5 |       3 |    5 |    8 |    1 |        0 |              2
50   5 |       2 |        2 |         5 |       3 |    6 |    9 |    1 |        1 |              3
51   6 |       2 |        3 |         5 |       3 |    9 |   16 |    1 |        2 |              4
52   7 |       2 |        4 |         5 |       3 |    4 |    3 |    1 |        3 |              5
53   8 |       2 |        5 |         5 |       3 |    3 |   -1 |    0 |        4 |              6
54   9 |       3 |        1 |         3 |       9 |    3 |    5 |    1 |        0 |              6
55  10 |       3 |        2 |         3 |       9 |    6 |    9 |    1 |        1 |              7
56  11 |       3 |        3 |         3 |       9 |    9 |   -1 |    0 |        2 |              8
57  12 |       4 |        1 |         9 |       4 |    9 |   16 |    1 |        0 |              8
58  13 |       4 |        2 |         9 |       4 |    4 |   -2 |    0 |        1 |              9
59(13 rows)
60
61-- q2
62SELECT agg_cost FROM  pgr_dijkstraVia(
63    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
64    ARRAY[1, 5, 3, 9, 4]
65)
66WHERE path_id = 3 AND edge <0;
67 agg_cost
68----------
69        2
70(1 row)
71
72-- q3
73SELECT route_agg_cost FROM  pgr_dijkstraVia(
74    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
75    ARRAY[1, 5, 3, 9, 4]
76)
77WHERE path_id = 3 AND edge < 0;
78 route_agg_cost
79----------------
80              8
81(1 row)
82
83-- q4
84SELECT row_number() over () as node_seq, node
85FROM  pgr_dijkstraVia(
86    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
87    ARRAY[1, 5, 3, 9, 4]
88)
89WHERE edge <> -1 ORDER BY seq;
90 node_seq | node
91----------+------
92        1 |    1
93        2 |    2
94        3 |    5
95        4 |    6
96        5 |    9
97        6 |    4
98        7 |    3
99        8 |    6
100        9 |    9
101       10 |    4
102(10 rows)
103
104-- q5
105SELECT path_id, route_agg_cost FROM  pgr_dijkstraVia(
106    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
107    ARRAY[1, 5, 3, 9, 4]
108)
109WHERE edge < 0;
110 path_id | route_agg_cost
111---------+----------------
112       1 |              2
113       2 |              6
114       3 |              8
115       4 |              9
116(4 rows)
117
118-- q6
119SELECT seq, route_agg_cost, node, agg_cost ,
120CASE WHEN edge = -1 THEN 'visits'
121ELSE 'passes in front'
122END as status
123FROM  pgr_dijkstraVia(
124    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
125    ARRAY[1, 5, 3, 9, 4])
126WHERE node = 9 and (agg_cost  <> 0 or seq = 1);
127 seq | route_agg_cost | node | agg_cost |     status
128-----+----------------+------+----------+-----------------
129   6 |              4 |    9 |        2 | passes in front
130  11 |              8 |    9 |        2 | visits
131(2 rows)
132
133ROLLBACK;
134ROLLBACK
135