Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwFSd-0003Yv-IR for pgsql-docs@arkaria.postgresql.org; Sat, 01 Sep 2018 23:37:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fwFSb-0000nR-9V for pgsql-docs@arkaria.postgresql.org; Sat, 01 Sep 2018 23:37:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwFSb-0000mv-0N for pgsql-docs@lists.postgresql.org; Sat, 01 Sep 2018 23:37:45 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fwFSU-0005D0-44 for pgsql-docs@postgresql.org; Sat, 01 Sep 2018 23:37:43 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1fwFSS-0007q7-40; Sat, 01 Sep 2018 19:37:36 -0400 Date: Sat, 1 Sep 2018 19:37:36 -0400 From: Bruce Momjian To: Tom Lane Cc: PostgreSQL-documentation Subject: Re: AT TIME ZONE correction Message-ID: <20180901233736.GA25700@momjian.us> References: <20180901225557.GA22406@momjian.us> <24277.1535844643@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <24277.1535844643@sss.pgh.pa.us> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Sep 1, 2018 at 07:30:43PM -0400, Tom Lane wrote: > Bruce Momjian writes: > > Looking over the AT TIME ZONE docs, I think they are subtly confusing. > > The order of conversion specific in the first example should _start_ > > with the assumption of local time zone for the time stamp, not something > > that happens after AT TIME ZONE is applied. The ordering in current > > docs makes the second example confusing too. > > > The attached patch fixes this. > > I think it's you that are confused. The text as written is correct, > or at least arguably so; your revision is definitely incorrect. > > SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'MST'; > > The way I'd describe this is that we start with a timestamp, > which has no particular timezone. The AT TIME ZONE says "Assume that > this zoneless timestamp is in MST, and convert it to timestamp with > time zone (which will be in UTC, internally)". Then after that, the > UTC timestamptz value is converted to PST8PDT for display purposes, > but that's done by timestamptz_out not AT TIME ZONE. > > If we were going from PST to MST as your patch describes it, the > output would be one hour later not one hour earlier than the input. > > SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'MST'; > > Here we've got a time value that was initially given in EST (-05), > but was converted to UTC by timestampz_in. Then the AT TIME ZONE > says "Please convert this UTC value to MST, and emit it as a zoneless > timestamp" (which will not be subject to any further conversion when > it's displayed). > > The existing text is indeed a bit deficient, because it fails to > draw a clear boundary between what the AT TIME ZONE operator is > doing and what is being done by the timestamp(tz) I/O functions. > But you're not making it better. Yes, I am still researching and realize my diff is wrong. Let me keep working and I will repost. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription +