Re: [HACKERS] Numeric with '-'

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [HACKERS] Numeric with '-'
Дата
Msg-id 27928.951162722@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Numeric with '-'  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
Ответы RE: [HACKERS] Numeric with '-'  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
Список pgsql-hackers
"Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
> The following phenomenon was reported to pgsql-jp(ML in Japan).

> rest=# select -1234567890.1234567;
> ERROR:  Unable to convert left operator '-' from type 'unknown'

I've committed fixes that make the parser treat numeric literals
the same no matter how many digits they have.  With current sources,

regression=# select -1234567890.1234567;    ?column?
--------------------1234567890.12346
(1 row)

which is probably still not what you want, because the default
type for a non-integer literal is float8 in the absence of any
context to clue the system otherwise, so you lose precision.
You can do

regression=# select -1234567890.12345678900::numeric;       ?column?
--------------------------1234567890.12345678900
(1 row)

but in reality that's only working because of the way that doNegate
works on literals; since there is no unary minus operator for NUMERIC,
a minus on a non-constant value is going to be coerced to float8:

regression=# select -val from num_data;    ?column?
------------------               0               0 34338492.215397           -4.31   -7799461.4119   -16397.038491
-93901.57763026       83028485          -7488124926804.0450474
 
(10 rows)

whereas this works right:

regression=# select 0-val from num_data;     ?column?
---------------------       0.0000000000       0.000000000034338492.2153970470      -4.3100000000-7799461.4119000000
-16397.0384910000 -93901.577630260083028485.0000000000  -74881.000000000024926804.0450474200
 
(10 rows)

Somebody ought to write a NUMERIC unary minus...
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: [HACKERS] new backslash command of psql
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] new backslash command of psql