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
S
E
L
E
C
T
(
d
a
t
e
p
a
r
t
(
’
e
p
o
c
h
’
,
n
o
w
(
)
)
)
:
:
i
n
t
e
g
e
r
;
SELECT (date_part(’epoch’,now()))::integer;
SELECT(datepart(’epoch’,now()))::integer; LANGUAGE SQL IMMUTABLE;
添加函数from_unixtime()
CREATE FUNCTION from_unixtime(int) RETURNS timestamp AS KaTeX parse error: Can't use function '$' in math mode at position 22: …T to_timestamp($̲1)::timestamp; LANGUAGE SQL IMMUTABLE;