The following bug has been logged on the website:
Bug reference: 18965
Logged by: Todd Brandys
Email address: brandystodd@gmail.com
PostgreSQL version: 17.5
Operating system: Linux
Description:
In the circumstance where a function evaluation is performed within Boolean
expression, the evaluation seems to continue past a function returning a
TRUE value. Here is a very boiled down version of my code, but it results
in the same issue. In the first SELECT statement, I get the expected
result, a single row with a TRUE value. In the other two SELECT statements,
an EXCEPTION is thrown, which is unexpected.
CREATE OR REPLACE FUNCTION raise(
IN i_msg text
)
RETURNS text AS $$
BEGIN
RAISE EXCEPTION '%', i_msg;
RETURN ''::text;
END;$$
LANGUAGE PLPGSQL
IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION test( )
RETURNS boolean AS $$
SELECT TRUE; $$
LANGUAGE SQL
IMMUTABLE STRICT;
SELECT TRUE OR public.raise('this exception should not be
raised')::boolean;
SELECT pg_catalog.PG_HAS_ROLE('postgres', 'postgres', 'member')
OR public.raise('this exception should not be raised')::boolean;
SELECT public.test() OR public.raise('this exception should not be
raised')::boolean;
Again, I am using PostgreSQL 17.5, compiled from source. I have no
extensions installed in the database. Here is the configure script I used
to build the distribution:
export PYTHON=/var/lib/pgsql/venv/bin/python3
./configure \
--prefix=/usr/local/installed/postgresql-17.5 \
--enable-atomics --enable-largefile --with-llvm --with-perl
--with-readline --with-python \
--with-uuid=ossp --with-zlib --with-ssl=openssl --with-libxml
--with-libxslt