On 18/03/2021 14:28, Tom Lane wrote:
> Beware --- what that actually does is expand into
> SELECT id, (do_breakdown(id)).f1, (do_breakdown(id)).f2, ...
>
> so that the function will be invoked N times if it produces N columns.
>
> What you generally want to do is invoke the function as a lateral FROM
> item:
>
> SELECT id, f.* FROM table AS t, LATERAL do_breakdown(t.id) AS f;
>
> regards, tom lane
Thanks for the info Tom, I can see how that would be quite a performance
hit, not to mention adverse effects if these functions start doing updates.
gary=# SELECT id, f.* FROM sessions AS t, LATERAL do_breakdown(t.id) AS f;
id | f1 | f2 | f3 | f4 | f5 | f6
----+-------+-------+-------+-------+-------+-------
1 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 | 6.00
2 | 11.00 | 12.00 | 13.00 | 14.00 | 15.00 | 16.00
3 | 21.00 | 22.00 | 23.00 | 24.00 | 25.00 | 26.00
(3 rows)
gary=#