pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedConfusion about JDBC + TIME WITHOUT TIME ZONE
5+ messages / 4 participants
[nested] [flat]
* Confusion about JDBC + TIME WITHOUT TIME ZONE
@ 2016-01-25 00:00 Bill Moran <wmoran@potentialtech.com>
0 siblings, 3 replies; 5+ messages in thread
From: Bill Moran @ 2016-01-25 00:00 UTC (permalink / raw)
To: pgsql-jdbc
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'.
Since my TZ is US Eastern, it appears as if JDBC is adjusting for
the timezone. I don't understand why it would do so, as the whole
point is that TIME WITHOUT TIME ZONE doesn't care, record, or
do anything else with or about the TZ.
To me, this feels like a bug. I'm certainly open to someone explaining
to me why this is the correct behavior, so I can stop understanding
it wrong (should that be the case) but that would have to include an
understanding of how to get the desired behavior. That behavior is
that the time passed in is stored without caring about its time zone.
--
Bill Moran
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Confusion about JDBC + TIME WITHOUT TIME ZONE
@ 2016-01-25 00:32 Dave Cramer <pg@fastcrypt.com>
parent: Bill Moran <wmoran@potentialtech.com>
2 siblings, 1 reply; 5+ messages in thread
From: Dave Cramer @ 2016-01-25 00:32 UTC (permalink / raw)
To: Bill Moran <wmoran@potentialtech.com>; +Cc: pgsql-jdbc
Well .... timezones in JDBC are certainly a thorny issue. First off there
is no JDBC allowance for any date/time object with out time zones. We have
to support time and date with time zones properly. That being said JDBC
spec says that if you do not provide a timezone then the timezone of the
JVM will be used. So the solution to your problem is to provide a 0
timezone.
See
http://stackoverflow.com/questions/18447995/postgresql-9-2-jdbc-driver-uses-client-time-zone
for others discussing this.
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On 24 January 2016 at 19:00, Bill Moran <wmoran@potentialtech.com> 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'.
>
> Since my TZ is US Eastern, it appears as if JDBC is adjusting for
> the timezone. I don't understand why it would do so, as the whole
> point is that TIME WITHOUT TIME ZONE doesn't care, record, or
> do anything else with or about the TZ.
>
> To me, this feels like a bug. I'm certainly open to someone explaining
> to me why this is the correct behavior, so I can stop understanding
> it wrong (should that be the case) but that would have to include an
> understanding of how to get the desired behavior. That behavior is
> that the time passed in is stored without caring about its time zone.
>
> --
> Bill Moran
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Confusion about JDBC + TIME WITHOUT TIME ZONE
@ 2016-01-25 01:51 Bill Moran <wmoran@potentialtech.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 5+ messages in thread
From: Bill Moran @ 2016-01-25 01:51 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
On Sun, 24 Jan 2016 19:32:33 -0500
Dave Cramer <pg@fastcrypt.com> wrote:
> Well .... timezones in JDBC are certainly a thorny issue. First off there
> is no JDBC allowance for any date/time object with out time zones.
That sentence explained it. Thanks.
--
Bill Moran
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Confusion about JDBC + TIME WITHOUT TIME ZONE
@ 2016-01-25 11:27 Philippe Marschall <pm@netcetera.ch>
parent: Bill Moran <wmoran@potentialtech.com>
2 siblings, 0 replies; 5+ messages in thread
From: Philippe Marschall @ 2016-01-25 11:27 UTC (permalink / raw)
To: pgsql-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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Confusion about JDBC + TIME WITHOUT TIME ZONE
@ 2016-01-25 11:42 Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
parent: Bill Moran <wmoran@potentialtech.com>
2 siblings, 0 replies; 5+ messages in thread
From: Vladimir Sitnikov @ 2016-01-25 11:42 UTC (permalink / raw)
To: Bill Moran <wmoran@potentialtech.com>; +Cc: pgsql-jdbc
Bill>When I try to insert via JDBC, the time is always adjusted for the
Bill>JVM's time zone. This behavior seems wrong to me
Bill>// Java code:
Bill>preparedStatement.setTime(1, Time.valueOf("00:00:10"));
A no-brain answer is: you do not provide the time zone, thus the
driver uses "current time zone".
What's wrong with that?
Note: java.sql.Time does not store "dd, hh, mm" in a separate fields.
It always converts to "milliseconds since...", thus it is doomed to
run into timezones.
Have you tried org.postgresql.jdbc.PgPreparedStatement#setTime(int,
java.sql.Time, java.util.Calendar)?
Alternative solution would be to use java.time.LocalTime -- it could
be easier to reason about.
More specific example would help to tell if the behavior is expected or not.
Can you share that?
Vladimir
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2016-01-25 11:42 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-01-25 00:00 Confusion about JDBC + TIME WITHOUT TIME ZONE Bill Moran <wmoran@potentialtech.com>
2016-01-25 00:32 ` Dave Cramer <pg@fastcrypt.com>
2016-01-25 01:51 ` Bill Moran <wmoran@potentialtech.com>
2016-01-25 11:27 ` Philippe Marschall <pm@netcetera.ch>
2016-01-25 11:42 ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
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