Re: [GENERAL] Fwd: Query parameter types not recognized - Mailing list pgsql-general

From Adrian Klaver
Subject Re: [GENERAL] Fwd: Query parameter types not recognized
Date
Msg-id 25d262e9-313c-f794-1a52-bba8bd8433ef@aklaver.com
Whole thread Raw
In response to Re: [GENERAL] Fwd: Query parameter types not recognized  (Arjen Nienhuis <a.g.nienhuis@gmail.com>)
List pgsql-general
On 02/10/2017 01:33 PM, Arjen Nienhuis wrote:
>
>
> On Feb 10, 2017 8:11 PM, "Roberto Balarezo" <rober710@gmail.com
> <mailto:rober710@gmail.com>> wrote:
>
>     Hi, I would like to know why this is happening and some advice if
>     there is a way to solve this problem:
>
>     I have a query like this:
>
>     |select COALESCE(duedate, ? + 1) from invoices order by duedate desc
>     limit 10; |
>
>     where ? is a query parameter. I’m using JDBC to connect to the
>     database, and sending parameters like this:
>
>     |query.setDate(1, defaultDueDate); |
>
> If you want to add to a date you cannot just add 1. You need an
> interval: coalesce(duedate, ? + interval '1 day')
>
> See:
>
> https://www.postgresql.org/docs/9.6/static/functions-datetime.html

Actually that is not the case, from above docs:

"Also, the + and * operators come in commutative pairs (for example both
date + integer and integer + date); we show only one of each such pair."

and:

test=# select current_date;
     date
------------
  2017-02-10
(1 row)

test=# select current_date + 1;
   ?column?
------------
  2017-02-11
(1 row)




--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Roberto Balarezo
Date:
Subject: Re: [GENERAL] Fwd: Query parameter types not recognized
Next
From: Roberto Balarezo
Date:
Subject: Re: [GENERAL] Fwd: Query parameter types not recognized