pg.ddx.io pgsql-jdbc@postgresql.org mailing list archivehelp / color / mirror / Atom feed
JDBC 7.4 to 8.1 regression problem 2+ messages / 2 participants [nested] [flat]
* JDBC 7.4 to 8.1 regression problem @ 2006-07-14 02:01 Carsten Friedrich <carsten@dtecht.com.au> 0 siblings, 1 reply; 2+ messages in thread From: Carsten Friedrich @ 2006-07-14 02:01 UTC (permalink / raw) To: pgsql-jdbc I just tried to switch from Postgres 7.4 to 8.1. Works fine as far as the server is concerned, as long as I use the JDBC 7.4 driver in my program. If I use the JDBC driver postgresql-8.1-407.jdbc3.jar I have the following problem: I use the following prepared statement: [...] final static String SQL= "SELECT " + [...] " WHERE " + [...] + " AND service_date <= ?" + " and service_date > date ? - interval '365 days'; " [...] This statement works fine with the 7.4 JDBC, but using statement.setDate(5, someDate); // where someDate is a valid java.sql.Date I get the following error message when executing the statement: ERROR: syntax error at or near "$5" The last "?" (before "- interval") is $5. Playing around a bit (leaving out the " date " bit) I noticed that JDBC seems to substitute the "?" by "2005-05-02 +1000". However, I don't know if this is a good or bad thing. Your help in this would be much appreciated. Thanks, Carsten ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: JDBC 7.4 to 8.1 regression problem @ 2006-07-14 16:15 Tom Lane <tgl@sss.pgh.pa.us> parent: Carsten Friedrich <carsten@dtecht.com.au> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2006-07-14 16:15 UTC (permalink / raw) To: Carsten Friedrich <carsten@dtecht.com.au>; +Cc: pgsql-jdbc "Carsten Friedrich" <carsten@dtecht.com.au> writes: > I use the following prepared statement: > final static String SQL= "SELECT " + > [...] > " WHERE " + > [...] > + " AND service_date <= ?" + > " and service_date > date ? - interval '365 days'; " The above is broken code, and always has been: the fact that it failed to malfunction back in 7.4 was purely accidental. You can only use the syntax "typename literal" with a literal constant. Instead of "date ?" use "?::date", or if you want to be fully SQL-spec-compliant write it out as "CAST(? AS date)". Actually, it'd probably be better to use "date_trunc('day', ?)" anyway, since that's what you're trying to achieve with the cast. regards, tom lane ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-07-14 16:15 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2006-07-14 02:01 JDBC 7.4 to 8.1 regression problem Carsten Friedrich <carsten@dtecht.com.au> 2006-07-14 16:15 ` Tom Lane <tgl@sss.pgh.pa.us>
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