"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