MySQL的2个常用函数unix_timestamp()与from_unixtime PostgreSQL并不提供,但通过PostgreSQL强大的扩展性可以轻松的解决问题。
话说远在天边,尽在眼前,文档看仔细,问题迎仞解。PostgreSQL 题供extract与date_part取epoch即可
即
unix_timestamp() = round(date_part(’epoch’,now()))
from_unixtime(int) = to_timestamp(int)
添加函数unix_timestamp()
CREATE FUNCTION unix_timestamp() RETURNS integer AS $$
SELECT (date_part(’epoch’,now()))::integer;
$$ LANGUAGE SQL IMMUTABLE;
添加函数from_unixtime()
CREATE FUNCTION from_unixtime(int) RETURNS timestamp AS $$
SELECT to_timestamp($1)::timestamp;
$$ LANGUAGE SQL IMMUTABLE;