Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id AF6E61288B2E for ; Wed, 1 Feb 2012 12:40:35 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RsdEZ-0007Zc-8M for pgsql-bugs@postgresql.org; Wed, 01 Feb 2012 16:40:35 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q11Ge88X016757; Wed, 1 Feb 2012 11:40:08 -0500 (EST) To: Merlin Moncure cc: o.bousche@krohne.com, pgsql-bugs@postgresql.org Subject: Re: BUG #6424: Possible error in time to seconds conversion In-reply-to: References: <15144.1328112025@sss.pgh.pa.us> Comments: In-reply-to Merlin Moncure message dated "Wed, 01 Feb 2012 10:24:33 -0600" Date: Wed, 01 Feb 2012 11:40:08 -0500 Message-ID: <16756.1328114408@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/10 X-Sequence-Number: 32353 Merlin Moncure writes: > TBH, I think the behavior of the example given is 100% correct *if a > timezone isn't specified', which the OP didn't. It's only weird if > you do this: ... > which really boils down to this: > postgres=# select extract(epoch from '1970-01-01 0:0:0 GMT'::timestamp); > date_part > ----------- > 21600 > (1 row) > which is what seems busted to me. Well, the timezone specification in that input is ignored, so you'll get that result (or actually, a result that depends on your timezone setting --- for me, that prints 18000) regardless of whether you write a timezone or which one you write. The underlying issue here is that at some time in the forgotten past, we decided that these two operations should produce the same result: regression=# select extract(epoch from '1970-01-01 0:0:0'::timestamp); date_part ----------- 18000 (1 row) regression=# select extract(epoch from '1970-01-01 0:0:0'::timestamptz); date_part ----------- 18000 (1 row) I believe that the second behavior is entirely correct, because since I'm in EST5EDT zone, "local midnight" for me is in fact 5 hours behind GMT. However, it seems debatable whether the first behavior is correct, since timestamp without timezone's operations really ought not depend on the timezone setting. If you do want a timezone-aware epoch value, you could always cast the timestamp value to timestamptz; but if you don't, it's damn hard to get one that's not, using the currently available operations. I think you have to do what the OP suggests here, namely subtract two timestamp values (forming an interval) and then use extract(epoch from interval). Ugh. regards, tom lane