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

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "brandystodd(at)gmail(dot)com" <brandystodd(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18965: Issue with Short-Circuit Evaluation in Boolean Expressions
Date: 2025-07-08 17:34:23
Message-ID: 33ae625c9ec9072ac61708405c2e7dfe50097047.camel@j-davis.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff Davis 2025-07-08 17:48:43 Re: BUG #18965: Issue with Short-Circuit Evaluation in Boolean Expressions
Previous Message Laurenz Albe 2025-07-08 16:53:25 Re: Unexpected behavior when setting "idle_replication_slot_timeout"