postgresql - postgres 表纪元时间戳的最后 7 天

标签 postgresql

我有一个表 (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/

相关文章:

java - Spring JDBC + Postgres SQL + Java 8 - 从/到 LocalDate 的转换

postgresql - 如何将plpgsql中的查询错误保存到表中?

postgresql - postgresql容器的数据保存在哪里,还有容器的位置在哪里?

php - 对 SELECT NOW() 的单个查询然后格式化它并更新值

sql - 什么是正确的查询?

sql - 删除 SQL 结果中的 SUM 列

swift - 转换 ASCII 十进制

postgresql - 如何使用 LIKE 查询在 PostgreSQL 中找到文字百分号 (%)?

postgresql - 更新时 Ecto.StaleEntryError

sql - 在 postgres 中查询表的授权