Rasmus Resen Amossen <spunk@rhk.dk> writes:
> I want to save some time information in postgresql with php. What is the
> datatype in postgresql coresponding to the mktime()-unixtime function in
> php (creates a time in the format "979333398" eg.)?
You can coerce an integer representing a Unix timestamp to abstime,
and thence to any other datetime datatype you might want to use.
play=> select now()::abstime::integer;
?column?
-----------
979337141
(1 row)
play=> select 979337141::integer::abstime;
?column?
------------------------
2001-01-12 17:05:41-05
(1 row)
The "official" way to get from a datetime type to a Unix timestamp is
date_part('epoch', timevalue):
play=> select date_part('epoch', now());
date_part
-----------
979337212
(1 row)
but I don't know of any easy way to go in the other direction except by
casting to abstime.
regards, tom lane