Sql 将时间戳打印为数字,而非人类可读
我需要一个针对psql运行的命令行,它可以:Sql 将时间戳打印为数字,而非人类可读,sql,postgresql,Sql,Postgresql,我需要一个针对psql运行的命令行,它可以: psql database -c "select date_trunc('day', start) as date, avg(finish - start) as duration from things group by date order by date;" 但问题是这给了我人类可读的输出,也就是: date | duration ---------------------+-----------------
psql database -c "select date_trunc('day', start) as date, avg(finish - start) as duration from things group by date order by date;"
但问题是这给了我人类可读的输出,也就是:
date | duration
---------------------+-----------------
2010-01-11 00:00:00 | 00:24:13.826822
2010-01-12 00:00:00 | 00:15:42.984878
2010-01-13 00:00:00 | 00:15:37.117834
2010-01-14 00:00:00 | 00:13:27.868552
2010-01-15 00:00:00 | 00:09:16.018057
2010-01-16 00:00:00 | 00:06:39.213929
我想要的是unix时间戳,以秒(或毫秒)为单位,两边都是整数。我已经阅读了文档,但无法理解这一点。我读到您可以用
SELECT date_part('epoch', now())
给出unix时间戳
那么你的情况呢
SELECT date_part('epoch', date_trunc('day', start) as date),
date_part('epoch', avg(finish - start)) as duration
FROM things
GROUP by date
ORDER by date;
博士后见