Getting multiple shortest paths with PgRouting in one query?
Something like
SELECT
source,
target,
(SELECT SUM(cost) FROM -- or whatever you want to do with the routing result
(SELECT * FROM shortest_path_astar('...',
source,
target,
false,
false)
) AS foo
) AS cost
FROM all_to_all;
Here's a query that returns all segments for all source-target combinations:
SELECT
source,
target,
shortest_path_astar('SELECT gid AS id, length AS cost, * FROM ways', source, target, false, false) AS segment
FROM
all_to_all
Incredible, inconsistent with SQL syntax, but works!
source | target | segment
-------+--------+----------------
1 | 4 | (1, 2, 0.1357)
1 | 4 | (2, 3, 0.2468)
1 | 4 | (3, 4, 0.9)
1 | 4 | (4, -1, 0)
other sources & targets here