public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: David G. Johnston <[email protected]>
Cc: Björn Kautler <[email protected]>
Cc: Tender Wang <[email protected]>
Cc: [email protected] <[email protected]>
Cc: Laurenz Albe <[email protected]>
Subject: Re: GROUP BY in CTE causes ELSE in outer query to be prematurely evaluated
Date: Wed, 04 Mar 2026 15:37:22 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAKFQuwZT0UaOiV+2h6f42_U_tU34wXH3Gv8BrjF_U168SWS5PQ@mail.gmail.com>
References: <CAKChYSo2n2_q_XtvO-3ow+Q0dSuWdzwydLbtr3Q12X65bqhL=g@mail.gmail.com>
	<CAHewXNnVarUKNXrJXyDH=PKs-wST7bMzyqg61_SA2Mo5PPePgw@mail.gmail.com>
	<CAKChYSrNec-ucGwK+-gjCGGSkcq1EFxi6C3RBCz5+-DwS2feJg@mail.gmail.com>
	<CAKFQuwZT0UaOiV+2h6f42_U_tU34wXH3Gv8BrjF_U168SWS5PQ@mail.gmail.com>

"David G. Johnston" <[email protected]> writes:
> On Wednesday, March 4, 2026, Björn Kautler <[email protected]> wrote:
>> What I tried to do was to provoke the division-by-zero error if I happened
>> 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 “fail()” 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






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: GROUP BY in CTE causes ELSE in outer query to be prematurely evaluated
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox