Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kvO4h-0000wX-FD for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Jan 2021 17:18:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kvO49-0004vn-Jx for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Jan 2021 17:18:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kvO49-0004vf-Dm for pgsql-bugs@lists.postgresql.org; Fri, 01 Jan 2021 17:18:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kvO47-0003yk-A1 for pgsql-bugs@lists.postgresql.org; Fri, 01 Jan 2021 17:18:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 101HICwI2527206; Fri, 1 Jan 2021 12:18:12 -0500 From: Tom Lane To: Dana Burd cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16797: EXTRACT(EPOCH FROM timestamp) is not using local timezone In-reply-to: References: <16797-f264b0b980b53b8b@postgresql.org> <2396654.1609354902@sss.pgh.pa.us> <2405485.1609363754@sss.pgh.pa.us> Comments: In-reply-to Dana Burd message dated "Thu, 31 Dec 2020 14:27:31 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2527204.1609521492.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 01 Jan 2021 12:18:12 -0500 Message-ID: <2527205.1609521492@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Dana Burd writes: > Can I suggest a slight alteration in the (9.9.1. EXTRACT) epoch > documentation to help others: > "For timestamp with time zone values, the number of seconds since > 1970-01-01 00:00:00 UTC (can be negative); for date and timestamp values= , > the number of seconds since 1970-01-01 00:00:00 UTC (date and timestamp > will assume UTC regardless of local timezone in order to maintain > immutability - one may explicitly cast timestamp to timestamptz to assum= e a > different timezone); for interval values, the total number of seconds in > the interval" Hmm, that's not really right either; it appears to imply that the epoch calculation is timezone-aware, which it specifically isn't for date and timestamp cases. An example (presuming US DST rules): regression=3D# select extract(epoch from date '2020-03-09') - extract(epoc= h from date '2020-03-08'); ?column? = ---------- 86400 (1 row) regression=3D# select extract(epoch from timestamp '2020-03-09') - extract= (epoch from timestamp '2020-03-08'); ?column? = ---------- 86400 (1 row) regression=3D# select extract(epoch from timestamptz '2020-03-09') - extra= ct(epoch from timestamptz '2020-03-08'); ?column? = ---------- 82800 (1 row) The last case knows that there was a DST transition in between, the first two don't take that into account. (You could argue that this is more a property of the types' input conversion routines than of extract() itself, but I think the point is valid anyway.) Perhaps a better phrasing is "for date and timestamp values, the nominal number of seconds since 1970-01-01 00:00:00, without regard to timezone or daylight-savings rules". regards, tom lane