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 1qxq65-003jf2-Dc for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Oct 2023 14:52:01 +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 1qxq63-002uDa-VX for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Oct 2023 14:51:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qxq63-002uCZ-Ms for pgsql-bugs@lists.postgresql.org; Tue, 31 Oct 2023 14:51:59 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qxq61-0040R4-6C for pgsql-bugs@lists.postgresql.org; Tue, 31 Oct 2023 14:51:59 +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 39VEpqta2583136; Tue, 31 Oct 2023 10:51:52 -0400 From: Tom Lane To: Laurenz Albe cc: 409800246@qq.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18173: ERROR: could not identify a comparison function for type unknown In-reply-to: <52e52bddd9d5396ca07f103f799518f82e2c8aad.camel@cybertec.at> References: <18173-c971c32eb961e810@postgresql.org> <52e52bddd9d5396ca07f103f799518f82e2c8aad.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Tue, 31 Oct 2023 12:10:05 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2583134.1698763912.1@sss.pgh.pa.us> Date: Tue, 31 Oct 2023 10:51:52 -0400 Message-ID: <2583135.1698763912@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Mon, 2023-10-30 at 13:24 +0000, PG Bug reporting form wrote: >> postgres=# select distinct (id,name,'D3Q84xpymM',123,'123') from test_v; >> ERROR: could not identify a comparison function for type unknown > This is not a bug. You probably want to remove the parentheses. It is a bit inconsistent that we allow select distinct id,name,'D3Q84xpymM',123,'123' from test_v; and select (id,name,'D3Q84xpymM',123,'123') from test_v; but not the above. Poking around, I discovered a related failure: select ((id,name,'D3Q84xpymM',123,'123')).f3 from test_v; ERROR: failed to find conversion function from unknown to text That happens because at the end of parsing we apply resolveTargetListUnknowns, which sees that there's an UNKNOWN output column and tries to coerce it to text, but can't since it's not a plain literal. So maybe there is a case for forcing unknowns to text in the input list of a RowExpr. You could argue that a RowExpr is morally the same thing as a SELECT list, so this would have some consistency to it. Nonetheless, it's a rather big semantics change and I wonder what it might break. Notably, in the context row(...,'foo',...)::somerowtype currently the cast to somerowtype will see an unknown literal and do the right thing, whereas maybe with text input it might do something surprising (and in any case we'd lose some efficiency from the extra type coercion). On the whole, given the lack of complaints for the last couple of decades, I'm content to say that it's operating as intended. At best we'd be switching from one nonstandard behavior to another. ("Oracle does it" doesn't make it standard.) In any case, I don't like the proposed patch one bit. Kluging this up in the specific case of DISTINCT is just adding a wart. regards, tom lane