From: Tom Lane <tgl@sss.pgh.pa.us>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: o.bousche@krohne.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6424: Possible error in time to seconds conversion
Date: Wed, 01 Feb 2012 11:40:08 -0500
Message-ID: <16756.1328114408@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHyXU0yb4B_t3Ojr0pohWqzStkGroPs4pgjEwGJ062rS7VxeMQ@mail.gmail.com>
References: <E1Rsaxi-0008Aq-V3@wrigleys.postgresql.org>
<15144.1328112025@sss.pgh.pa.us>
<CAHyXU0yb4B_t3Ojr0pohWqzStkGroPs4pgjEwGJ062rS7VxeMQ@mail.gmail.com>
Merlin Moncure <mmoncure@gmail.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, mmoncure@gmail.com, o.bousche@krohne.com
Subject: Re: BUG #6424: Possible error in time to seconds conversion
In-Reply-To: <16756.1328114408@sss.pgh.pa.us>
References: <E1Rsaxi-0008Aq-V3@wrigleys.postgresql.org> <15144.1328112025@sss.pgh.pa.us> <CAHyXU0yb4B_t3Ojr0pohWqzStkGroPs4pgjEwGJ062rS7VxeMQ@mail.gmail.com> <16756.1328114408@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox