BUG #18976: -0.0 with float8 will be transformed to 0 in prepare statement but not in normal execution

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: 798604270(at)qq(dot)com
Subject: BUG #18976: -0.0 with float8 will be transformed to 0 in prepare statement but not in normal execution
Date: 2025-07-03 03:03:05
Message-ID: 18976-c1bc92542b90e5e6@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 18976
Logged by: Chi Zhang
Email address: 798604270(at)qq(dot)com
PostgreSQL version: 18beta1
Operating system: Ubuntu 24.04 and docker
Description:

The value -0.0 with float8 is transformed to 0 in prepared statements but
remains -0 in normal execution. Although 0 and -0 are numerically equal,
this discrepancy can lead to subtle bugs in certain cases—for example, when
the value is cast to a VARCHAR, as illustrated below.
```
PREPARE prepare_query (float8) AS SELECT CAST($1 AS VARCHAR) =
CAST(-0.0::float8 AS VARCHAR);
EXECUTE prepare_query(-0.0); -- f
```

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Laurenz Albe 2025-07-03 12:23:42 Re: BUG #18976: -0.0 with float8 will be transformed to 0 in prepare statement but not in normal execution
Previous Message Tom Lane 2025-07-02 19:21:50 Re: BUG #18974: Postgresql repeatable crash after pg_upgrade from 15 to 17.5 version in postgresql_fdw queries