pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: David G. Johnston <david.g.johnston@gmail.com>
To: brandystodd@gmail.com <brandystodd@gmail.com>
To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #18965: Issue with Short-Circuit Evaluation in Boolean Expressions
Date: Tue, 08 Jul 2025 10:34:23 -0700
Message-ID: <33ae625c9ec9072ac61708405c2e7dfe50097047.camel@j-davis.com> (raw)
In-Reply-To: <CAKFQuwZ6qgcGCXDEHBMftRvC=qmEbh_LT-J=jU96Y2c1V3k0QA@mail.gmail.com>
References: <18965-89456ea7e640a053@postgresql.org>
	<CAKFQuwZ6qgcGCXDEHBMftRvC=qmEbh_LT-J=jU96Y2c1V3k0QA@mail.gmail.com>

On Fri, 2025-06-20 at 11:14 -0700, David G. Johnston wrote:
> > In the circumstance where a function evaluation is performed within
> > Boolean
> > expression, the evaluation seems to continue past a function
> > returning a
> > TRUE value.
> > 
> 
> Where did we claim we perform short-circuiting?

Even if you force the execution-time evaluation order with CASE, you
can still get an error:

EXPLAIN SELECT CASE WHEN random() < 2 THEN TRUE ELSE (1/0 = 0) END;
ERROR:  division by zero

The expression "random() < 2" is always true, so at execution time the
second branch will never be reached. But it is reached at planning
time.

Regards,
	Jeff Davis






view thread (5+ messages)  latest in thread

Message-ID: <33ae625c9ec9072ac61708405c2e7dfe50097047.camel@j-davis.com>
Permalink:  ../33ae625c9ec9072ac61708405c2e7dfe50097047.camel@j-davis.com/
Also on:    postgresql.org/message-id/33ae625c9ec9072ac61708405c2e7dfe50097047.camel@j-davis.com

 · 

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: pgsql@j-davis.com, david.g.johnston@gmail.com, brandystodd@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18965: Issue with Short-Circuit Evaluation in Boolean Expressions
  In-Reply-To: <33ae625c9ec9072ac61708405c2e7dfe50097047.camel@j-davis.com>

* 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