Re: [Pgjdbc-commit] ERROR: syntax error at or near "$1"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dave Cramer <pg(at)fastcrypt(dot)com>
Cc: William Harris <boggy(at)dineco(dot)com>, List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: [Pgjdbc-commit] ERROR: syntax error at or near "$1"
Date: 2005-11-06 16:49:34
Message-ID: 25249.1131295774@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Dave Cramer <pg(at)fastcrypt(dot)com> writes:
> On 6-Nov-05, at 9:01 AM, William Harris wrote:
>> intervalStmt = con.prepareStatement( "select current_date +
>> (interval ?)" );

The above is not and never has been correct syntax; the fact that it
failed to fail in previous JDBC versions was accidental. The syntax
interval 'literal'
(or in general any type name followed by a string literal) is defined
to work only for literals. The correct way to do this is either
CAST(? AS interval) (SQL standard)
?::interval (Postgres-ism)
See
http://www.postgresql.org/docs/8.0/static/sql-syntax.html#SQL-SYNTAX-CONSTANTS
particularly the note at the end of section 4.1.2.5.

Fraid you're out of luck on the SET example though :-(

regards, tom lane

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2005-11-06 22:34:43 Re: Stable JDBC drivers for 8.1
Previous Message Dave Cramer 2005-11-06 15:43:12 Re: [Pgjdbc-commit] ERROR: syntax error at or near "$1"