Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 287919FA0B3 for ; Wed, 5 Sep 2007 07:02:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 41818-01 for ; Wed, 5 Sep 2007 07:02:30 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from mail01.enterprisedb.com (mail01.enterprisedb.com [63.246.7.168]) by postgresql.org (Postfix) with ESMTP id 9F5E69FA07F for ; Wed, 5 Sep 2007 07:02:35 -0300 (ADT) thread-index: Acfvo+lIAKOH+D2AR5yfXxsdbnzh3A== Received: from [172.24.32.97] ([62.232.55.118]) by mail01.enterprisedb.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Wed, 5 Sep 2007 06:02:46 -0400 Content-Class: urn:content-classes:message Importance: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4073 Message-ID: <46DE7E7A.70208@enterprisedb.com> Date: Wed, 05 Sep 2007 11:01:30 +0100 From: "Heikki Linnakangas" User-Agent: Icedove 1.5.0.12 (X11/20070730) MIME-Version: 1.0 To: "Peter Kovacs" Cc: Subject: Re: PreparedStatement rounds doubles to scale 14 during update References: In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 05 Sep 2007 10:02:47.0468 (UTC) FILETIME=[E935E6C0:01C7EFA3] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/14 X-Sequence-Number: 17436 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