Re: How to typecast an integer into a timestamp?

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: How to typecast an integer into a timestamp?
Дата
Msg-id 201201270817.37774.adrian.klaver@gmail.com
обсуждение исходный текст
Ответ на How to typecast an integer into a timestamp?  (bboett@free.fr)
Ответы Re: How to typecast an integer into a timestamp?  (Bruno Boettcher <bboett@bboett.adlp.org>)
Re: How to typecast an integer into a timestamp?  (Bruno Boettcher <bboett@bboett.adlp.org>)
Список pgsql-general
On Friday, January 27, 2012 7:44:55 am bboett@free.fr wrote:
> Hello!
>
> again quite a stupid problem i regularly run into....
> and that i still haven't solved yet...
>
> again i used a type timestamp to keep a track of modification time, and
> again it gets stupid and confusing.....
>
> first of all the errors are labeled as timestamp without timezone, i only
> specified timestamp....
>
> the data was created as a timestamp with php-mktime, but when sending to
> the database postgres complains that its an int, and when i try to
> typecast it, (with the ::timestamp appendix to the value), that its not
> possible to convert an int to a timestamp (without timezone) .....
>
> so as usual i would discard the timezone datatype and alter the table to
> use integer instead, but this time i am wondering, since this datatype is
> present, there's surely a way to use it properly? but how?
>
> please enlighten me!

Did some digging. php-mktime returns the Unix epoch (seconds since January 1
1970 00:00:00 GMT)

Postgres has a function(to_timestamp) that will convert that to a timestamp:

http://www.postgresql.org/docs/9.0/interactive/functions-formatting.html

to_timestamp(double precision)    timestamp with time zone    convert Unix
epoch to time stamp    to_timestamp(1284352323)

So something like the below in your query should work:

to_timestamp(int_returned_from_php)


>
> ciao
> Bruno

--
Adrian Klaver
adrian.klaver@gmail.com

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

Предыдущее
От: Andy Colson
Дата:
Сообщение: Re: How to typecast an integer into a timestamp?
Следующее
От: Giuseppe Sacco
Дата:
Сообщение: error "permission denied for relation" on postgresql 9.0.6 during CREATE TABLE