Skip site navigation (1) Skip section navigation (2)

Re: 8.0.3 parse errors where 7.x was ok

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Nick Johnson <pgsql(at)spatula(dot)net>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: 8.0.3 parse errors where 7.x was ok
Date: 2005-08-10 00:17:11
Message-ID: 42F94787.7030408@opencloud.com (view raw or flat)
Thread:
Lists: 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

In response to

pgsql-jdbc by date

Next:From: a.vokac@sh.cvut.czDate: 2005-08-10 09:33:31
Subject: Re: java.sql.SQLException: Cannot instantiate a SerialArray object
Previous:From: Kris JurkaDate: 2005-08-10 00:05:09
Subject: Re: 8.0.3 parse errors where 7.x was ok

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group