pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: brandystodd@gmail.com
Subject: BUG #18965: Issue with Short-Circuit Evaluation in Boolean Expressions
Date: Fri, 20 Jun 2025 17:42:06 +0000
Message-ID: <18965-89456ea7e640a053@postgresql.org> (raw)

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



view thread (5+ messages)  latest in thread

Message-ID: <18965-89456ea7e640a053@postgresql.org>
Permalink:  ../18965-89456ea7e640a053@postgresql.org/
Also on:    postgresql.org/message-id/18965-89456ea7e640a053@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, brandystodd@gmail.com
  Subject: Re: BUG #18965: Issue with Short-Circuit Evaluation in Boolean Expressions
  In-Reply-To: <18965-89456ea7e640a053@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox