I wrote:
> However, when you poke at that a bit closer, it's not a license
> for unlimited whitespace:

> regression=# select to_number('123  456', '999999');
>  to_number 
> -----------
>      12345
> (1 row)

> I've not tracked down the exact cause of that, but I think it
> has to do with the fact that NUM_numpart_from_char() is willing
> to eat a single leading space per call, even if it's not the
> first call.

I tried simply removing that bit:

diff --git a/src/backend/utils/adt/formatting.c 
b/src/backend/utils/adt/formatting.c
index 3960235e14..366430863f 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5134,12 +5134,6 @@ NUM_numpart_from_char(NUMProc *Np, int id, int input_len)
                 (id == NUM_0 || id == NUM_9) ? "NUM_0/9" : id == NUM_DEC ? 
"NUM_DEC" : "???");
 #endif
 
-       if (OVERLOAD_TEST)
-               return;
-
-       if (*Np->inout_p == ' ')
-               Np->inout_p++;
-
        if (OVERLOAD_TEST)
                return;
 

All our regression tests still pass, and this example seems to behave
more sanely:

regression=# select to_number('123 456', '999999');
 to_number 
-----------
     12345
(1 row)

regression=# select to_number('123  456', '999999');
 to_number 
-----------
      1234
(1 row)

That might or might not be a behavior you like, but it's at least
possible to see where it's coming from: it's eating the digits that
appear within a six-character window, and not any more.

Not sure if anyone would thank us for making this change though.
I can't avoid the suspicion that somebody somewhere is depending
on the current behavior.

Anyway, this is getting off-topic for the current thread.

                        regards, tom lane


Reply via email to