0

I have a list of starting points and a list of target points for pgRouting. I want to calculate the shortest path for every pair of [source,target]. I am using a subselect to pass an array of node id's to the pg_dijkstra() function:

SELECT seq, id1 AS node, id2 AS edge, cost, linestring
  FROM pgr_dijkstra(
    'SELECT id::integer, source::int4, target::int4, st_length(linestring)::float8 as cost FROM my_ways',

    --source nodes
    array(
        select 
            target as "source_ids"
        from 
            my_ways
        where
            id in (
                select gid from my_sources
            )
    ), 

    --target nodes
    array(
        select 
            target as "target_ids"
        from 
            my_ways
        where
            id in (
                select objectid from my_targets
            )
    ),
    false, 
    false
  ) as di
  JOIN atene_4377.ways_atene_4377 ways
  ON di.id2 = ways.id ;

But when I do so I get the following error message:

ERROR: function pgr_dijkstra(unknown, integer[], integer[], boolean, boolean) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts.

However, if I replace the arrays with single node ids, the algorithm works fine. So there is something wrong about how I pass the array to the function. Any ideas how to fix this?

  • 1
    There's only one boolean parameter in the signature. You may need to cast the arrays to BIGINT[], too. – geozelot Nov 13 at 15:02
  • Which version of pgRouting do you use? As in the comment of @geoelot compare the expected function parameters with the documentation and casting values can help to make sure the data type is correct. – dkastl Nov 14 at 2:54

Your Answer

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

Browse other questions tagged or ask your own question.