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 1rfmkV-002EqK-6p for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Feb 2024 20:11:23 +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 1rfmkT-008ODE-Dl for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Feb 2024 20:11:21 +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 1rfmkT-008OCd-5p for pgsql-bugs@lists.postgresql.org; Thu, 29 Feb 2024 20:11:21 +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 1rfmkP-002CxV-W4 for pgsql-bugs@lists.postgresql.org; Thu, 29 Feb 2024 20:11:20 +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 41TKBHnv2741769; Thu, 29 Feb 2024 15:11:17 -0500 From: Tom Lane To: "David G. Johnston" cc: PetSerAl , "pgsql-bugs@lists.postgresql.org" Subject: Re: Record returning function accept not matched columns declaration In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Thu, 29 Feb 2024 12:48:13 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2741767.1709237477.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 29 Feb 2024 15:11:17 -0500 Message-ID: <2741768.1709237477@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Thursday, February 29, 2024, PetSerAl wrote: >> postgres=# with a(b) as (values (row(1,2,3))) >> postgres-# select * from a, coalesce(b) as c(d int,e int, f int) >> postgres-# union all >> postgres-# select * from a, nullif(b, null) as c(d int,e int, f int) >> postgres-# union all >> postgres-# select * from a, unnest(array[b]) as c(d int,e int, f int) >> postgres-# union all >> postgres-# select * from a, json_populate_record(b, null) as c(d int,e >> int, f int); --expect OK > My concern with all of this is accepting the specification of column > definitions for functions that don’t return the record pseudo-type. Hm? These cases all *do* return record, because that's what a.b is typed as. It looks to me like we broke these edge cases in refactoring. v11 gives me the expected errors: regression=# with a(b) as (values (row(1,2,3))) select * from a, nullif(b, null) as c(d int,e int); ERROR: function return row and query-specified return row do not match DETAIL: Returned row contains 3 attributes, but query expects 2. regression=# with a(b) as (values (row(1,2,3))) select * from a, coalesce(b) as c(d int,e int); ERROR: function return row and query-specified return row do not match DETAIL: Returned row contains 3 attributes, but query expects 2. v12 rejects the nullif example but not coalesce. v14 and up lets them both by. I think the v14 change has to do with the function calls having got flattened to constants, but I've not fingered the exact culprit yet. I didn't look yet for the earlier behavioral change. Even more amusing, since v14: regression=# with a(b) as (values (row(1,2,3))) select * from a, coalesce(b) as c(d int,e int,f int, g int); server closed the connection unexpectedly I think that Assert is just wrong and can be removed, though; it doesn't seem to be guarding anything of interest. regards, tom lane