pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christopher BROWN <brown@reflexe.fr>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: PreparedStatement.setDate() behavior with OVERLAPS
Date: Tue, 11 Aug 2015 10:01:28 -0400
Message-ID: <9152.1439301688@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHL_zcMr0u+xdhGM5vJvt6zTfOGdh9Cp1Pd+gEERe6XC2khMvA@mail.gmail.com>
References: <CAHL_zcMr0u+xdhGM5vJvt6zTfOGdh9Cp1Pd+gEERe6XC2khMvA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Christopher BROWN <brown@reflexe.fr> writes:
> When I use the following query as a PreparedStatement with the 9.4.1201
> JDBC driver, using a 9.4.4 database, the SQL is rejected:

> SELECT id, ctime, mtime, is_archived, ref_store, ref_supplier,
> period_begins, period_ends, received_by, received_on, received_qty,
> disposed_qty FROM store_delivery WHERE (period_begins, period_ends +
> interval '1 day') OVERLAPS (?, ? + interval '1 day') AND ref_store = ?
> ORDER BY period_begins, ctime

> Specifically, with "invalid input syntax for type interval".  I'm setting
> the first two parameters to java.sql.Date values, using "setDate" method of
> PreparedStatement (the third parameter is an integer, ex 4251).

FWIW, the same would happen if you just did this in psql:

regression=# select '2015-09-06' + interval '1 day';
ERROR:  invalid input syntax for type interval: "2015-09-06"

The server uses various heuristics to determine the type of an unmarked
literal or parameter symbol, and the first one that applies in this
context is "assume it's the same type as the other input to the binary
operator".  So the only way to make this work is to explicitly tell the
server that the parameter is of type date or timestamp.  You could do that
within the SQL string with "::date", which as you mentioned fixes the
problem.  However, I'd have expected that if you set the parameter with
setDate or equivalent, the JDBC driver would pass along the information
that the value is of type date.  I'm not sure what the restrictions are on
making that happen, but that's the area to sniff around in.  Maybe you're
actually using setString, for example?  Or using protocol version 2, which
doesn't have a provision for passing parameter type data?

			regards, tom lane


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (13+ messages)  latest in thread

Message-ID: <9152.1439301688@sss.pgh.pa.us>
Permalink:  ../9152.1439301688@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9152.1439301688@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, brown@reflexe.fr
  Subject: Re: PreparedStatement.setDate() behavior with OVERLAPS
  In-Reply-To: <9152.1439301688@sss.pgh.pa.us>
  References: <CAHL_zcMr0u+xdhGM5vJvt6zTfOGdh9Cp1Pd+gEERe6XC2khMvA@mail.gmail.com> <9152.1439301688@sss.pgh.pa.us>

* 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