Re: Fwd: Query parameter types not recognized

From: rob stone <floriparob(at)gmail(dot)com>
To: Roberto Balarezo <rober710(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Fwd: Query parameter types not recognized
Date: 2017-02-10 20:38:58
Message-ID: 1486759138.9125.1.camel@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Roberto,
On Fri, 2017-02-10 at 10:17 -0500, Roberto Balarezo 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);
> Where defaultDueDate is a java.sql.Date object. However, when I try
> to execute the query, I get this error:
>
> org.postgresql.util.PSQLException: ERROR: COALESCE types timestamp
> without time zone and integer cannot be matched
> Why is it inferring that the type is integer, when I send it as
> Date??
>
>

Prepared statement's set.Date applies the current server timezone to
the value. So, if the database column duedate is of type DATE, it can't
interpret what you are trying to do.

If duedate can be null, then I really don't understand your query.

HTH.

Rob

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2017-02-10 20:58:06 Re: Alter view with psql command line
Previous Message Leonardo M. Ramé 2017-02-10 17:26:18 Re: Alter view with psql command line