Home > Net >  PostgreSQL: replace generate_series with an array
PostgreSQL: replace generate_series with an array

Time:04-12

I have a working SQL code that creates geometries according to numbers generated from a generate_series function:

  CREATE TEMPORARY TABLE catchments ON COMMIT DROP AS (
    SELECT lims, ST_ConcaveHull(the_geom, alpha_factor) AS the_geom_overlap FROM (
      SELECT lims, ST_MakeValid(ST_Collect(n.the_geom)) AS the_geom
      FROM generate_series(1, 10, 2) AS lims, pgr_drivingDistance(
        'SELECT id, source, target, cost, reverse_cost FROM edges',
        vertex_id, lims, true
      ) a, nodes n WHERE a.node = n.vid
      GROUP BY lims
    ) AS conv_hull
    ORDER BY lims DESC
  );

Now I need to replace the fixed interval series by an array with varying intervals, e.g. [1, 2, 5, 7, 8].

Is there a simple way to "convert" the generate_series by an array with the same logic? I would like to avoid using a for loop if possible.

CodePudding user response:

FROM unnest(ARRAY[1,2,5,7,8]) AS lims

should do it.

  • Related