Re: now() vs 'epoch'::timestamp
| От | Steve Crawford |
|---|---|
| Тема | Re: now() vs 'epoch'::timestamp |
| Дата | |
| Msg-id | 551D8402.9010208@pinpointresearch.com обсуждение исходный текст |
| Ответ на | Re: now() vs 'epoch'::timestamp ("David G. Johnston" <david.g.johnston@gmail.com>) |
| Ответы |
Re: now() vs 'epoch'::timestamp
Re: now() vs 'epoch'::timestamp |
| Список | pgsql-general |
On 04/02/2015 10:34 AM, David G. Johnston wrote:
I was actually just looking at the microseconds being off. Now I'm curious again and haven't been able to come up with a plausible explanation. My client and server are in America/Pacific time zone. What I've seen so far:>>>>> "SC" == Steve Crawford <scrawford@pinpointresearch.com> writes:
...
What I haven't determined is why converting back is off by 21600 seconds. What timezone is your server set to - and/or the client requesting the calculation? I haven't looked to see if that is a plausible explanation but if you are +/- 6hrs from UTC...David J.
First, there appears to be some lingering automatic casting:
select 'epoch';
?column?
----------
epoch
select 'epoch' at time zone 'UTC';
timezone
---------------------
1970-01-01 00:00:00
In the Pacific time zone, I should be -07 from UTC but if I strip down James' statement to the following the result shows as -08, not -07:
select 'epoch'::timestamptz;
timestamptz
------------------------
1969-12-31 16:00:00-08
Which we can see is correct:
select '1969-12-31 16:00:00-08'::timestamptz at time zone 'UTC';
timezone
---------------------
1970-01-01 00:00:00
But something gets crossed up when we add a couple calculations:
select (now() - (now() - 'epoch')) ;
?column?
------------------------
1969-12-31 17:00:00-08
Now we are off by an hour:
select (now() - (now() - 'epoch')) at time zone 'UTC';
timezone
---------------------
1970-01-01 01:00:00
select (now()::timestamp without time zone - (now()::timestamp without time zone - 'epoch'));
?column?
---------------------
1970-01-01 00:00:00
That's all I've discovered so far but I have to run to a meeting.
Cheers,
Steve
В списке pgsql-general по дате отправления: