Re: BUG #18965: Issue with Short-Circuit Evaluation in Boolean Expressions

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: brandystodd@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-06-20T18:37:10Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> CREATE OR REPLACE FUNCTION raise(
>     IN          i_msg           text
> )
> RETURNS text AS $$
> BEGIN
>     RAISE EXCEPTION '%', i_msg;
>     RETURN ''::text;
> END;$$
> LANGUAGE PLPGSQL
> IMMUTABLE STRICT;

I think the fundamental problem you're having is that you marked
this function IMMUTABLE, which gives the planner license to
pre-evaluate it.  It had better be VOLATILE to discourage advance
evaluation.

https://www.postgresql.org/docs/current/xfunc-volatility.html

			regards, tom lane