Thread: pgsql: Further fix for psql's code for locale-aware formatting of numer

pgsql: Further fix for psql's code for locale-aware formatting of numer

From
Tom Lane
Date:
Further fix for psql's code for locale-aware formatting of numeric output.

On closer inspection, those seemingly redundant atoi() calls were not so
much inefficient as just plain wrong: the author of this code either had
not read, or had not understood, the POSIX specification for localeconv().
The grouping field is *not* a textual digit string but separate integers
encoded as chars.

We'll follow the existing code as well as the backend's cash.c in only
honoring the first group width, but let's at least honor it correctly.

This doesn't actually result in any behavioral change in any of the
locales I have installed on my Linux box, which may explain why nobody's
complained; grouping width 3 is close enough to universal that it's barely
worth considering other cases.  Still, wrong is wrong, so back-patch.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/6325527d845b629243fb3f605af6747a7a4ac45f

Modified Files
--------------
src/bin/psql/print.c |   14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)


Re: pgsql: Further fix for psql's code for locale-aware formatting of numer

From
Bruce Momjian
Date:
Offlist, I think it was this commit:

    commit 73a7c322c36bb96d4e2d053ff245b0f7b99f09e0
    Author: Bruce Momjian <bruce@momjian.us>
    Date:   Sun Jul 10 03:46:13 2005 +0000

        Add psql \pset numericsep to allow output numbers like 100,000.0 or
        100.000,0.

        Eugen Nedelcu

which I later wacked around too:

    commit 45a19efa9ec66fa35cc86671e2a1cebfe787fd9f
    Author: Bruce Momjian <bruce@momjian.us>
    Date:   Thu Jul 14 08:42:37 2005 +0000

        Change numericsep to a boolean, and make it locale-aware.

    commit bd157821649ae203b9c8ce8daf4ec027a0003351
    Author: Bruce Momjian <bruce@momjian.us>
    Date:   Thu Jul 14 21:12:41 2005 +0000

        Enable multi-byte thousands_sep and decimal_point for numericsep.

    commit 507465525e8c3e4ebf0159ac07c915dd609cd6b3
    Author: Bruce Momjian <bruce@momjian.us>
    Date:   Mon Jul 18 20:57:53 2005 +0000

        \pset numericsep -> numericlocale.

    commit 8ddd22f2456af0155f9c183894f481203e86b76e
    Author: Bruce Momjian <bruce@momjian.us>
    Date:   Tue Sep 27 16:30:25 2005 +0000

        Fix incorrect psql \x memory allocation for numericlocale.  Redesign API
        to be less error-prone.

Obviously this was all a very long time ago.

---------------------------------------------------------------------------

On Fri, Sep 25, 2015 at 04:01:33AM +0000, Tom Lane wrote:
> Further fix for psql's code for locale-aware formatting of numeric output.
>
> On closer inspection, those seemingly redundant atoi() calls were not so
> much inefficient as just plain wrong: the author of this code either had
> not read, or had not understood, the POSIX specification for localeconv().
> The grouping field is *not* a textual digit string but separate integers
> encoded as chars.
>
> We'll follow the existing code as well as the backend's cash.c in only
> honoring the first group width, but let's at least honor it correctly.
>
> This doesn't actually result in any behavioral change in any of the
> locales I have installed on my Linux box, which may explain why nobody's
> complained; grouping width 3 is close enough to universal that it's barely
> worth considering other cases.  Still, wrong is wrong, so back-patch.
>
> Branch
> ------
> master
>
> Details
> -------
> http://git.postgresql.org/pg/commitdiff/6325527d845b629243fb3f605af6747a7a4ac45f
>
> Modified Files
> --------------
> src/bin/psql/print.c |   14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
>
> --
> Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-committers

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription                             +


Re: pgsql: Further fix for psql's code for locale-aware formatting of numer

From
Bruce Momjian
Date:
Oops, I guess it wasn't offlist.  Anyway, now everyone knows I might
have been one of the original authors that required the triple-commit
fix.  ;-)

---------------------------------------------------------------------------

On Sun, Oct  4, 2015 at 09:57:52PM -0400, Bruce Momjian wrote:
>
> Offlist, I think it was this commit:
>
>     commit 73a7c322c36bb96d4e2d053ff245b0f7b99f09e0
>     Author: Bruce Momjian <bruce@momjian.us>
>     Date:   Sun Jul 10 03:46:13 2005 +0000
>
>         Add psql \pset numericsep to allow output numbers like 100,000.0 or
>         100.000,0.
>
>         Eugen Nedelcu
>
> which I later wacked around too:
>
>     commit 45a19efa9ec66fa35cc86671e2a1cebfe787fd9f
>     Author: Bruce Momjian <bruce@momjian.us>
>     Date:   Thu Jul 14 08:42:37 2005 +0000
>
>         Change numericsep to a boolean, and make it locale-aware.
>
>     commit bd157821649ae203b9c8ce8daf4ec027a0003351
>     Author: Bruce Momjian <bruce@momjian.us>
>     Date:   Thu Jul 14 21:12:41 2005 +0000
>
>         Enable multi-byte thousands_sep and decimal_point for numericsep.
>
>     commit 507465525e8c3e4ebf0159ac07c915dd609cd6b3
>     Author: Bruce Momjian <bruce@momjian.us>
>     Date:   Mon Jul 18 20:57:53 2005 +0000
>
>         \pset numericsep -> numericlocale.
>
>     commit 8ddd22f2456af0155f9c183894f481203e86b76e
>     Author: Bruce Momjian <bruce@momjian.us>
>     Date:   Tue Sep 27 16:30:25 2005 +0000
>
>         Fix incorrect psql \x memory allocation for numericlocale.  Redesign API
>         to be less error-prone.
>
> Obviously this was all a very long time ago.
>
> ---------------------------------------------------------------------------
>
> On Fri, Sep 25, 2015 at 04:01:33AM +0000, Tom Lane wrote:
> > Further fix for psql's code for locale-aware formatting of numeric output.
> >
> > On closer inspection, those seemingly redundant atoi() calls were not so
> > much inefficient as just plain wrong: the author of this code either had
> > not read, or had not understood, the POSIX specification for localeconv().
> > The grouping field is *not* a textual digit string but separate integers
> > encoded as chars.
> >
> > We'll follow the existing code as well as the backend's cash.c in only
> > honoring the first group width, but let's at least honor it correctly.
> >
> > This doesn't actually result in any behavioral change in any of the
> > locales I have installed on my Linux box, which may explain why nobody's
> > complained; grouping width 3 is close enough to universal that it's barely
> > worth considering other cases.  Still, wrong is wrong, so back-patch.
> >
> > Branch
> > ------
> > master
> >
> > Details
> > -------
> > http://git.postgresql.org/pg/commitdiff/6325527d845b629243fb3f605af6747a7a4ac45f
> >
> > Modified Files
> > --------------
> > src/bin/psql/print.c |   14 +++++++++++---
> > 1 file changed, 11 insertions(+), 3 deletions(-)
> >
> >
> > --
> > Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-committers
>
> --
>   Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>   EnterpriseDB                             http://enterprisedb.com
>
> + As you are, so once was I. As I am, so you will be. +
> + Roman grave inscription                             +
>
>
> --
> Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-committers

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription                             +