pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Simon Mitchell <simon@jseb.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: PreparedStatement error for date parameter with overlaps
Date: Tue, 31 May 2011 13:12:12 +1000
Message-ID: <BANLkTim756hJon=1wyLeCuyH4bth3fcNiQ@mail.gmail.com> (raw)
In-Reply-To: <14646.1306806733@sss.pgh.pa.us>
References: <BANLkTikCY4ax50aOqNy2BdoYEoLSdc1Sew@mail.gmail.com>
	<14646.1306806733@sss.pgh.pa.us>

This is a very minor issue, the problem only occurs with the prepared
statement, a query string without prepared works fine. I was just following
it up as it was a problem posted on an Australian forum, the original issue
has been resolved.

http://forums.whirlpool.net.au/forum-replies.cfm?t=1708081&p=-1&#bottom


Anyway, so the sql I am using is just based on the overlaps example from the
postgresql doc
http://www.postgresql.org/docs/9.0/static/functions-datetime.html

The strange thing is the doing a toString() before executeQuery() prints out
the sql as per the postgres example, I can cut and past it into psql and it
runs fine.

Both   ?::date and  CAST(? AS date) fail in java.

   ?::date works fine in psql, but  CAST(? AS date) fails in psql.

SELECT (date CAST('2001-02-16' AS date), date ('2001-12-21')) OVERLAPS (date
('2001-10-30'), date ('2002-10-30'));
ERROR:  syntax error at or near "CAST"

I have achieved my main aim, to put a work around on the net, so it should
turn up in a search. As I could not find one while looking at the opening
post on this forumn

I think i had an issue with setDate as well, but may have been just my poor
java.

Thanks guys for your replies.

On Tue, May 31, 2011 at 11:52, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Simon Mitchell <simon@jseb.com> writes:
> > // some bad code
> >     sqlText = "SELECT (date ?, date ?) OVERLAPS (date ?, date ?);";
>
> That's not going to work, because the syntax
>        date 'something'
> only works for literal constants, and a ? marker is not a literal constant.
> You could try
>        ?::date
> or
>        CAST(? AS date)
> if you prefer to avoid Postgres-specific syntax.  Even better, don't use
> setString --- that's really only meant for parameters that are of string
> datatypes.
>
>                        regards, tom lane
>



-- 
simon

view thread (11+ messages)  latest in thread

Message-ID: <BANLkTim756hJon=1wyLeCuyH4bth3fcNiQ@mail.gmail.com>
Permalink:  ../BANLkTim756hJon=1wyLeCuyH4bth3fcNiQ@mail.gmail.com/
Also on:    postgresql.org/message-id/BANLkTim756hJon=1wyLeCuyH4bth3fcNiQ@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: simon@jseb.com
  Subject: Re: PreparedStatement error for date parameter with overlaps
  In-Reply-To: <BANLkTim756hJon=1wyLeCuyH4bth3fcNiQ@mail.gmail.com>
  References: <BANLkTikCY4ax50aOqNy2BdoYEoLSdc1Sew@mail.gmail.com> <14646.1306806733@sss.pgh.pa.us> <BANLkTim756hJon=1wyLeCuyH4bth3fcNiQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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