Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 4BD789FB32A for ; Thu, 5 Oct 2006 17:06:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 78504-09 for ; Thu, 5 Oct 2006 17:06:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from talk.nabble.com (www.nabble.com [72.21.53.35]) by postgresql.org (Postfix) with ESMTP id E852F9FB1C6 for ; Thu, 5 Oct 2006 17:06:00 -0300 (ADT) Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1GVZTk-0008Ap-4I for pgsql-sql@postgresql.org; Thu, 05 Oct 2006 13:06:00 -0700 Message-ID: <6667446.post@talk.nabble.com> Date: Thu, 5 Oct 2006 13:06:00 -0700 (PDT) From: chrisj To: pgsql-sql@postgresql.org Subject: Re: Assigning a timestamp without timezone to a timestamp In-Reply-To: <20061005183128.GD8826@phlogiston.dyndns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: chrisj.wood@sympatico.ca References: <6613652.post@talk.nabble.com> <20061003135623.GB3191@phlogiston.dyndns.org> <6621346.post@talk.nabble.com> <20061003145134.GA3399@phlogiston.dyndns.org> <8C5B026B51B6854CBE88121DBF097A864DE848@ehost010-33.exch010.intermedia.net> <20061005183128.GD8826@phlogiston.dyndns.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.272 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/70 X-Sequence-Number: 26459 Hi Andrew, If only all time zones were fixed offset timezones life would be so much simpler. Unfortunately the main area of deployment of my app will beToronto which is on EDT which is not a fixed offsets timezone. I hope/assume your solution works with "EDT" instead of "-3", I will test it soon. Andrew Sullivan wrote: > > On Wed, Oct 04, 2006 at 11:04:56AM -0700, Hector Villarreal wrote: >> Hi >> I am also interested in this type of setup. However, in the example >> below >> I am a little confused as to why the table entry is 1, -3 > > The 1 is an artificial key (it's the criterion in the WHERE clause). > The -03 is the time zone offset. The most reliable way to handle > time zone offsets, I find, is to use the numeric offset from UTC. > That's the way PostgreSQL shows them in some cases, too. On my > system, for instance, I get this for SELECT now() (at the moment): > > now > ------------------------------- > 2006-10-05 14:21:51.507419-04 > (1 row) > >> SELECT a.timestamp::timestamptz from (SELECT '2006-10-03 >> 09:00'||"timezone" as timestamp from storetz where id = 1) as a; >> timestamp > > So what this does is > > SELECT > > the column named "timestamp" from relation "a" > cast to timestamp with time zone (the :: is a shorthand for > cast in Postgres) > > FROM > > a relation called "a" > constituted as (this is that "as a" on the end) > > SELECT > the literal string '2006-10-03 09:00' > concatenated to (that's what "||" means) > the column "timezone" > [and call that whole thing "timestamp" > FROM > a relation called "storetz" > WHERE > the storetz row has an id of 1. > > So, what you get is a timestamp with a time zone that is built up > from the combination of a timestamp without time zone and some time > zone data that you have. > > What's _really_ cool in Postgres about the time handling is that you > can also change your time zone, and find that the data nicely > represents your new time zone too. You can see this in my original > example: I was using GMT, but inserted a timestamp in -03. When I > selected the answer, though, I got one back in GMT (==UTC). So > that's why you see this: > >> >> testing=# SELECT a.timestamp::timestamptz from (SELECT '2006-10-03 >> 09:00'||"timezone" as timestamp from storetz where id = 1) as a; >> timestamp >> ------------------------ >> 2006-10-03 12:00:00+00 >> (1 row) > > 2006-10-03 09:00:00-03 == 2006-10-03 12:00:00+00 > > Hope that helps, > A > > -- > Andrew Sullivan | ajs@crankycanuck.ca > The fact that technology doesn't work is no bar to success in the > marketplace. > --Philip Greenspun > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > > -- View this message in context: http://www.nabble.com/Assigning-a-timestamp-without-timezone-to-a-timestamp-with-timezone-tf2373845.html#a6667446 Sent from the PostgreSQL - sql mailing list archive at Nabble.com.