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.96) (envelope-from ) id 1vxsyP-00HEFV-1L for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Mar 2026 20:37:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vxsyN-00ECfI-2U for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Mar 2026 20:37:36 +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.96) (envelope-from ) id 1vxsyN-00ECf9-1h for pgsql-bugs@lists.postgresql.org; Wed, 04 Mar 2026 20:37:36 +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.98.2) (envelope-from ) id 1vxsyL-00000000coT-2yTM for pgsql-bugs@lists.postgresql.org; Wed, 04 Mar 2026 20:37:35 +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 624KbMmE1656488; Wed, 4 Mar 2026 15:37:22 -0500 From: Tom Lane To: "David G. Johnston" cc: =?UTF-8?Q?Bj=C3=B6rn_Kautler?= , Tender Wang , "pgsql-bugs@lists.postgresql.org" , Laurenz Albe Subject: Re: GROUP BY in CTE causes ELSE in outer query to be prematurely evaluated In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Wed, 04 Mar 2026 12:32:04 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1656486.1772656642.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 04 Mar 2026 15:37:22 -0500 Message-ID: <1656487.1772656642@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 Wednesday, March 4, 2026, Bj=C3=B6rn Kautler wro= te: >> What I tried to do was to provoke the division-by-zero error if I happe= ned >> to forget some WHEN branch as this is a bug. >> Is there some safe way to do something like this you are aware of > Write a volatile =E2=80=9Cfail()=E2=80=9D plpgsql function, and call it = in the else block. > Raise exception there. Right. An intentional failure is a side-effect, and immutable subexpressions are not supposed to have side-effects. As long as you mark the fail() function volatile, the planner will avoid pre-evaluating it. regards, tom lane