Re: Specifying columns returned by a function, when the function is in a SELECT column list? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Specifying columns returned by a function, when the function is in a SELECT column list?
Date
Msg-id CAKFQuwbFBn6uV1qczBXOZjd0r=zeH9s1KN4CQD_Nj=Lg17_GLQ@mail.gmail.com
Whole thread Raw
In response to Specifying columns returned by a function, when the function is in a SELECT column list?  (Ron Johnson <ronljohnsonjr@gmail.com>)
List pgsql-general
On Tue, Nov 19, 2024 at 8:48 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
It's trivial to specify columns when a table-returning function is the FROM clause, but how does one specify columns when the table-returning function is a column in a SELECT clause?

You don't/cannot.  And with lateral you shouldn't find the need to hack around it either.  Non-scalar function calls in the select clause are now obsolete.

In the select clause the function call returns a single-column of composite type with the names of the fields in the composite already known.  As the query scope where you invoke the function you should only use the composite.  If you need to dive into its fields you'd need a subquery - ideally one that doesn't risk being optimized away due to a multiple-evaluation hazard.

David J.

pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Specifying columns returned by a function, when the function is in a SELECT column list?
Next
From: Paul Foerster
Date:
Subject: PostgreSQL 15.9 Update: Partitioned tables with foreign key constraints