【发布时间】:2014-01-18 04:47:22
【问题描述】:
我已经查看了许多与此相关的 SO 问题,但我似乎无法解决任何问题。我不太擅长半复杂的 SQL 查询。
我想获取当前时间与以小时为单位的 unix 时间戳列之间的差异。
我不确定我在这件事上做错了什么。目标是只提取少于 24 小时的行。如果有更好的工作方法或示例,那就太好了。
我从这里Timestamp Difference In Hours for PostgreSQL尝试了几个答案
无论我尝试了多少不同的方法,我都无法让这个查询工作。 wc.posted 是 bigint 存储为 unix timestamp
SELECT w.wal_id, wc.com_id, w.posted AS post_time, wc.posted AS com_time
FROM wall as w LEFT JOIN wall_comments as wc ON w.wal_id=wc.wal_id
WHERE (EXTRACT(EPOCH FROM wc.posted)) > current_timestamp - interval '24 hours'
然后是错误:
ERROR: function pg_catalog.date_part(unknown, bigint) does not exist
LINE 1: ... wall_comments as wc ON w.wal_id=wc.wal_id WHERE (EXTRACT(EP...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function pg_catalog.date_part(unknown, bigint) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 148
这是一个简化的fiddle
【问题讨论】:
标签: sql postgresql timestamp