Skip to content Skip to sidebar Skip to footer

Plpgsql Function That Returns Multiple Columns Gets Called Multiple Times

I'm running PostgreSQL 9.2.1 and have a plpgsql function that returns 3 columns. It's called like this (simplified): SELECT (my_function(b.input)).*, a.other, b.columns FROM table_

Solution 1:

This should do the job:

SELECT (y).*
FROM  (
   SELECT my_aggregate_function(border, lower_limit, upper_limit, operation) AS y
   FROM (
      SELECT (x).*, operation
      FROM  (
         SELECT my_function(ca.timeslice_id) AS x, agc.operation
         FROM   geometry_component agc
         JOIN   volume             av  ON av.id = agc.volume_id
         JOIN   volume_dependency  avd ON avd.id = av.contributor_id
         JOIN   my_rowset_function('2013-02-22') ca ON ca.feature_id = avd.idWHERE  agc.timeslice_id = 12345ORDERBY agc.sequence
         ) sub1
      )sub2
   )sub3

Solution 2:

Unfortunately, that's a normal quirk of the implementation. It will be possible to avoid this problem when support for LATERAL queries goes in with 9.3.

For now I'm not aware of any good workaround.

Post a Comment for "Plpgsql Function That Returns Multiple Columns Gets Called Multiple Times"