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 1fXc26-0005rg-4p for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jun 2018 00:40:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fXc24-0004Kp-CE for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jun 2018 00:40:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXc24-0004Ki-6S for pgsql-bugs@lists.postgresql.org; Tue, 26 Jun 2018 00:40:32 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXc21-0001cA-TS for pgsql-bugs@lists.postgresql.org; Tue, 26 Jun 2018 00:40:31 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 687E921EDE; Mon, 25 Jun 2018 20:40:28 -0400 (EDT) Received: from web4 ([10.202.2.214]) by compute1.internal (MEProxy); Mon, 25 Jun 2018 20:40:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=/xxrL+ 49pxT0W47D/aX1Qcy/C97MIW5TVUqp5PhFwbo=; b=tyxs4tDW0e7oqc1rw/rc41 L5L/7+9lKi5F1rPWDZLpGXHQZjfFJltglS8TyjobV8UU0gmfRjueuMJgef6oUatU c0lRioT/9djdebdN4CbcMqtHUeXcyJsGhL1hBioNtnbNWdSHwrjf+xO+wz8qnEi0 cQBMzzyJ2pW7lG3UgB357Jzz651SDkYBmARavC9KIA1Ee8u8cczV7e6VRUD9xb6l 2Ztu5wlPDlWtbSn3/iZeqKxIHNKQTD0IVq84F2LnL+z77z2Tv2vcUewa3Eo9oEUz 0DnWultGkdAhHD0/9Zi+pnFkAztCRbeDQmOl0YQM2n7HvcI35pmNx4EIllpXbmuA == X-ME-Proxy: X-ME-Sender: Received: by mailuser.nyi.internal (Postfix, from userid 99) id 0FD39BA4CF; Mon, 25 Jun 2018 20:40:28 -0400 (EDT) Message-Id: <1529973627.48469.1420256816.1159290F@webmail.messagingengine.com> From: Gary Bernhardt To: "David G. Johnston" Cc: pgsql-bugs@lists.postgresql.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: multipart/alternative; boundary="_----------=_1529973627484692" X-Mailer: MessagingEngine.com Webmail Interface - ajax-0d8ea36c References: <1529970473.36096.1420218376.3C13DF11@webmail.messagingengine.com> <1529972735.44579.1420252720.11BFA61D@webmail.messagingengine.com> In-Reply-To: Subject: Re: Converting to UTC multiple times converts back to local time zone Date: Mon, 25 Jun 2018 17:40:27 -0700 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --_----------=_1529973627484692 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" The last example in my original email showed this happening where one "AT TIME ZONE" is in a subquery and the other is in the outer query. Imagine that scaled up to a large, complex query; and imagine that it eventually grows a redundant "AT TIME ZONE" because someone modifying an outer query doesn't realize that a deep subquery is already doing "AT TIME ZONE". Now the time is suddenly in the wrong zone, but the programmer explicitly asked for the timestamp to be in UTC. We can certainly call that a mistake in the query (it's redundant if nothing else). But I would never expect the value to switch back to local time when I add "AT TIME ZONE 'utc'". On Mon, Jun 25, 2018, at 5:32 PM, David G. Johnston wrote: > On Mon, Jun 25, 2018 at 5:25 PM, Gary Bernhardt > wrote:>> On Mon, Jun 25, 2018, at 5:20 PM, David G. Johnston wrote: >> > I'll agree that this was a surprising finding for me too, but in >> > the overall scheme of how PostgreSQL works, and other features it >> > provides (e.g., TimeZone GUC and to_char()) it fits. >> >> Thanks, David. I find this behavior quite off-putting, but I'm happy >> to take your word that it's intended and consistent with other >> features.> > Care to be more specific? You didn't really provide an example that > gives others insight into why you would use "AT TIME ZONE" twice in > the same expression.> > David J. > --_----------=_1529973627484692 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset="utf-8"
The last example in my original email showed this happening where one "AT TIME ZONE" is in a subquery and the other is in the outer query. Imagine that scaled up to a large, complex query; and imagine that it eventually grows a redundant "AT TIME ZONE" because someone modifying an outer query doesn't realize that a deep subquery is already doing "AT TIME ZONE". Now the time is suddenly in the wrong zone, but the programmer explicitly asked for the timestamp to be in UTC.

We can certainly call that a mistake in the query (it's redundant if nothing else). But I would never expect the value to switch back to local time when I add "AT TIME ZONE 'utc'".

On Mon, Jun 25, 2018, at 5:32 PM, David G. Johnston wrote:
On Mon, Jun 25, 2018 at 5:25 PM, Gary Bernhardt <gary.bernhardt@gmail.com> wrote:
On Mon, Jun 25, 2018, at 5:20 PM, David G. Johnston wrote:
> I'll agree that this was a surprising finding for me too, but in the overall scheme of how PostgreSQL works, and other features it provides (e.g., TimeZone GUC and to_char()) it fits.

Thanks, David. I find this behavior quite off-putting, but I'm happy to take your word that it's intended and consistent with other features.

Care to be more specific?  You didn't really provide an example that gives others insight into why you would use "AT TIME ZONE" twice in the same expression.

David J.


--_----------=_1529973627484692--