Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YsEN6-0007DL-4J for pgsql-admin@arkaria.postgresql.org; Tue, 12 May 2015 17:53:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YsEN5-0006Kk-IP for pgsql-admin@arkaria.postgresql.org; Tue, 12 May 2015 17:53:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YsEN4-0006J5-Ai for pgsql-admin@postgresql.org; Tue, 12 May 2015 17:53:34 +0000 Received: from mailout.easymail.ca ([64.68.201.169]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YsEN0-000098-QD for pgsql-admin@postgresql.org; Tue, 12 May 2015 17:53:33 +0000 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id EC747E16E; Tue, 12 May 2015 13:53:26 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at mailout.easymail.ca X-Spam-Flag: NO X-Spam-Score: -3.901 X-Spam-Level: X-Spam-Status: No, score=-3.901 required=5 tests=[ALL_TRUSTED=-1.8, AWL=-0.194, BAYES_00=-2.599, DNS_FROM_AHBL_RHSBL=0.692] Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (easymail-mailout.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F22HlGKi7pev; Tue, 12 May 2015 13:53:26 -0400 (EDT) Received: from [192.168.2.16] (unknown [8.39.228.5]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout.easymail.ca (Postfix) with ESMTPSA id 7AA59E169; Tue, 12 May 2015 13:53:26 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Subject: Re: Timestamp Shifts when calling to_timestamp(extract (epoch from timestamp)) From: Scott Ribe In-Reply-To: Date: Tue, 12 May 2015 11:53:23 -0600 Cc: "pgsql-admin@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <4FD9A31F-C7E3-4A27-B431-5B284BD3EF28@elevated-dev.com> References: To: Robert Burgholzer X-Mailer: Apple Mail (2.2098) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org On May 12, 2015, at 11:33 AM, Robert Burgholzer wrote: >=20 > In postgresql 9.3 I am running into what I consider counterintuitive beha= vior when I convert something to a Unix epoch, then back from a timestamp w= ithout timezone. Calling "to_timestamp(extract (epoch from timestamp))" re= turns a time that is shifted the distance from local time to GMT (Example 1= ). I have a workaround for when I do data imports, in that if I create col= umns as "timestamp with timezone" and do the same conversion, they convert = to and fro seemelessly (example 2).=20=20 >=20 > Thoughts on this? To me, it would seem intuitive that if you did not spe= cify a timezone, the db would choose it's own local timestamp as the timezo= ne. =46rom the documentation on date/time data types: "Note: The SQL standard requires that writing just timestamp be equivalent = to timestamp without time zone, and PostgreSQL honors that behavior. timest= amptz is accepted as an abbreviation for timestamp with time zone; this is = a PostgreSQL extension.=E2=80=9D Then from date/time functions: "epoch For timestamp with time zone values, the number of seconds since 1970-01-01= 00:00:00 UTC (can be negative); for date andtimestamp values, the number o= f seconds since 1970-01-01 00:00:00 local time; for interval values, the to= tal number of seconds in the interval=E2=80=9D So you get number of seconds from UTC your local time in the call to epoch,= essentially ignoring the specified =E2=80=98EST=E2=80=99 time zone. Then o= n converting back, it=E2=80=99s treated as seconds from UTC. --=20 Scott Ribe scott_ribe@elevated-dev.com http://www.elevated-dev.com/ https://www.linkedin.com/in/scottribe/ (303) 722-0567 voice --=20 Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin