Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xterr-0002nh-Ht for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Nov 2014 15:50:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xterq-0003bp-Ur for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Nov 2014 15:50:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xterq-0003bj-BH for pgsql-bugs@postgresql.org; Wed, 26 Nov 2014 15:50:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xtern-0000o4-8b for pgsql-bugs@postgresql.org; Wed, 26 Nov 2014 15:50:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id sAQFopQ7014915; Wed, 26 Nov 2014 10:50:51 -0500 From: Tom Lane To: tommaso.sala@cla-it.eu cc: pgsql-bugs@postgresql.org Subject: Re: BUG #12053: Strange behavior for numeric types with unspecified precision-scale In-reply-to: <20141125111529.15508.34881@wrigleys.postgresql.org> References: <20141125111529.15508.34881@wrigleys.postgresql.org> Comments: In-reply-to tommaso.sala@cla-it.eu message dated "Tue, 25 Nov 2014 11:15:29 +0000" Date: Wed, 26 Nov 2014 10:50:51 -0500 Message-ID: <14914.1417017051@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org tommaso.sala@cla-it.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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs