Re: PreparedStatement error upon trying to set a '?' after interval keyword

From: Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: javadesigner <javadesigner(at)yahoo(dot)com>, List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: PreparedStatement error upon trying to set a '?' after interval keyword
Date: 2014-08-12 12:22:14
Message-ID: CAH7T-aoPABiZyCqSy6cVDxKRH6KGrWfi-NAVMUSxFSLPNQ=s-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Yes Craig's way is better. I was only thinking of handling the string
interpolation itself rather than generating the interval itself.

I'd probably use the ::interval cast syntax though, so something like:
checkin_time > (CURRENT_DATE - (? * '1 day'::interval))

Regards,
-- Sehrope Sarkuni
Founder & CEO | JackDB, Inc. | http://www.jackdb.com/

On Tue, Aug 12, 2014 at 12:02 AM, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:
> On 08/12/2014 04:34 AM, Sehrope Sarkuni wrote:
>> AND checkin_time > (CURRENT_DATE - (? || ' days')::interval)
>
>
> It's generally preferable to write
>
> (? * INTERVAL '1' DAY)
>
> instead.
>
> --
> Craig Ringer http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2014-08-12 13:02:08 Re: PreparedStatement error upon trying to set a '?' after interval keyword
Previous Message Craig Ringer 2014-08-12 04:02:56 Re: PreparedStatement error upon trying to set a '?' after interval keyword