Re: BUG #19350: Short circuit optimization missed when running sqlscriptes in JDBC

From: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
To: ZhangChi <798604270(at)qq(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #19350: Short circuit optimization missed when running sqlscriptes in JDBC
Date: 2025-12-16 15:17:08
Message-ID: CAKAnmmJ=SfR-C3f9Y6Soi=g-QPRqaxzY5pbUa3QMZsStHMJP6A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>
> I wonder why this query triggers an error under JDBC but not in the CLI.

Fails as expected from the command line:

prepare foo1 as select 99 / $1::int * $2;
PREPARE
execute foo1(0, null);
ERROR: division by zero

prepare foo2 as select 99 / ($1::int * $2);
PREPARE
execute foo2(0, null);
?column?
----------

(1 row)

prepare foo3 as select (99 / $1::int) * $2;
PREPARE
execute foo3(0, null);
ERROR: division by zero

If you want the "null combined with anything = null" to always happen
before the "divide by zero is wrong" make your query specific like in foo2
above.

Cheers,
Greg

--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products & Tech Support

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-12-16 15:41:46 Re: BUG #19354: JOHAB rejects valid byte sequences
Previous Message Robert Haas 2025-12-16 14:26:12 Re: BUG #19354: JOHAB rejects valid byte sequences