Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B2B9C632527 for ; Wed, 28 Apr 2010 04:45:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 36379-09 for ; Wed, 28 Apr 2010 07:45:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from vsmail.isc84.org (vsmail.isc84.org [92.103.170.130]) by mail.postgresql.org (Postfix) with ESMTP id 3B7B563249B for ; Wed, 28 Apr 2010 04:45:23 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by vsmail.isc84.org (Postfix) with ESMTP id 8708E170180; Wed, 28 Apr 2010 09:45:21 +0200 (CEST) X-Virus-Scanned: Scanneur Antivirus isc84.org Received: from vsmail.isc84.org ([127.0.0.1]) by localhost (vsmail.isc84.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1RLj2YIlEMmE; Wed, 28 Apr 2010 09:45:11 +0200 (CEST) Received: from [172.18.101.2] (unknown [172.18.101.2]) by vsmail.isc84.org (Postfix) with ESMTP id 78FE917017A; Wed, 28 Apr 2010 09:45:11 +0200 (CEST) Message-ID: <4BD7E787.8080703@isc84.org> Date: Wed, 28 Apr 2010 09:45:11 +0200 From: Olivier Bouiron Reply-To: o.bouiron@isc84.org User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); fr; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: Oliver Jowett CC: h.henoch@isc84.org, PostgreSQL - JDBC Subject: Re: [Jdbc-commits] JDBC and real values returned by Postgres References: <4BD69D2D.3030508@isc84.org> <4BD77B70.40603@opencloud.com> In-Reply-To: <4BD77B70.40603@opencloud.com> Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.713 tagged_above=-10 required=5 tests=BAYES_40=-0.001, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.723, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201004/69 X-Sequence-Number: 20480 Thanks, you resolved my problem!

If it can help someone, this is how to do:

    public static void main( String[] args ) {
        try {
            StringBuffer sb = new StringBuffer();
            Properties props = new Properties();

            // Connexion
            props.setProperty( "user", "postgres" );
            Connection _connexion = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/test", props );
            // Create and fill the table
            sb.append( "create temporary table test_oliv (val float);" );
            sb.append( "insert into test_oliv(val) values (1.8);" );
            sb.append( "insert into test_oliv(val) values (1.8);" );
            sb.append( "insert into test_oliv(val) values (1.8);" );
            _connexion.prepareStatement( sb.toString() ).execute();

            // Request
            ResultSet rs = _connexion.prepareStatement( "select sum(val) as t from test_oliv;" ).executeQuery();
            rs.next();
            System.out.println( "Before:" );
            // Responses from jdbc driver: not the same displayed by the basic psql editor of postgres.
            System.out.println( "Value: " + rs.getFloat( "t" ) );
            rs.close();

           
_connexion.prepareStatement( "SET extra_float_digits=0" ).execute();
            rs = _connexion.prepareStatement( "select sum(val) as t from test_oliv;" ).executeQuery();
            rs.next();
            System.out.println( "After:" );
            // Responses from jdbc driver: the same displayed by the basic psql editor of postgres.
            System.out.println( "Value: " + rs.getFloat( "t" ) );

            rs.close();

            _connexion.close();
        } catch ( Exception e ) {
            e.printStackTrace();
        }
    }

Regards

Olivier Bouiron

Le 28/04/2010 02:04, Oliver Jowett a écrit :
Olivier Bouiron wrote:

Under the psql editor, when I want the sum of these 3 rows, the answer is 5.4.
But, under Java using the JDBC connector, the answer is 5.399999

I tried to use an other connector (postgresql-8.2-510.jdbc4) and the problem disapears.

I'd guess that it is due to newer drivers setting extra_float_digits. See http://archives.postgresql.org/pgsql-jdbc/2009-05/msg00077.php

-O


-- 
Olivier Bouiron
Institut Sainte Catherine
1750, chemin du lavarin
84000 AVIGNON
Tel: 04.90.27.57.43