From: Dave Cramer <pg@fastcrypt.com>
To: Oliver Jowett <oliver@opencloud.com>
Cc: 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: Fri, 22 Jul 2005 08:09:39 -0400
Message-ID: <27F3B08D-C3A4-4ED2-B360-2412A835B6F9@fastcrypt.com> (raw)
In-Reply-To: <42E0529E.7060807@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>
<26982.1121906793@sss.pgh.pa.us>
<42E03BB8.7090101@opencloud.com>
<24343.1121993659@sss.pgh.pa.us>
<42E0529E.7060807@opencloud.com>
I've hacked my local version to track the servers time zone and use
the calendar appropriate to the servers time zone.
This would allow the user to set the driver, and server time zone to
UTC as suggested below.
One issue I have is that the server returns some time zones in
lowercase.
ie EST -> est
EST5EDT -> est5edt
java doesn't understand these. Why is the server changing them to
lower case?
Dave
On 21-Jul-05, at 9:57 PM, Oliver Jowett wrote:
> Tom Lane wrote:
>
>> Oliver Jowett <oliver@opencloud.com> writes:
>>
>>
>>> i.e. currently the core of the problem is this behaviour:
>>>
>>
>>
>>
>>> template1=# select '2005-01-01 15:00:00
>>> +1000'::timestamptz::timestamp;
>>> timestamp
>>> ---------------------
>>> 2005-01-01 18:00:00
>>> (1 row)
>>>
>>
>>
>> Well, the current interpretation is that timestamptz -> timestamp
>> produces a timestamp representing what the timestamptz equates to in
>> your current TimeZone. I do not foresee changing that behavior
>> when/if
>> we add explicit TZ info to timestamptz --- it would break just about
>> every existing app that uses this conversion.
>>
>
> I can understand backwards compatibility issues, but it doesn't
> make my
> example above any more obvious :/
>
>
>> The more I think about this, the more I think that the correct
>> solution
>> must include having the driver set TimeZone = UTC (and complain if
>> the
>> app tries to change it). Then you can specify parameter types as
>> either
>> timestamp or timestamptz, it doesn't really matter, because
>> conversions
>> between them on the server side will be no-ops. When you convert
>> a Java
>> Timestamp to send to the server, you always convert it using a UTC
>> Calendar object. I'm not sure if the setTimestamp variants with a
>> Calendar are special in this regime; arguably you should ignore the
>> supplied Calendar, on the principle that you know what the
>> Timestamp is
>> supposed to mean.
>>
>
> I don't think this works, as we need to support the Calendar variants.
> Specifically, given this code:
>
> // 2005-01-01 05:00:00 UTC
> Timestamp now = new Timestamp(1104555600*1000L);
> Calender localCalendar = Calendar.getInstance(new Locale
> ("en","NZ"));
> ps.setTimestamp(1, now, localCalendar);
>
> I would expect it to end up setting a timestamptz value of '2005-01-01
> 05:00:00 +0000' (or an equivalent instant as represented in some other
> timezone), or a timestamp of '2005-01-01 18:00:00' (as NZ is +1300 in
> January). I think this is the correct interpretation given what the
> javadoc says about setTimestamp() using the provided calendar to
> construct an appropriate SQL TIMESTAMP value. The JDBC spec may be
> lousy
> but I don't think they added the Calendar variants with the
> intention of
> having drivers completely ignore that parameter..
>
> I don't see how we can handle this even with TimeZone = UTC:
>
> If we pass '2005-01-01 05:00:00 +0000' as timestamptz then it is wrong
> if implicitly cast to timestamp; if we pass it as timestamp then it's
> just the wrong value immediately.
>
> If we pass '2005-01-01 18:00:00 +1300' as timestamptz then it still
> doesn't cast to the correct timestamp value; if we pass it as
> timestamp
> then it is the right timestamp value, but is wrong if it is then
> cast to
> timestamptz.
>
> Passing '2005-01-01 18:00:00 +1300' as an unknown type will work for
> both timestamp and timestamptz as there's no implicit casting
> involved,
> but we run the risk of getting the type wrong or not being able to
> determine a type at all. Conversely, this is effectively what the V2
> protocol path is doing anyway.
>
> If we can't change the casting behaviour, and TimeZone hackery doesn't
> work, and we want to support both timestamp and timestamptz via the
> standard interfaces, then it seems like passing the parameters as
> UNKNOWN is the only practical option :(
>
> -O
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>
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: pg@fastcrypt.com, 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: <27F3B08D-C3A4-4ED2-B360-2412A835B6F9@fastcrypt.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> <26982.1121906793@sss.pgh.pa.us> <42E03BB8.7090101@opencloud.com> <24343.1121993659@sss.pgh.pa.us> <42E0529E.7060807@opencloud.com> <27F3B08D-C3A4-4ED2-B360-2412A835B6F9@fastcrypt.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