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 1qlsSY-004hWU-4A for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Sep 2023 14:57:46 +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 1qlsSW-00DsAe-J1 for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Sep 2023 14:57:44 +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 1qlsSW-00DsAQ-A4 for pgsql-bugs@lists.postgresql.org; Thu, 28 Sep 2023 14:57:44 +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 1qlsST-00873w-Iu for pgsql-bugs@lists.postgresql.org; Thu, 28 Sep 2023 14:57:43 +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 38SEvdYH960061; Thu, 28 Sep 2023 10:57:39 -0400 From: Tom Lane To: David Rowley cc: Vik Fearing , =?UTF-8?Q?Marek_Malevi=C4=8D?= , pgsql-bugs@lists.postgresql.org Subject: Re: Broken type checking for empty subqueries In-reply-to: References: <7e55db68-7169-4e43-363e-947c79ba7922@malevicovi.net> <42808eee-9a68-cfbd-924c-db895d13f9c0@postgresfriends.org> Comments: In-reply-to David Rowley message dated "Fri, 29 Sep 2023 01:41:11 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <960059.1695913059.1@sss.pgh.pa.us> Date: Thu, 28 Sep 2023 10:57:39 -0400 Message-ID: <960060.1695913059@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > I've not looked at the code to see if this would be practical or not, > but I wonder if we could reduce these bug reports by using the new > soft error reporting that's now done in the input functions to have > constant folding just silently not do any folding for the expression > if a cast fails. Sadly, I doubt that would cover enough of the problem space to make much difference to people who try to do this sort of thing. > ... I imagine most people who > have had them fail during constant folding have just redesigned or > found some hack to prevent the folding from taking place anyway. Yeah. The given query looks like it was already hacked to avoid constant-folding, though I wonder if whoever wrote it really understood that. Otherwise it'd be a lot more natural to use something like CASE. Anyway, adding OFFSET 0 to suppress sub-select folding is probably the best answer here. regards, tom lane