From: Oliver Jowett <oliver@opencloud.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Kris Jurka <books@ejurka.com>
Cc: Christian Cryder <c.s.cryder@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Timestamp Conversion Woes Redux
Date: Thu, 21 Jul 2005 12:20:51 +1200
Message-ID: <42DEEA63.6090507@opencloud.com> (raw)
In-Reply-To: <26535.1121903232@sss.pgh.pa.us>
References: <90876a9e05071810503606d431@mail.gmail.com>
<16335.1121714809@sss.pgh.pa.us>
<10C90079-DD0A-43D7-9389-7486803F0AB1@fastcrypt.com>
<42DC37AC.5030704@opencloud.com>
<C36F2D5F-093E-489C-8D6F-A67B746EA6C8@fastcrypt.com>
<42DCF0C9.4030501@opencloud.com>
<23396.1121781259@sss.pgh.pa.us>
<392278AB-987F-40CF-B59D-DDF53B9A4ACF@fastcrypt.com>
<Pine.BSO.4.56.0507191100110.68@leary.csoft.net>
<90876a9e050719093261c52c64@mail.gmail.com>
<Pine.BSO.4.56.0507200109220.31980@leary.csoft.net>
<42DDF238.8090601@opencloud.com>
<Pine.BSO.4.56.0507201125190.5339@leary.csoft.net>
<42DEDB5A.9000803@opencloud.com>
<26535.1121903232@sss.pgh.pa.us>
Tom Lane wrote:
> I think any solution that tries to work 100% for both flavors of SQL
> timestamp is simply doomed to failure --- unless there are more
> semantics to Java's Timestamp type than I've gathered from this
> discussion. The impression I have is that Timestamp is supposed to
> represent absolute time instants (ie, there's no additional "what time
> zone is this in" info needed to determine the exact equivalent GMT
> time), which would make it equivalent to timestamptz.
That's correct. A Timestamp is essentially a wrapper around
milliseconds-since-epoch. It has no timezone information beyond some
badly thought out, not settable, "timezone offset" that always reflects
the default timezone, and some getHour/getMinute/etc accessors (again
using the JVM's default timezone only); these have been deprecated since
JDK 1.1 in favor of using Calendar objects.
Timestamps are then interpreted by feeding them through a Calendar for
locale- and timezone-specific formatting -- e.g. you can ask a Calendar
for the hour of a particular Timestamp, and it'll give you the
appropriate hour based on the timezone the Calendar is for.
> timestamp-without-zone is a fundamentally different critter, because it
> does not assume that there is any such thing as absolute GMT-equivalent
> time.
In other words, a timestamp-without-zone is just a
year-month-day-hour-minute-second tuple, which could correspond to many
instants in time depending on timezone and daylight savings changes?
The thing is that there are two distinct variants of setTimestamp():
(1) setTimestamp(index, timestamp)
(2) setTimestamp(index, timestamp, calendar)
(2) obviously maps to timestamp-with-zone. The question is what do we do
with (1) -- is the intention to set:
(a) a particular instant in time identified by 'timestamp', or
(b) the particular year-month-day-hour-minute-second described by
('timestamp' interpreted in the default timezone of the JVM)
1(a) is timestamp-with-zone again
1(b) is timestamp-without-zone
The JDBC spec doesn't help us here.
If we go with 1(a) then we have problems when casting to a
timestamp-without-zone value when the JVM and server timezones do not match.
If we go with 1(b) then we have problems when casting to a
timestamp-with-zone value when the JVM and server timezones do not
match, or when daylight savings means there are two possible instants in
a particular timezone identified by the timestamp-without-zone.
...
I'd like to go with 1(b):
I don't like 1(a) because it gives you no way of getting a
timestamp-without-zone into the database without having a timezone
available on the Java side that exactly matches the server timezone. As
found elsewhere in the thread, the two zic databases are already out of
sync, so I don't like the chances of that..
With 1(b), if you hit the casting problem, you have a workaround: use
the setTimestamp() method that takes a Calendar, and explicitly pass the
default JVM calendar. That completely avoids the need for the
problematic cast.
-O
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: oliver@opencloud.com, tgl@sss.pgh.pa.us, books@ejurka.com, c.s.cryder@gmail.com
Subject: Re: Timestamp Conversion Woes Redux
In-Reply-To: <42DEEA63.6090507@opencloud.com>
References: <90876a9e05071810503606d431@mail.gmail.com> <16335.1121714809@sss.pgh.pa.us> <10C90079-DD0A-43D7-9389-7486803F0AB1@fastcrypt.com> <42DC37AC.5030704@opencloud.com> <C36F2D5F-093E-489C-8D6F-A67B746EA6C8@fastcrypt.com> <42DCF0C9.4030501@opencloud.com> <23396.1121781259@sss.pgh.pa.us> <392278AB-987F-40CF-B59D-DDF53B9A4ACF@fastcrypt.com> <Pine.BSO.4.56.0507191100110.68@leary.csoft.net> <90876a9e050719093261c52c64@mail.gmail.com> <Pine.BSO.4.56.0507200109220.31980@leary.csoft.net> <42DDF238.8090601@opencloud.com> <Pine.BSO.4.56.0507201125190.5339@leary.csoft.net> <42DEDB5A.9000803@opencloud.com> <26535.1121903232@sss.pgh.pa.us> <42DEEA63.6090507@opencloud.com>
* 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