I'm using a PostGIS / pgRouting database setup with a road network. I'm trying to create an origin-destination table with the complete route information, so not just the sum of the length, like in this post.
I'm trying to get something like this as output table:
Origin | Destination | vertex_id | cost
1 2 415 14.2
1 2 508 4.3
1 3 919 2.4
1 3 1024 6.8
The following code for calculating a single route works fine, but how do I automate this for a lot of origin-destination pairs?
SELECT * FROM shortest_path('
SELECT gid AS id,
start_id::int4 AS source,
end_id::int4 AS target,
length::float8 AS cost
FROM network',
1, -- start_id
2, -- end_id
false, false);
I've tried something with subqueries, like this where I'm getting the start_ids from table nodes
:
SELECT id,
(SELECT * FROM shortest_path('
SELECT gid AS id,
start_id::int4 AS source,
end_id::int4 AS target,
length::float8 AS cost
FROM network',
id::int4, -- start_id
450969, -- end_id
false, false))
FROM nodes;
But this doesn't work because the subquery returns multiple rows (as expected): ERROR: subquery must return only one column
. Any help?