pgsql: Fix to_number() to correctly ignore thousands separator when it'

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix to_number() to correctly ignore thousands separator when it'
Date: 2013-05-11 20:35:08
Message-ID: E1UbGVY-0002tP-8Q@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix to_number() to correctly ignore thousands separator when it's '.'.

The existing code in NUM_numpart_from_char has hard-wired logic to treat
'.' as decimal point, even when we're using a locale-aware format string
and the locale says that '.' is the thousands separator. This results in
clearly wrong answers in FM mode (where we must be able to identify the
decimal point location), as per bug report from Patryk Kordylewski.

Since the initialization code in NUM_prepare_locale already sets up
Np->decimal as either the locale decimal-point string or "." depending
on which decimal-point format code was used, there's really no need to
have any extra logic at all in NUM_numpart_from_char: we only need to
test for a match to Np->decimal.

(Note: AFAICS there's nothing in here that explicitly checks for thousands
separators --- rather, any unmatched character is silently skipped over.
That's pretty bogus IMO but it's not the issue being complained of.)

This is a longstanding bug, but it's possible that some existing apps
are depending on '.' being recognized as decimal point even when using
a D format code. Hence, no back-patch. We should probably list this
as a potential incompatibility in the 9.3 release notes.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/35d50b527a9f99e22a317269ceb00491397d0e00

Modified Files
--------------
src/backend/utils/adt/formatting.c | 36 ++++++++++++------------------------
1 files changed, 12 insertions(+), 24 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message pgsql 2013-05-11 21:00:21 pgsql: Tag refs/tags/REL9_3_BETA1 was created
Previous Message Tom Lane 2013-05-11 20:14:25 pgsql: Fix buildfarm incompatibility in updated pg_upgrade test script.