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 6279252A1F for ; Thu, 21 Jul 2005 12:14:10 -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 84918-06 for ; Thu, 21 Jul 2005 15:14:01 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.193]) by svr1.postgresql.org (Postfix) with ESMTP id 2D3EA52A01 for ; Thu, 21 Jul 2005 12:14:00 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 71so245043wri for ; Thu, 21 Jul 2005 08:14:00 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=AE1q/7tnVsnztZy6kjBakwRocl0exyMHwYPjDuSnvsiaLaQhmByDfOAv/lHTxnX+teSWO6lTgsnjS6vBPxoimiJdHQyqHBiVneCYpNBzoa16laTvaQwNsxLRcSZWWCYMb5qjEP8vvFOIvMP/29PxluW5X4LF15XyU/njh3pzslw= Received: by 10.54.13.67 with SMTP id 67mr554261wrm; Thu, 21 Jul 2005 08:13:32 -0700 (PDT) Received: by 10.54.86.16 with HTTP; Thu, 21 Jul 2005 08:13:31 -0700 (PDT) Message-ID: <90876a9e05072108132fd1122@mail.gmail.com> Date: Thu, 21 Jul 2005 09:13:31 -0600 From: Christian Cryder Reply-To: Christian Cryder To: Tom Lane Subject: Re: Timestamp Conversion Woes Redux Cc: Oliver Jowett , Kris Jurka , pgsql-jdbc@postgresql.org In-Reply-To: <26535.1121903232@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <90876a9e05071810503606d431@mail.gmail.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> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.076 tagged_above=0 required=5 tests=AWL, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200507/221 X-Sequence-Number: 13369 On 7/20/05, Tom Lane wrote: > I am not sure however that Christian's basic complaint is solvable. > The problem here is very simple: the semantics of SQL TIMESTAMP WITHOUT > TIME ZONE do not match Java's Timestamp, no how, no way. For instance, > '2004-04-04 02:30' is an unconditionally valid timestamp-without-zone, > no matter what anybody's timezone setting is. However, if you try > to interpret it as local time in a US DST-observing zone, you have a > problem. You can never convert this value to timestamptz and back in > a DST-observing zone and not have it change ... which is basically > what Christian is hoping for. But there is *no* timestamptz value > that will decode as 02:30, because that's not a valid value for > timestamptz. Hi guys, Here's what we're looking for in a nutshell. The DB allows a date of '2004-04-04 02:30' in a timestamp column (eg. it may have gotten there via a manual insert from the sql query tool, etc. - However it got there, it's there; that's our starting point). Now, all we want is to be able to read that value via JDBC and then write it back via JDBC, and have the DB end up with same date that we started w/ at the beginning. And right now, it's _extremely_ difficult to accomplish that via the current Postgres driver implementation (we had to jump through hoops and create a custom PGTimestamp class, then wrap the postgres prepared statement, and even then, we still have to programatically turn off DST on the client...it works, but BLECH!) In my mind, that fact that it is so difficult to do such a simple thing should give us pause; it's a fundamental data integrity issue at the root. It's certainly causing us a lot of grief as we try to think about migrating to Postgres; and I'll bet we're not the only ones who see this as an issue. Please don't misunderstand - I realize the JDBC spec is vague, I understand that Sun's Timestamp implementation may have been poorly thought out. But at the end of the day, we have a timestamp value in Postgres - we need to be able to read/write that value without having it changed on us. We are currently using another DB who's JDBC implementation doesn't have this problem. We currently have lots and lots of code using PreparedStatements (so switching to Statements to work around this is not very realistic). The idea of having to turn off DST on our severs in order to make this work is also not a viable option (there are other things running on these boxes, where the time does matter). My point in all this is that regardless of who's to blame here, what we really need is a workable solution. What I was trying to say yesterday is that I think a big part of the problem hinges on the decision to convert the underlying timestamp value to a _string_ representation when passing it across the wire; DST doesn't affect millis, but it does affect the toString() representation. So if we keep the value in millis when flattening and then reconstituting, it seems like we could work around the DST issue (and that right there would be a huge step in the right direction). Again, I'm not familiar enough w/ the internals of Postgres or even the JDBC implementation to tell you "this is how you should do it". I'm just saying that the way the current implementation flattens the timestamp via toString() seems fundamentally problematic to me. At the end of the day, I don't really care how we get there - we just need to be able to read/write timestamp data without having it munged... hopefully that's not too much to ask. Hope that helps, Christian