Re: Inconsistency between TO_CHAR() and TO_NUMBER()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Patryk Kordylewski <pk(at)fooby(dot)de>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Inconsistency between TO_CHAR() and TO_NUMBER()
Date: 2013-05-10 15:49:18
Message-ID: 8415.1368200958@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Patryk Kordylewski <pk(at)fooby(dot)de> writes:
> SET lc_numeric TO 'de_DE.UTF-8';
> SET

> SELECT
> TO_CHAR(123456789.123, 'FM99G999G999G999G999G999G999D000'),
> TO_NUMBER(TO_CHAR(123456789.123, 'FM99G999G999G999G999G999G999D000'),
> 'FM99G999G999G999G999G999G999D000');
> to_char | to_number
> -----------------+-----------
> 123.456.789,123 | 123.456
> (1 row)

I looked into this, and find that the reason it misbehaves is that
NUM_numpart_from_char() will treat a '.' as being a decimal point
*without any regard to locale considerations*. So even if we have
a locale-dependent format string and a locale that says '.' is a
thousands separator, it does the wrong thing.

It's a bit surprising nobody's complained of this before.

I propose the attached patch. I'm slightly worried though about whether
this might break any existing applications that are (incorrectly)
depending on a D format specifier being able to match '.' regardless of
locale. Perhaps we should only apply this to HEAD and not back-patch?

regards, tom lane

Attachment Content-Type Size
fix-to-number-locale-thousands.patch text/x-patch 2.3 KB
unknown_filename text/plain 149 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas Kellerer 2013-05-10 16:09:58 Re: Inconsistency between TO_CHAR() and TO_NUMBER()
Previous Message Tom Lane 2013-05-10 13:10:38 Re: Strange time zone +00:53:28