pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: pgsql-jdbc@postgresql.org
Subject: [Fwd: Re: Mapping Java BigDecimal]
Date: Mon, 18 Jan 2010 11:02:08 -0700
Message-ID: <4B54A220.6010404@ttc-cmc.net> (raw)


> Hi All,
>
> We decide add support PostgreSQL database (now supporting only Oracle 
> database) to our product.
>
> In Oracle we mapping Java BigDecimal to number(19, 2), in PostgreSQL 
> to numeric(19, 2).
>
> If I store to "BigDecimal column" number without decimal, e.g. "3", 
> than Oracle JDBC driver return "3", but PostgreSQL JDBC driver return 
> "3.00".
>
> Is there some way (mapping, server setup, jdbc driver setup,...) how 
> reach return number without trailing zeroes on decimal position?
>
> I'm using JDBC4 PostgreSQL Driver (v. 8.4-701) and PostgreSQL v. 
> 8.1.18 (default for CentoOS 5.3).
> Thank you all 


Perhaps you should check the context of the use of this column in
your application. The designer looks like that precision which
the BigDecimal type provided was desired to be maintained by the
application. That BigDecimal if you check the docs, is a BigInteger
with a precision, scale, for rounding. The returned value is correct
as indicated by Oracle, because it really is an Integer, no decimal
places. The Numeric type in PostgreSQL is really not the same since
it is a real with specified precision and decimal places. If you
do choose Graig's recommendation, removing decimal places, you mind
as well limit perhaps the database storage for this column and define
as Numeric (19,2) which more clearly maintains the original intent
of the column. See below just numeric with no specification will
return decimal places if given.

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 ('3.53', '3.53');
INSERT 0 1
postgres=# SELECT SUM(x), SUM(y) FROM test;
sum  | sum
------+------
7.01 | 7.01
(1 row)

danap.







Message-ID: <4B54A220.6010404@ttc-cmc.net>
Permalink:  ../4B54A220.6010404@ttc-cmc.net/
Also on:    postgresql.org/message-id/4B54A220.6010404@ttc-cmc.net

 · 

reply

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: [Fwd: Re: Mapping Java BigDecimal]
  In-Reply-To: <4B54A220.6010404@ttc-cmc.net>
  References: <4B54A220.6010404@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