Re: Mapping Java BigDecimal

From: "Donald Fraser" <postgres(at)kiwi-fraser(dot)net>
To: "[JDBC]" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Mapping Java BigDecimal
Date: 2010-01-20 10:02:19
Message-ID: B3CF49FF1A8B405BB64E09E642B16B5E@DEVELOP1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Ok I finally see what you are getting at.
However I personally think that PostgreSQL is more correct.

In Oracle (excuse the format if this type-cast is not valid in Oracle - I've
never used Oracle)
SELECT '3'::number(6,2)
3

In PostgreSQL
SELECT '3'::numeric(6,2);
3.00

In Java
test = new BigDecimal("3").setScale(2);
System.out.println(test.toPlainString());
3.00

If you have set a scale in PostgreSQL you will always get that number of
decimal points and therefore your result from the database will always be
consistent and therefore predictable.
I would not want a database that returned data in any other way, just my
opinion of course.

Donald

----- Original Message -----
From: "dmp" <danap(at)ttc-cmc(dot)net>
To: <pgsql-jdbc(at)postgresql(dot)org>
Sent: Wednesday, January 20, 2010 4:27 AM
Subject: Re: [JDBC] Mapping Java BigDecimal

>> I would like to disagree with the statement that PostgreSQL
>> numeric is a real with rounding to the precision specified.
>
>
> I concede my mis-statement.
>
>> 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
>
>
> Oracle NUMBER(19,2), (precision,scale) is just the same as NUMERIC(19,2),
> but if do
>
> Oracle NUMBER(19,2) ----> PostgreSQL Numeric, no precision yields the
> desired result
> as Jakub has figured out and keeps whatever precision input.
>
> danap.
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message John T. Dow 2010-01-20 14:07:58 Re: refreshRow is slow
Previous Message dmp 2010-01-20 04:27:46 Re: Mapping Java BigDecimal