我有一个表 (funny_quotes),它有一个名为 quote_date 的列,它以 unix 纪元时间(秒)存储数据
我想运行一个查询,仅从该表 (funny_quotes) 返回最近 3 天的数据。
我在 postgres 中本地创建了一个表,但无法将日期存储为纪元时间,它们只能存储为时间戳值
select * from funny_quotes where quote_date > (now() - interval '3 days')
最佳答案
您应该将等式右边修改为纪元,以便能够进行比较:
select * from funny_quotes where quote_date > extract(epoch from (now() - interval '3 days'))
或者反过来:将 quote_date
转换为时间戳:
select * from funny_quotes where to_timestamp(quote_date) > now() - interval '3 days'
您可以阅读更多相关信息 in the docs
关于postgresql - postgres 表纪元时间戳的最后 7 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57230491/