Re: RowDescription for a function does not include table OID

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Maxwell Dreytser <Maxwell(dot)Dreytser(at)assistek(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: RowDescription for a function does not include table OID
Date: 2024-06-21 15:51:18
Message-ID: 597261.1718985078@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-interfaces

Maxwell Dreytser <Maxwell(dot)Dreytser(at)assistek(dot)com> writes:
> I am working on a meta-programming use-case where I need to scrape some detailed information about the results of a function that "RETURNS TABLE (LIKE physical_table)", which ends up with prorettype = 'physical_table'::regtype.
> The problem is that for the query "SELECT * FROM my_function()" the RowDescription that is sent back shows 0 for Table OID and Column Index.

Yes, that's expected. You're selecting from a function, not a table.

> I would expect that the Table OID contains the relation OID of this
> table, as it would do for a typical statement like "SELECT * FROM
> my_table".

The PG wire protocol specification [1] defines these fields thus:

If the field can be identified as a column of a specific
table, the object ID of the table; otherwise zero.

If the field can be identified as a column of a specific
table, the attribute number of the column; otherwise zero.

My reading of that is that we should populate these fields only for
the case of direct selection from a table. If you go further than
that, then first off you have a ton of definitional issues (should it
"look through" views, for example?), and second you probably break
applications that are expecting the existing, longstanding definition.

regards, tom lane

[1] https://www.postgresql.org/docs/current/protocol-message-formats.html

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2024-06-21 15:52:00 Re: RowDescription for a function does not include table OID
Previous Message Maxwell Dreytser 2024-06-21 15:41:09 Re: RowDescription for a function does not include table OID

Browse pgsql-interfaces by date

  From Date Subject
Next Message David G. Johnston 2024-06-21 15:52:00 Re: RowDescription for a function does not include table OID
Previous Message Maxwell Dreytser 2024-06-21 15:41:09 Re: RowDescription for a function does not include table OID