I have a system that uses shortest_path function pgrouting 1.x. At the moment, I want to migrate to pgrouting 2. And I assume the equivalent function to shortest_path is pgr_dijkstra. (Correct?)

When running this, (Hibernate Query Language)

SELECT SUM(t2.length) as totalLength FROM (
    SELECT * FROM pgr_dijkstra(
        'SELECT gid AS id, source::int4, target::int4, 
                cost::double precision AS cost, 
                reverse_cost::double precision as reverse_cost 
            FROM openstreetmap',5374,5364, false, true
    )) AS t1, openstreetmap AS t2 WHERE t1.edge_id = t2.gid

I get error ERROR: column t1.edge_id does not exist

What is the edge_id in the output of pgr_dijkstra ?

1 Answer 1


The new Dijkstra function returns a different result set type named pgr_costResult (seq, id1, id2, cost)

Look at this example from the documentation to see how you can rename the column names using aliases:

SELECT seq, id1 AS node, id2 AS edge, cost
        FROM pgr_dijkstra(
                'SELECT id, source, target, cost, reverse_cost FROM edge_table',
                7, 12, true, true

 seq | node | edge | cost
   0 |    7 |    8 |    1
   1 |    8 |    9 |    1
   2 |    9 |   15 |    1
   3 |   12 |   -1 |    0
(4 rows)

So you either change the alias to match with edge_id or you join with id2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.