Re: ibatis with overlaps query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: emilu(at)encs(dot)concordia(dot)ca
Cc: PostgreSQL SQL List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: ibatis with overlaps query
Date: 2009-04-02 15:09:44
Message-ID: 23537.1238684984@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Emi Lu <emilu(at)encs(dot)concordia(dot)ca> writes:
> With ibatis, do overlap checking:

> (1) select (DATE #begin_date#, DATE #end_date#) overlaps
> (DATE '2008-01-01', DATE '2009-01-01')
> . #begin_date# is varchar
> . #end_date# is varchar

> Cause: java.sql.SQLException: ERROR: syntax error at or near "$4"

> However, when I updated the query to
> (2) select (#begin_date#::DATE, #end_date#::DATE) overlaps
> (DATE '2008-01-01', DATE '2009-01-01')

> It works. I am bit confused why (1) does not work, but (2) does?

The syntax DATE 'foo' (or more generally, typename 'foo') works
only for string-literal constants 'foo'. It looks like what your
frontend is actually sending is a parameter symbol, like DATE $1,
which is a syntax error.

There is more about this in the manual, sections 4.1.2.5
and 4.2.8:
http://www.postgresql.org/docs/8.3/static/sql-syntax.html

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Willis 2009-04-02 16:09:56 Re: FUNCTION problem
Previous Message Tom Lane 2009-04-02 15:00:42 Re: SQL to Check whether "AN HOUR PERIOD" is between start and end timestamps