postgres时间戳转换工具

postgres时间戳转换工具, 记录一下方便使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- from unixtimestamp, convert to timestamp
create function from_us(ts bigint)
returns timestamp as $$
begin
return abstime(ts::int);
end;
$$ language plpgsql;


-- from unixtimestamp, convert to timestamp
create function from_us(ts integer)
returns timestamp as $$
begin
return abstime(ts);
end;
$$ language plpgsql;


-- to unix timestamp, from a string, convert to int4
create function to_uts(date varchar)
returns int4 as $$
begin
return extract(epoch from to_timestamp(date, 'yyyy-MM-dd'));
end;
$$ language plpgsql
文章目录
,