Re: Timestamp Shifts when calling to_timestamp(extract (epoch from timestamp))

Поиск
Список
Период
Сортировка
От Scott Ribe
Тема Re: Timestamp Shifts when calling to_timestamp(extract (epoch from timestamp))
Дата
Msg-id 4FD9A31F-C7E3-4A27-B431-5B284BD3EF28@elevated-dev.com
обсуждение исходный текст
Ответ на Timestamp Shifts when calling to_timestamp(extract (epoch from timestamp))  (Robert Burgholzer <rburghol@vt.edu>)
Ответы Re: Timestamp Shifts when calling to_timestamp(extract (epoch from timestamp))  (Robert Burgholzer <rburghol@vt.edu>)
Список pgsql-admin
On May 12, 2015, at 11:33 AM, Robert Burgholzer <rburghol@vt.edu> wrote:
>
> In postgresql 9.3 I am running into what I consider counterintuitive behavior when I convert something to a Unix
epoch,then back from a timestamp without timezone.  Calling "to_timestamp(extract (epoch from timestamp))" returns a
timethat is shifted the distance from local time to GMT (Example 1).  I have a workaround for when I do data imports,
inthat if I create columns as "timestamp with timezone" and do the same conversion, they convert to and fro seemelessly
(example2).   
>
> Thoughts on this?  To me, it would seem intuitive that if you did not specify a timezone, the db would choose it's
ownlocal timestamp as the timezone. 

From the documentation on date/time data types:

"Note: The SQL standard requires that writing just timestamp be equivalent to timestamp without time zone, and
PostgreSQLhonors that behavior. timestamptz is accepted as an abbreviation for timestamp with time zone; this is a
PostgreSQLextension.” 

Then from date/time functions:

"epoch
For timestamp with time zone values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative); for date
andtimestampvalues, the number of seconds since 1970-01-01 00:00:00 local time; for interval values, the total number
ofseconds in the interval” 

So you get number of seconds from UTC your local time in the call to epoch, essentially ignoring the specified ‘EST’
timezone. Then on converting back, it’s treated as seconds from UTC. 

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice







В списке pgsql-admin по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Timestamp Shifts when calling to_timestamp(extract (epoch from timestamp))
Следующее
От: Robert Burgholzer
Дата:
Сообщение: Re: Timestamp Shifts when calling to_timestamp(extract (epoch from timestamp))