0

I followed the steps in "pgRouting 2.0 for Windows quick guide". At the step of running pgr_dijkstra using the sql below:

SELECT id, id1 AS node, id2 AS edge, cost, the_geom
  FROM pgr_dijkstra(
    'SELECT gid, source, target, st_length(geom) as cost FROM public.roads_svy21',
    1, 3000, false, false
  ) as di
  JOIN public.roads_svy21_vertices_pgr pt
  ON di.id2 = pt.id ;

It returned me an error message below:

Error, query must return columns 'id', 'source', 'target' and 'cost'

What is the possible cause of the error?

3

The possible cause is what the error says: the first argument of the pgr_dijkstra(sql:text,..) function must contain an SQL statement, which returns id, source, target and cost.

In your case you query for gid, but it should return id as column name.

SELECT id, id1 AS node, id2 AS edge, cost, the_geom
  FROM pgr_dijkstra(
    'SELECT gid AS id, source, target, st_length(geom) as cost FROM public.roads_svy21',
    1, 3000, false, false
  ) as di
  JOIN public.roads_svy21_vertices_pgr pt
  ON di.id2 = pt.id ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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