This is a variation on plpgsql function that returns multiple columns gets called multiple times. However, I was hoping to find a solution to my particular set of circumstances.
I have a function that processes an array of rows with a given parameter, and returns a set of rows + a new column.
CREATE OR REPLACE foo(data data[], parameter int) RETURNS SETOF enhanceddata AS
...
The function works on a test case with only 1 set of data
SELECT * FROM foo( (SELECT ARRAY_AGG(data) FROM datatable GROUP BY dataid WHERE dataid = something), 1)
But I would like to make it work with multiple groups of data, without passing a dataid
to the function. I tried a number of variations of:
SELECT dataid, (foo(ARRAY_AGG(data)),1).*
FROM dataset
WHERE dataid = something -- only testing on 1
GROUP BY dataid
But the function gets called once for every column.
enhanceddata
is a composite type, I presume? The definition of which would be essential to your question. Because the problem you describe only applies if multiple columns are returned (not for multiple rows). – Erwin Brandstetter