Re: Fwd: Query parameter types not recognized

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

Hello Roberto,
On Fri, 2017-02-10 at 16:43 -0500, Roberto Balarezo wrote:
> Hi Rob,
>
> Thanks for your answer. The query is just an example I made to
> illustrate the problem. In the database I'm working with, duedate is
> a timestamp without timezone column, which can contain null values.
> The parameter is supposed to be of type DATE. From Java, I'm sending
> a Date object (which contains no timezone information, so the driver
> should not have problem with this). So if the field duedate has a
> null value, a default date with one day added is returned.
> I read that the driver has problems with timestamp columns, because
> it cannot tell the server if it is a timestamp with or without
> timezone, but dates should not present this problem. The server
> should know it is of DATE type.
>
> PS: I have changed the code of the application to send the value
> (defaultDate + 1 day) calculated in the application and sent this as
> a parameter to make it work, but there are many queries like this and
> I would like to know why it happens and if I can make it work
> changing the query and not the code.
>

If the column duedate is defined as a timestamp, then setDate is not
the answer. java.sql.Date is just a "date".
java.util.Date is a timestamp object but from 1.8 onwards it is pretty
well deprecated in favour of the Calendar methods. You can of course
have 0:0:0 as the time part.
All I can suggest is a spot of reading the docs about Calendar and
formatting your (defaultDate + 1) as a timestamp.

HTH,
Rob

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tanner Kerr 2017-02-11 00:34:53 BDR problem rejoining node
Previous Message François Beaulieu 2017-02-10 22:54:56 Potential bug with pg_notify