pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philippe Marschall <pm@netcetera.ch>
To: pgsql-jdbc@postgresql.org
Subject: Re: Confusion about JDBC + TIME WITHOUT TIME ZONE
Date: Mon, 25 Jan 2016 12:27:40 +0100
Message-ID: <56A606AC.6020707@netcetera.ch> (raw)
In-Reply-To: <20160124190035.78da947487fa2559c162cdcf@potentialtech.com>
References: <20160124190035.78da947487fa2559c162cdcf@potentialtech.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

On 25.01.16 01:00, Bill Moran wrote:
>
> I have a table that has a TIME WITHOUT TIME ZONE column.
>
> When I try to insert via JDBC, the time is always adjusted for the
> JVM's time zone. This behavior seems wrong to me. For example:
>
> // Java code:
> preparedStatement.setTime(1, Time.valueOf("00:00:10"));
>
> Then, watching the PostgreSQL logs, I see that the value supplied
> for parameter #1 is '05:00:10'.

I am more leaning towards a bug. Can you try the following on a 
TIMESTAMP WITHOUT TIME ZONE column?

preparedStatement.setTimestamp(1, java.sql.Timestamp.valueOf("2016-01-25 
00:00:10"));

If in that case the time (of the timestamp) stored is actually 
'00:00:10' then I would argue for a bug. The reasoning being:

The java.sql date and time classes (Date, Time and Timestamp) are to be 
interpreted in the JVM default time zone in the case of WITHOUT TIME 
ZONE database types.

For example:
  - For a TIMESTAMP WITHOUT TIME ZONE what in SQL is '2016-01-25 
00:00:10' will be in Java java.sql.Timestamp 2016-01-25 00:00:10 in the 
JVM default time zone
  - For a DATE WITHOUT TIME ZONE what in SQL is '2016-01-25' will be 
java.sql.Date 2016-01-25 00:00:00 in the JVM default time zone (the time 
is added because java.util.Date instance implicitly always have a time)

If the agree on this then it would make sense that
  - For a TIME WITHOUT TIME ZONE what in SQL is '00:00:10' will be 
java.sql.Time 1970-01-01 00:00:10 in the JVM default time zone (the date 
is added because java.util.Date instance implicitly always have a date 
and in this case 1970-01-01 is specified)


Cheers
Philippe



-- 
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 (5+ messages)  latest in thread

Message-ID: <56A606AC.6020707@netcetera.ch>
Permalink:  ../56A606AC.6020707@netcetera.ch/
Also on:    postgresql.org/message-id/56A606AC.6020707@netcetera.ch

 · 

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: pm@netcetera.ch
  Subject: Re: Confusion about JDBC + TIME WITHOUT TIME ZONE
  In-Reply-To: <56A606AC.6020707@netcetera.ch>
  References: <20160124190035.78da947487fa2559c162cdcf@potentialtech.com> <56A606AC.6020707@netcetera.ch>

* 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