Re: select into composite type / return

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Torsten Grust <torsten(dot)grust(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>, Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Subject: Re: select into composite type / return
Date: 2021-03-18 14:28:33
Message-ID: 3718235.1616077713@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Torsten Grust <torsten(dot)grust(at)gmail(dot)com> writes:
> Hi Gary,
> a shot in the dark but maybe

> SELECT id, (do_breakdown(id)).*
> FROM ...

> already does the job?

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2021-03-18 14:32:50 Re: select into composite type / return
Previous Message Gary Stainburn 2021-03-18 11:20:24 Re: select into composite type / return