Re: GROUP BY in CTE causes ELSE in outer query to be prematurely evaluated - Mailing list pgsql-bugs

From Tom Lane
Subject Re: GROUP BY in CTE causes ELSE in outer query to be prematurely evaluated
Date
Msg-id 1656487.1772656642@sss.pgh.pa.us
Whole thread Raw
In response to Re: GROUP BY in CTE causes ELSE in outer query to be prematurely evaluated  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Wednesday, March 4, 2026, Björn Kautler <Bjoern@kautler.net> 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



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: GROUP BY in CTE causes ELSE in outer query to be prematurely evaluated
Next
From: Rafia Sabih
Date:
Subject: Re: Two issues with REFRESH MATERIALIZED VIEW CONCURRENTLY