Re: ibatis with overlaps query - Mailing list pgsql-sql

From Tom Lane
Subject Re: ibatis with overlaps query
Date
Msg-id 23537.1238684984@sss.pgh.pa.us
Whole thread Raw
In response to ibatis with overlaps query  (Emi Lu <emilu@encs.concordia.ca>)
List pgsql-sql
Emi Lu <emilu@encs.concordia.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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: SQL to Check whether "AN HOUR PERIOD" is between start and end timestamps
Next
From: Peter Willis
Date:
Subject: Re: FUNCTION problem