mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
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
This commit is contained in:
@@ -5804,14 +5804,14 @@ NUM_numpart_to_char(NUMProc *Np, int id)
|
||||
++Np->inout_p;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (*Np->number_p)
|
||||
{
|
||||
*Np->inout_p = *Np->number_p; /* Write DIGIT */
|
||||
++Np->inout_p;
|
||||
Np->num_in = true;
|
||||
}
|
||||
}
|
||||
/* do no exceed string length */
|
||||
/* do not advance past end of string */
|
||||
if (*Np->number_p)
|
||||
++Np->number_p;
|
||||
}
|
||||
|
||||
@@ -2116,6 +2116,12 @@ SELECT to_char('100'::numeric, 'FM999.');
|
||||
100
|
||||
(1 row)
|
||||
|
||||
SELECT to_char('100'::numeric, 'FM999.SG "items"');
|
||||
to_char
|
||||
------------
|
||||
100+ items
|
||||
(1 row)
|
||||
|
||||
SELECT to_char('100'::numeric, 'FM999');
|
||||
to_char
|
||||
---------
|
||||
|
||||
@@ -1033,6 +1033,7 @@ FROM v;
|
||||
|
||||
SELECT to_char('100'::numeric, 'FM999.9');
|
||||
SELECT to_char('100'::numeric, 'FM999.');
|
||||
SELECT to_char('100'::numeric, 'FM999.SG "items"');
|
||||
SELECT to_char('100'::numeric, 'FM999');
|
||||
SELECT to_char('12345678901'::float8, 'FM9999999999D9999900000000000000000');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user