The basic Postgres tutorial has an example with OUT options, for example:
create or replace function hi_lo(a numeric, b numeric, c numeric, OUT hi numeric, OUT lo numeric) as $$ begin hi := greatest(a, b, c); lo := least(a, b, c); end; $$ language plpgsql;
Then the results look like
select hi_lo(2, 3, 4); -- returns one column, "hi_lo" with value "(4, 2)". select * from hi_lo(2, 3, 4); -- returns two columns, "hi" / 4 and "lo" / 2.
But suppose you want to execute a function in columns that come from a join, and that you donβt have access to change a function or use an alternative function? For example, using some data about the toy:
select hi_lo(a.actor_id, length(a.name), ma.movie_id) from actors a join movies_actors ma on a.actor_id = ma.movie_id limit 10;
returns the results in a single column "hi_lo" have 2-tuple values.
The request wrapper in parentheses and an attempt to select * from it do not change the output format. So
select * from ( select hi_lo(a.actor_id, length(a.name), ma.movie_id) from actors a join movies_actors ma on a.actor_id = ma.movie_id limit 10; ) rr
does not affect the form of the result.
The following attempt results in an error: "The subquery should return only one column"
select ( select * from hi_lo(a.actor_id, length(a.name), ma.movie_id) ) from actors a join movies_actors ma on a.actor_id = ma.movie_id limit 10;
Finally, I also tried unnest , but it gives an argument type error because the values ββof the tuple are not treated as arrays.
How can you get multiple columns in the output if you cannot move the function evaluation to the from section?