pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Kovacs <maxottovonstirlitz@gmail.com>
To: Heikki Linnakangas <heikki@enterprisedb.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: PreparedStatement rounds doubles to scale 14 during update
Date: Wed, 5 Sep 2007 13:42:00 +0200
Message-ID: <b6e8f2e80709050442s7439d8ebt345024599931400d@mail.gmail.com> (raw)
In-Reply-To: <46DE7E7A.70208@enterprisedb.com>
References: <b6e8f2e80709050227r420d7a3cx751f819fba658854@mail.gmail.com>
	<46DE7E7A.70208@enterprisedb.com>

Heikki,

Thank you for your reply.

What are base-10 datatypes? Are they numeric types? I cannot find them
in the backend documentation.

Is there a mapping of Java types to backend types documented somewhere?

Thanks a lot
Peter

On 9/5/07, Heikki Linnakangas <heikki@enterprisedb.com> wrote:
> 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
>



view thread (13+ messages)  latest in thread

Message-ID: <b6e8f2e80709050442s7439d8ebt345024599931400d@mail.gmail.com>
Permalink:  ../b6e8f2e80709050442s7439d8ebt345024599931400d@mail.gmail.com/
Also on:    postgresql.org/message-id/b6e8f2e80709050442s7439d8ebt345024599931400d@mail.gmail.com

 · 

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: maxottovonstirlitz@gmail.com, heikki@enterprisedb.com
  Subject: Re: PreparedStatement rounds doubles to scale 14 during update
  In-Reply-To: <b6e8f2e80709050442s7439d8ebt345024599931400d@mail.gmail.com>
  References: <b6e8f2e80709050227r420d7a3cx751f819fba658854@mail.gmail.com> <46DE7E7A.70208@enterprisedb.com> <b6e8f2e80709050442s7439d8ebt345024599931400d@mail.gmail.com>

* 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