Re: [HACKERS] Fix number skipping in to_number

From: Oliver Ford <ojford(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Fix number skipping in to_number
Date: 2017-11-13 16:18:44
Message-ID: CAGMVOdvwpMyQ+6PmVMVJupzcDe3wLcrUtVdXMbOKYibTAY6G0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Nov 12, 2017 at 7:00 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Oliver Ford <ojford(at)gmail(dot)com> writes:
>> [ 0001-apply-number-v3.patch ]
>
> I looked at this patch briefly and have a couple of comments:
>
> * It seems entirely wrong to be matching to L_thousands_sep in the
> NUM_COMMA case; that format code is by definition not locale aware,
> so it should be matching to plain ',' independently of locale.

Ok I've changed it to just search for a comma.

> * Don't we need to fix the NUM_L (currency symbol) case in the
> same manner? (The NUM_D and NUM_S cases are handled in
> NUM_numpart_from_char and seem ok at a quick glance.)

Yes you get the same skipping if you do:

select to_number('12','L99');
to_number
-----------
2

However, this case is not as easy to fix as you can't do a simple
string comparison like with the group separator. The currency symbol
for the locale can be " " but if we do a comparison, it won't match if
the symbol specified is "$" or "£" (so will end up missing characters
at the end of the supplied string). Could we apply the attached patch
and then put fixing it for currency on the TODO list?

> * I'm not in love with the noadd flag. Other places in this
> switch that want to skip the final increment do it with
> "continue", and I think this should do likewise.

I've changed to continue in the latest patch. All existing tests pass.

Attachment Content-Type Size
0001-apply-number-v4.patch application/octet-stream 3.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-11-13 16:26:27 Re: [HACKERS] Fix number skipping in to_number
Previous Message Alvar Freude 2017-11-13 16:07:05 Re: Migration to PGLister - After