# Shortest Path Dijkstra

I would like to calculate the shortest path with dijkstra algorithm.

sample query ```SELECT seq, id1 AS node, id2 AS edge, cost FROM pgr_dijkstra(' SELECT gid AS id, source::integer, target::integer, length::double precision AS cost FROM ways', 30, 60, false, false);```

I imported an osm map, it has proper network. The name of the table is `at_2po_4pgr`, colums are `id, osm_id, osm_name, osm_meta, osm_source_id, osm_target_id, clazz, flags, source, target, km, kmh, cost, reverse_cost, x1, y1, x2, y2, geom_way`.

in result I would like to see the shortest path and streets name in a row where route was planning.

Thanks

• What have you tried? You already have a working sample query which just has to be adjusted to your column names. Feb 8, 2014 at 17:25
• yes I tried, but I dont know which cloumn fit into the query Please help @underdark Feb 8, 2014 at 17:54

You best start with the workshop, and especially look at the chapter, which explains how to write a simple plpgsql wrapper function to return additional attributes such as street name for example.

A query might look like this then:

``````SELECT seq, id1 AS node, id2 AS edge, cost, b.the_geom, b.osm_name FROM pgr_dijkstra('
SELECT id,
source::integer,
target::integer,
length::double precision AS cost
FROM at_2po_4pgr',
30, 60, false, false) a LEFT JOIN at_2po_4pgr b ON (a.id2 = b.id);
``````

You really just have to change a few table/attribute names.

• How can I calculate the distance between A and B in km?? with sum() function? Feb 9, 2014 at 13:32
• I think you better ask this as a new question, but just before I gave an answer which might help you, too: gis.stackexchange.com/a/86102/800 Feb 11, 2014 at 5:00
• I tried, I got this `ERROR: column "pgr_dijkstra.seq" must appear in the GROUP BY clause or be used in an aggregate function SQL state: 42803 Character: 8` Query: `SELECT seq, id1 AS node, id2 AS edge, sum(cost) AS cost FROM pgr_dijkstra('` Feb 11, 2014 at 10:00