X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3490E52956 for ; Wed, 20 Jul 2005 21:21:02 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97961-09 for ; Thu, 21 Jul 2005 00:20:53 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id E21FA52940 for ; Wed, 20 Jul 2005 21:20:52 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1DvOnz-0003fk-Lb; Thu, 21 Jul 2005 12:20:51 +1200 Message-ID: <42DEEA63.6090507@opencloud.com> Date: Thu, 21 Jul 2005 12:20:51 +1200 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Kris Jurka , Christian Cryder , pgsql-jdbc@postgresql.org Subject: Re: Timestamp Conversion Woes Redux References: <90876a9e05071810503606d431@mail.gmail.com> <16335.1121714809@sss.pgh.pa.us> <10C90079-DD0A-43D7-9389-7486803F0AB1@fastcrypt.com> <42DC37AC.5030704@opencloud.com> <42DCF0C9.4030501@opencloud.com> <23396.1121781259@sss.pgh.pa.us> <392278AB-987F-40CF-B59D-DDF53B9A4ACF@fastcrypt.com> <90876a9e050719093261c52c64@mail.gmail.com> <42DDF238.8090601@opencloud.com> <42DEDB5A.9000803@opencloud.com> <26535.1121903232@sss.pgh.pa.us> In-Reply-To: <26535.1121903232@sss.pgh.pa.us> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/211 X-Sequence-Number: 13359 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