Heim >Datenbank >MySQL-Tutorial >给PostgreSQL添加MySQL的unix_timestamp与from_unixtime函数

给PostgreSQL添加MySQL的unix_timestamp与from_unixtime函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 16:54:441318Durchsuche

MySQL的2个常用函数unix_timestamp()与from_unixtime PostgreSQL并不提供,但通过PostgreSQL强大的扩展性可以轻松的解决问题。话

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;

 

本文来自:

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:Ubuntu 9.04安装Oracle XENächster Artikel:Oracle中被锁定的解决办法