From: dmp <danap@ttc-cmc.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: Mapping Java BigDecimal
Date: Tue, 19 Jan 2010 07:59:31 -0700
Message-ID: <4B55C8D3.7090907@ttc-cmc.net> (raw)
In-Reply-To: <407d949e1001190304m1bfea314ta5bd89e035d01c9@mail.gmail.com>
References: <4B540B7D.1080306@b2bcentrum.cz>
<4B541C40.9040206@postnewspapers.com.au>
<407d949e1001180209v39e46a88v6d5a0e5a181a5d84@mail.gmail.com>
<4B55371B.40105@postnewspapers.com.au>
<407d949e1001190304m1bfea314ta5bd89e035d01c9@mail.gmail.com>
Yesterday I indirectly, but did not completely demonstrate
the difference between the BigDecimal and Numeric data
types in the databases. My example indicated the precision
is carried and return in the default when no precision is given
for Numeric, but more importantly:
postgres=# CREATE TEMP TABLE test (x numeric, y numeric(19, 2));
CREATE TABLE
postgres=# INSERT INTO test VALUES ('3.48', '3.48');
INSERT 0 1
postgres=# INSERT INTO test VALUES ('0.056', '0.056');
INSERT 0 1
postgres=# SELECT SUM(x), SUM(y) FROM test;
sum | sum
-------+------
3.536 | 3.54
(1 row)
As indicated PostgreSQL kept the precision and rounded for
the specified y column to the precision defined. The unspecified
precision column x just kept on adding precision decimal places.
If you chop either the x or y column decimal places you will
get the whole Integer 3. The same process in Oracle for the summing
with a BigDecimal data type I suspect most likely will return 4.
The BigDecimal is a BigInteger rounded to the specified precision.
Quite a difference creature than the Numeric(19, 2) in PostgreSQL,
which is real with rounding to the precision specified, not to the
nearest whole Integer.
Perhaps this whole mapping question should be put over to the
database forum for an appropriate answer to BigDecimal to what
in PostgreSQL.
danap.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: danap@ttc-cmc.net
Subject: Re: Mapping Java BigDecimal
In-Reply-To: <4B55C8D3.7090907@ttc-cmc.net>
References: <4B540B7D.1080306@b2bcentrum.cz> <4B541C40.9040206@postnewspapers.com.au> <407d949e1001180209v39e46a88v6d5a0e5a181a5d84@mail.gmail.com> <4B55371B.40105@postnewspapers.com.au> <407d949e1001190304m1bfea314ta5bd89e035d01c9@mail.gmail.com> <4B55C8D3.7090907@ttc-cmc.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox