Re: PreparedStatement rounds doubles to scale 14 during update

From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "Peter Kovacs" <maxottovonstirlitz(at)gmail(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: PreparedStatement rounds doubles to scale 14 during update
Date: 2007-09-05 10:01:30
Message-ID: 46DE7E7A.70208@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Peter Kovacs wrote:
> Hi,
>
> I have the following problem with postgresql-8.1-407.jdbc3.jar used
> against a 8.1 version backend.
>
> A table "chemterms_cols_test" has a column "logp" defined as:
>
> logp numeric(30,17)
>
> The double value 6.118992224252588 gets rounded to 6.11899222425259000
> during updates with PreparedStatements using place-holder. (There is
> no rounding with Statement and the value specified in the SQL
> literally.) Is this the expected behaviour?

The problem is in the conversion from double to numeric in the server.
The server-side float8 data type doesn't have enough precision for that
many decimal places. Because converting between numeric and
floating-point data types almost always leads to rounding errors at some
point, I would strongly recommend sticking to base-10 data types
everywhere if you care about the precision.

If you use BigDecimal instead of double in your java-program, it works fine.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Albe Laurenz 2007-09-05 10:34:14 RE: [JDBC] Questión of JDBC
Previous Message Peter Kovacs 2007-09-05 09:27:19 PreparedStatement rounds doubles to scale 14 during update