Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mueIu-0005gX-4J for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Dec 2021 17:31:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mueIs-0005Jx-Lj for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Dec 2021 17:30:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mueIs-0005Ji-CE for pgsql-hackers@lists.postgresql.org; Tue, 07 Dec 2021 17:30:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mueIk-0004Is-Lc for pgsql-hackers@lists.postgresql.org; Tue, 07 Dec 2021 17:30:58 +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 1B7HUmaX3501515; Tue, 7 Dec 2021 12:30:48 -0500 From: Tom Lane To: Robert Haas cc: PostgreSQL Hackers Subject: Re: ExecTypeSetColNames is fundamentally broken In-reply-to: References: <2950001.1638729947@sss.pgh.pa.us> <3360468.1638824732@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Tue, 07 Dec 2021 11:19:27 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3501513.1638898248.1@sss.pgh.pa.us> Date: Tue, 07 Dec 2021 12:30:48 -0500 Message-ID: <3501514.1638898248@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Mon, Dec 6, 2021 at 4:05 PM Tom Lane wrote: >> select f(t) from t(x,y); >> >> If we adopt the "rename for all purposes" interpretation, then >> the second SELECT must fail, because what f() is being passed is >> no longer of type t. > For me, the second SELECT does fail: > rhaas=# select f(t) from t(x,y); > ERROR: column "x" does not exist Ah, sorry, I fat-fingered the alias syntax. Here's a tested example: regression=# create table t (a int, b int); CREATE TABLE regression=# insert into t values(11,12); INSERT 0 1 regression=# create function f(t) returns int as 'select $1.a' language sql; CREATE FUNCTION regression=# select f(t) from t as t(x,y); f ---- 11 (1 row) If we consider that the alias renames the columns "for all purposes", how is it okay for f() to select the "a" column? Another way to phrase the issue is that the column names seen by f() are currently different from those seen by row_to_json(): regression=# select row_to_json(t) from t as t(x,y); row_to_json ----------------- {"x":11,"y":12} (1 row) and that seems hard to justify. regards, tom lane