pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
8.0.3 parse errors where 7.x was ok
3+ messages / 3 participants
[nested] [flat]

* 8.0.3 parse errors where 7.x was ok
@ 2005-08-09 23:53  Nick Johnson <pgsql@spatula.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Nick Johnson @ 2005-08-09 23:53 UTC (permalink / raw)
  To: pgsql-jdbc

I'm getting a new exception when upgrading to Postgres 8.0.3 with the JDBC 
drivers it builds:

java.sql.SQLException: ERROR: parse error at or near "$1"

This is happening with the following bit of code:

     105         try {
     106             s = c.prepareStatement("select now() - interval ?");
     107             s.setString(1, "7 days");
     108             ResultSet r = s.executeQuery();

The driver was built from postgresql-jdbc-8.0-311.src using the FreeBSD 
port on FreeBSD 5.4 with Java 1.4.2-p7.

Using the older jar built for postgresql-7.3.4 works fine.

Is this syntax no longer supported?

    Nick

-- 
"The aptly-named morons.org is an obscenity-laced screed..."
 	-- Robert P. Lockwood, Catholic League director of research
Nick Johnson, version 2.1                             http://web.morons.org/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: 8.0.3 parse errors where 7.x was ok
@ 2005-08-10 00:05  Kris Jurka <books@ejurka.com>
  parent: Nick Johnson <pgsql@spatula.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Kris Jurka @ 2005-08-10 00:05 UTC (permalink / raw)
  To: Nick Johnson <pgsql@spatula.net>; +Cc: pgsql-jdbc



On Tue, 9 Aug 2005, Nick Johnson wrote:

> I'm getting a new exception when upgrading to Postgres 8.0.3 with the JDBC 
> drivers it builds:
> 
> java.sql.SQLException: ERROR: parse error at or near "$1"
> 
>      105         try {
>      106             s = c.prepareStatement("select now() - interval ?");
>      107             s.setString(1, "7 days");
>      108             ResultSet r = s.executeQuery();
> 
> Is this syntax no longer supported?
> 

Yes.  The 8.0 driver always uses server side prepared statements when in
the past the statements were usually put together on the driver side.  
The using a type prefix (like "interval") is not supported in server
prepared statements, so this is a server limitation that is now exposed
with the new driver.  I believe "?::interval" or "cast(? as interval)"
should work.

Kris Jurka



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: 8.0.3 parse errors where 7.x was ok
@ 2005-08-10 00:17  Oliver Jowett <oliver@opencloud.com>
  parent: Nick Johnson <pgsql@spatula.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Oliver Jowett @ 2005-08-10 00:17 UTC (permalink / raw)
  To: Nick Johnson <pgsql@spatula.net>; +Cc: pgsql-jdbc

Nick Johnson wrote:
> I'm getting a new exception when upgrading to Postgres 8.0.3 with the
> JDBC drivers it builds:
> 
> java.sql.SQLException: ERROR: parse error at or near "$1"
> 
> This is happening with the following bit of code:
> 
>     105         try {
>     106             s = c.prepareStatement("select now() - interval ?");
>     107             s.setString(1, "7 days");
>     108             ResultSet r = s.executeQuery();

Because the driver now pushes parameter handling to the backend, you can
only put ? placeholders where there is a PARAM terminal in the backend's
SQL grammar. Previously the driver just substituted parameter values
directly into the query, so you could get away with all sorts of things.

Perhaps this will work instead:

  s = c.prepareStatement("select now() - ?");
  s.setObject(new org.postgresql.util.PGInterval("7 days"));

-O



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-08-10 00:17 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-08-09 23:53 8.0.3 parse errors where 7.x was ok Nick Johnson <pgsql@spatula.net>
2005-08-10 00:05 ` Kris Jurka <books@ejurka.com>
2005-08-10 00:17 ` Oliver Jowett <oliver@opencloud.com>

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