From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix to_char() for number formats ending in a decimal point.
Date: Tue, 20 Oct 2026 16:56:24 +0000
Message-ID: <E1xJD8S-000000002SA-0Hsu@gemulon.postgresql.org> (raw)
Fix to_char() for number formats ending in a decimal point.
When a number format has a decimal point with no digit positions
after it (e.g. '9.' or 'FM999.PL'), NUM_numpart_to_char() copied the
terminating '\0' of the number string into the output as if it were a
digit, resulting in apparent truncation of the output; for example,
a sign or literal text following the decimal point would disappear.
Fix it by not copying the '\0'.
This is clearly a bug, but given the lack of field complaints,
people who have run into it may think it's expected behavior,
and may even have written applications that depend on it.
Therefore it seems unwise to change it in stable branches.
I (tgl) think it's not too late to fix it in v19 though.
Bug: #19771
Author: Gowtham Reddy <gowthamdoma18@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19771-4f173b891525020c@postgresql.org
Backpatch-through: 19
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/776df8a6d7c42282825d658ff631509f033e8f34
Modified Files
--------------
src/backend/utils/adt/formatting.c | 4 ++--
src/test/regress/expected/numeric.out | 6 ++++++
src/test/regress/sql/numeric.sql | 1 +
3 files changed, 9 insertions(+), 2 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Fix to_char() for number formats ending in a decimal point.
In-Reply-To: <E1xJD8S-000000002SA-0Hsu@gemulon.postgresql.org>
References: <E1xJD8S-000000002SA-0Hsu@gemulon.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