[pgrouting-users] pgr_kdijkstraCost- how to use array with braces?

Stephen Woodbridge woodbri at swoodbridge.com
Thu Sep 17 10:31:39 PDT 2015


On 9/17/2015 12:25 PM, Bistrais, Bob wrote:
> Hello,
>
> I am trying to work with pgRouting’s pgr_kdijkstraCost to find multiple
> paths.  The input requires an array of target nodes enclosed by brackets
> [].  But when I generate the array in Postgres, the array is enclosed in
> braces {}.  So I can’t get the algorithm to work.
>
> Can anyone suggest how to make this array work with the
> pgr_kdijkstraCost algorithm?

Hi Bob,

I would be helpful if you showed you sql that didn't work. But here is a 
go in a vacuum:

Define a static array in postgres with:
     array[item, item, item, ...]
     '{item, item, item, ...}'::integer[] -- cast string to integer array

Define an array as an aggregrate:
     select array_agg(id) from some_table;

Combining these:
     select * from pgr_kdijkstraCost(..., (select array_agg(id) from 
some_table), ...);
     select * from pgr_kdijkstraCost(..., array[1,2,3,27,35,...], ...);
     select * from pgr_kdijkstraCost(..., 
'{1,2,3,27,35,...}'::integer[], ...);


-Steve


More information about the Pgrouting-users mailing list