我查看了许多与此相关的SO问题,但似乎没有任何一种方法能够奏效。我不太擅长半复杂的SQL查询。
我想要获取当前时间和一个以Unix时间戳表示的列之间的差值(以小时为单位)。
我不确定我做对了什么或做错了什么。目标是只检索小于24小时的行。如果有更好的方法或示例可以使用,那将是很好的。
我尝试了这里Timestamp Difference In Hours for PostgreSQL中的几个答案。
无论我如何尝试,都无法使这个查询起作用。wc.posted是一个存储为Unix时间戳的bigint。
那么错误信息为:
这里有一个简化版的 fiddle。
我想要获取当前时间和一个以Unix时间戳表示的列之间的差值(以小时为单位)。
我不确定我做对了什么或做错了什么。目标是只检索小于24小时的行。如果有更好的方法或示例可以使用,那将是很好的。
我尝试了这里Timestamp Difference In Hours for PostgreSQL中的几个答案。
无论我如何尝试,都无法使这个查询起作用。wc.posted是一个存储为Unix时间戳的bigint。
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:
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。