Обсуждение: Unnexpected results using to_number()

Поиск
Список
Период
Сортировка

Unnexpected results using to_number()

От
"Andrew Snow"
Дата:
Is this supposed to happen? I discovered this when I was experimenting with
converting a string to a number.

# SELECT to_number('12,454.8-', '99G999D9S');
 to_number
-----------
  -12454.8
(1 row)

# SELECT to_number('12,454.8-', '');
pqReadData() -- backend closed the channel unexpectedly.
        This probably means the backend terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!#




I am running PostgreSQL 7.0.2 on FreeBSD 3.4-STABLE (x86).  Thanks,


- Andrew.

Re: Unnexpected results using to_number()

От
Tom Lane
Дата:
"Andrew Snow" <andrew@modulus.org> writes:
> # SELECT to_number('12,454.8-', '');
> pqReadData() -- backend closed the channel unexpectedly.

In current sources I get a NULL result, which seems to be what the
code author intended originally.  However this seems a little bit
inconsistent --- shouldn't it raise a bad-format error instead?
For example,

regression=#  SELECT to_number('12,454.8-', ' ');
ERROR:  Bad numeric input format ' '

Seems odd that no spaces means "return NULL" but 1 or more spaces
doesn't.
        regards, tom lane


Re: [HACKERS] Re: Unnexpected results using to_number()

От
Karel Zak
Дата:
On Sun, 9 Jul 2000, Tom Lane wrote:

> "Andrew Snow" <andrew@modulus.org> writes:
> > # SELECT to_number('12,454.8-', '');
> > pqReadData() -- backend closed the channel unexpectedly.
> 
> In current sources I get a NULL result, which seems to be what the
> code author intended originally.  However this seems a little bit
my original code not return NULL, but return numeric_in(NULL, 0, 0) for
this situation.

> inconsistent --- shouldn't it raise a bad-format error instead?
> For example,
> 
> regression=#  SELECT to_number('12,454.8-', ' ');
> ERROR:  Bad numeric input format ' '
Thanks for fix Tom.
                Karel