Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VKXTn-00031y-S9 for pgsql-jdbc@arkaria.postgresql.org; Fri, 13 Sep 2013 17:48:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VKXTn-0006S1-8e for pgsql-jdbc@arkaria.postgresql.org; Fri, 13 Sep 2013 17:48:27 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VKXT0-0006Qa-W6 for pgsql-jdbc@postgresql.org; Fri, 13 Sep 2013 17:47:39 +0000 Received: from www7.your-server.de ([213.133.104.7]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VKXSx-00018E-Nj for pgsql-jdbc@postgresql.org; Fri, 13 Sep 2013 17:47:38 +0000 Received: from [78.46.5.203] (helo=sslproxy01.your-server.de) by www7.your-server.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.74) (envelope-from ) id 1VKXSv-0004ER-UL; Fri, 13 Sep 2013 19:47:33 +0200 Received: from [84.148.26.216] (helo=luna) by sslproxy01.your-server.de with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1VKXSs-0003Uw-Q5; Fri, 13 Sep 2013 19:47:30 +0200 From: "Tilman Sandig" To: "'Mikko Tiihonen'" Cc: References: <004201ceb098$2d6d79f0$88486dd0$@com> <56318f6405134b7faed245cea972e928@AMSPR07MB018.eurprd07.prod.outlook.com> In-Reply-To: <56318f6405134b7faed245cea972e928@AMSPR07MB018.eurprd07.prod.outlook.com> Subject: Re: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString() Date: Fri, 13 Sep 2013 19:47:23 +0200 Organization: Sandig Software Productions GmbH Message-ID: <004601ceb0a9$4fab48b0$ef01da10$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac6wmCtDEfy1E0onTWW8r28/J1DUhwAAmvDQAAK0apA= Content-Language: de X-Authenticated-Sender: info@sandig.com X-Virus-Scanned: Clear (ClamAV 0.97.6/17848/Fri Sep 13 19:23:00 2013) X-Pg-Spam-Score: -0.5 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org I think, you are right; but it might be a potential pitfall, since=20 - the behavior is nondeterministic - the results differ from documented sample codes and PgAdmin-query-results= , especially when using the=20 EXTRACT-function like=20 select EXTRACT(YEAR FROM now()) I didn't expect to retrieve "2013.0" with the 6th call... Actually, my website crashed when processing the results in my xml-framewor= k (that is the reason, why I use getString()) building a new date-string from extracted components. -Tilman -----Urspr=FCngliche Nachricht----- Von: Mikko Tiihonen [mailto:Mikko.Tiihonen@nitorcreations.com]=20 Gesendet: Freitag, 13. September 2013 18:12 An: Tilman Sandig; pgsql-jdbc@postgresql.org Betreff: RE: [JDBC] JDBC 9.2: multiple execution of prepared statement-quer= y delivers different double precision results via getString() The first few times the driver requests the server to return "1 as double p= recision" as a text value (thus using server side toString function). After that the driver evaluates the actual types of the columns and request= s the server to send the value in binary format. Your toString method will then invoke Double(1).toString on your client side. If you modify your code to do System.out.println("Value: " + rs.getDouble(1)); the result should not ch= ange as statements change column values to binary data encoding. I do not think the driver can make guarantees about the format of getString= values, unless the original database field is textual. -Mikko ________________________________________ From: pgsql-jdbc-owner@postgresql.org on = behalf of Tilman Sandig Sent: 13 September 2013 18:44 To: pgsql-jdbc@postgresql.org Subject: [JDBC] JDBC 9.2: multiple execution of prepared statement-query de= livers different double precision results via getString() Hello, there might be a problem in the latest JDBC-driver (9.2 build 1003) when qu= erying double precision-result columns multiple times and retrieving the result with ResultSet.getString(): The first five queries work as expected, further calls append ".0" to the r= esult-string. Here is a sample code: PreparedStatement stmt =3D myConnection.prepareStatement("select cast(1 as = double precision)"); for (int x=3D0;x<12;x++){ ResultSet rs =3D stmt.executeQuery(); while (rs.next()){ System.out.println("Value: " + rs.getString(1)); } } ------- Output: ------- Value: 1 Value: 1 Value: 1 Value: 1 Value: 1 Value: 1.0 Value: 1.0 Value: 1.0 Value: 1.0 Value: 1.0 Value: 1.0 Value: 1.0 The problem does not occur when using JDBC-driver version 9.1; I use Postgr= eSQL Version 9.3.0 (Win64/Vista) Best regards, Tilman Sandig -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make change= s to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc