Re: BUG #12053: Strange behavior for numeric types with unspecified precision-scale

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: tommaso(dot)sala(at)cla-it(dot)eu
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #12053: Strange behavior for numeric types with unspecified precision-scale
Date: 2014-11-26 15:50:51
Message-ID: 14914.1417017051@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

tommaso(dot)sala(at)cla-it(dot)eu writes:
> We found out that PgSql acts weirdly when using "numeric" type with
> UN-specified precision and scale
> Writing 0.001 via a .net DataAdapter to a numeric column with unspecified
> precision-scale results in a weird 0.00 value:
> if you later
> SELECT "that value" + 0.001 you get 0.002,
> but if you
> SELECT "that value" * 2 you get 0.00
> and
> SELECT "that value" * 5 gives a rounded 0.01
> Value in the database is correct, since if you TO_CHAR it, it gets printed
> correctly as .001, but if you SELECT it, you get 0.00
> Also, the weirder thing is that 0.000001 doesn't get truncated!

I think you must have some issues with the .Net adapter. Postgres
itself doesn't give such inconsistent results:

regression=# create table t1 (f1 numeric);
CREATE TABLE
regression=# insert into t1 values (0.001);
INSERT 0 1
regression=# select * from t1;
f1
-------
0.001
(1 row)

regression=# select f1 + 0.001 from t1;
?column?
----------
0.002
(1 row)

regression=# select f1 * 2 from t1;
?column?
----------
0.002
(1 row)

regression=# select f1 * 5 from t1;
?column?
----------
0.005
(1 row)

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2014-11-26 16:19:49 Re: BUG #12070: hstore extension: hstore_to_json_loose produces invalid JSON
Previous Message henrik-postgres 2014-11-26 14:19:24 BUG #12072: init script creates pid file with wrong owner