pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Johnston <polobo@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()
Date: Fri, 13 Sep 2013 14:21:09 -0700 (PDT)
Message-ID: <1379107269525-5770793.post@n5.nabble.com> (raw)
In-Reply-To: <004601ceb0a9$4fab48b0$ef01da10$@com>
References: <004201ceb098$2d6d79f0$88486dd0$@com>
	<56318f6405134b7faed245cea972e928@AMSPR07MB018.eurprd07.prod.outlook.com>
	<004601ceb0a9$4fab48b0$ef01da10$@com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Tilman Sandig wrote
> I think, you are right; but it might be a potential pitfall, since 
> 
> - the behavior is nondeterministic
> - the results differ from documented sample codes and
> PgAdmin-query-results, especially when using the 
> EXTRACT-function like 
> 
>     select EXTRACT(YEAR FROM now())
> 
> I didn't expect to retrieve "2013.0" with the 6th call...

The action itself is not really supported so it isn't surprising that there
are oddities.  If the "getXXX" doesn't match the actual result type the
behavior is undetermined.

The PgAdmin equivalent is not a fair comparison though it does make sense to
try it.  The "correct" way is to accept the double at the client side and
let the client, not the driver, convert it for display.

I'm not sure the driver can or even should save the user from themselves in
this kind of situation; any such parenting is going to result in either a
"strict/non-strict" mode setup or complaints because of "type mis-match"
errors.


> If you modify your code to do
>   System.out.println("Value: " + rs.getDouble(1)); the result should not
> change as statements change column values to binary
> data encoding.

the "correct" modification is:

SELECT extract(year FROM now())::integer  --or "::varchar; or
::integer::varchar" to be perfectly safe

The extract function is multi-purpose and so has to have an output that is
flexible.  If you know what field you are extracting you should cast the
double result to that which most closely matches the field in question.

David J.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/JDBC-9-2-multiple-execution-of-prepared-statement-query-deli...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (4+ messages)

Message-ID: <1379107269525-5770793.post@n5.nabble.com>
Permalink:  ../1379107269525-5770793.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1379107269525-5770793.post@n5.nabble.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: polobo@yahoo.com
  Subject: Re: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()
  In-Reply-To: <1379107269525-5770793.post@n5.nabble.com>
  References: <004201ceb098$2d6d79f0$88486dd0$@com> <56318f6405134b7faed245cea972e928@AMSPR07MB018.eurprd07.prod.outlook.com> <004601ceb0a9$4fab48b0$ef01da10$@com> <1379107269525-5770793.post@n5.nabble.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