From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
Cc: | o(dot)bousche(at)krohne(dot)com, pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #6424: Possible error in time to seconds conversion |
Date: | 2012-02-01 16:40:08 |
Message-ID: | 16756.1328114408@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Merlin Moncure <mmoncure(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | download_mn | 2012-02-01 17:05:48 | BUG #6427: Installation stack builder error |
Previous Message | Merlin Moncure | 2012-02-01 16:24:33 | Re: BUG #6424: Possible error in time to seconds conversion |