Home > Database > Mysql Tutorial > 给PostgreSQL添加MySQL的unix_timestamp与from_unixtime函数

给PostgreSQL添加MySQL的unix_timestamp与from_unixtime函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:54:44
Original
1319 people have browsed it

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

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template