Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sKgXu-00BbQj-MT for pgsql-general@arkaria.postgresql.org; Fri, 21 Jun 2024 15:51:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sKgXs-003uhg-Km for pgsql-general@arkaria.postgresql.org; Fri, 21 Jun 2024 15:51:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sKgXs-003uhX-8z for pgsql-general@lists.postgresql.org; Fri, 21 Jun 2024 15:51:24 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sKgXp-002R7q-Mo for pgsql-general@lists.postgresql.org; Fri, 21 Jun 2024 15:51:23 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 45LFpIvj597262; Fri, 21 Jun 2024 11:51:18 -0400 From: Tom Lane To: Maxwell Dreytser cc: "pgsql-general@lists.postgresql.org" Subject: Re: RowDescription for a function does not include table OID In-reply-to: References: <3528232.1718682678@sss.pgh.pa.us> Comments: In-reply-to Maxwell Dreytser message dated "Fri, 21 Jun 2024 14:41:55 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <597260.1718985078.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 21 Jun 2024 11:51:18 -0400 Message-ID: <597261.1718985078@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Maxwell Dreytser 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 =3D 'physical_table':= :regtype. > The problem is that for the query "SELECT * FROM my_function()" the RowD= escription 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