Re: select into composite type / return

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: select into composite type / return
Date: 2021-03-18 14:32:50
Message-ID: e13395d5-10e5-3e83-1dd1-ad5d98d0e8b7@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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=#

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2021-03-22 10:34:13 Re: select into composite type / return
Previous Message Tom Lane 2021-03-18 14:28:33 Re: select into composite type / return