1、age函数
用于获取两个时间相差
audit=# select age('2020-01-01 17:53:02' :: TIMESTAMP , '2020-01-01 17:46:20' :: TIMESTAMP);
age
----------
00:06:42
(1 row)
-- 等价于
select '2020-01-01 17:53:02' :: TIMESTAMP -'2020-01-01 17:46:20' :: TIMESTAMP;
2、时间戳
可能我们需要获取多少秒;即上面的“ 6 min 42 sec;应该是 402 s
audit=# select EXTRACT(epoch FROM '2020-01-01 17:53:02' :: TIMESTAMP ) - EXTRACT(epoch FROM '2020-01-01 17:46:20' :: TIMESTAMP );
?column?
----------
402
(1 row)