From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)jp> |
Cc: | "pgsql-hackers" <pgsql-hackers(at)postgreSQL(dot)org> |
Subject: | Re: [HACKERS] Numeric with '-' |
Date: | 2000-02-21 19:52:02 |
Message-ID: | 27928.951162722@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
"Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)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
-74881
24926804.0450474
(10 rows)
whereas this works right:
regression=# select 0-val from num_data;
?column?
---------------------
0.0000000000
0.0000000000
34338492.2153970470
-4.3100000000
-7799461.4119000000
-16397.0384910000
-93901.5776302600
83028485.0000000000
-74881.0000000000
24926804.0450474200
(10 rows)
Somebody ought to write a NUMERIC unary minus...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Kaare Rasmussen | 2000-02-21 19:58:44 | Re: [HACKERS] Beta for 4:30AST ... ? |
Previous Message | j.j.geel | 2000-02-21 19:50:55 |