PG Bug reporting form <noreply(at)postgresql(dot)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