-
-
Notifications
You must be signed in to change notification settings - Fork 366
Uniform Result Set for pgr_dijkstra() in 3.0
The current plan in pgRouting 3.0 is for the following functions to have return results following the examples below. This would require code that wants to post-process these results need to be aware of what function was used to generate the results and if you wanted to post-process data from multiple different function calls it would need to have lots of ugly IF statements and/or column checking to deal with the differences. Another alternative would be to cast all the results into a common result structure that can accommodate any of these. One option would be to fit all of these into the many-to-many return structure as all of these can easily use that structure and it would still make sense.
I have presented new functions based on adding _UNI to the function name to signify uniformity of result structure. I'm sure there is a better name, but the naming is not the point, it is presenting the results in a uniform way. It is easy to ignore columns that one is not interested in, but it is harder to add them after the fact. In this particular case the pgr_*_UNI() functions can be implemented as simple wrappers like:
select a.seq, start_v::bigint, end_v::bigint, a.node, a.cost, a.tot_cost
from pgr_dijkstra(text sql, bigint start_v, bigint end_v) as a;
using SQL or plpgsql function wrapper.
The minimal use signature:
SET OF (seq, node, edge, cost, tot_cost)
pgr_dijkstra(text sql, bigint start_v, bigint end_v);
SET OF (seq, start_v, end_v, node, edge, cost, tot_cost)
pgr_dijkstra_UNI(text sql, bigint start_v, bigint end_v);
Dijkstra 1 to 1:
SET OF (seq, node, edge, cost, tot_cost)
pgr_dijkstra(text sql, bigint start_v, bigint end_v,
boolean directed:=true);
SET OF (seq, start_v, end_v, node, edge, cost, tot_cost)
pgr_dijkstra_UNI(text sql, bigint start_v, bigint end_v,
boolean directed:=true);
Dijkstra many to 1:
SET OF (seq, start_v, node, edge, cost, tot_cost)
pgr_dijkstra(text sql, array[ANY_INTEGER] start_v, bigint end_v,
boolean directed:=true);
SET OF (seq, start_v, end_v, node, edge, cost, tot_cost)
pgr_dijkstra_UNI(text sql, array[ANY_INTEGER] start_v, bigint end_v,
boolean directed:=true);
Dijkstra 1 to many:
SET OF (seq, end_v, node, edge, cost, tot_cost)
pgr_dijkstra(text sql, bigint start_v, array[ANY_INTEGER] end_v,
boolean directed:=true);
SET OF (seq, start_v, end_v, node, edge, cost, tot_cost)
pgr_dijkstra_UNI(text sql, bigint start_v, array[ANY_INTEGER] end_v,
boolean directed:=true);
Dijkstra many to many:
SET OF (seq, start_v, end_v, node, edge, cost, tot_cost)
pgr_dijkstra(text sql, array[ANY_INTEGER] start_v, array[ANY_INTEGER] end_v,
boolean directed:=true);
-- this is not required because it is the same as above
-- and is only presented here for uniformity of naming
SET OF (seq, start_v, end_v, node, edge, cost, tot_cost)
pgr_dijkstra_UNI(text sql, array[ANY_INTEGER] start_v, array[ANY_INTEGER] end_v,
boolean directed:=true);