postgresql - Postgres 选择当前小时数据

标签 postgresql

我有一个带有表“token”的 postgres 数据库,它有“token_id”及其生成时间

token_id | generated_time
196618   | 2016-10-15 01:02:48.963
196619   | 2016-10-15 01:02:50.569
196620   | 2016-10-15 01:03:12.931
196621   | 2016-10-15 02:03:17.037
196622   | 2016-10-15 02:22:55.782
196623   | 2016-10-15 02:24:57.477
196624   | 2016-10-15 03:23:00

我想做的是从表中选择当前小时数据,例如,如果当前日期时间是 2016-10-15 01:30:15 那么我想选择 之间的所有数据>2016-10-15 01:00:00 和 2016-10-15 02:00:00

感谢您的任何建议。

最佳答案

我会说 date_trunc('hour')在这里可能会有帮助,例如

select token_id, generated_time
from token
where generated_time between date_trunc('hour', current_timestamp) and date_trunc('hour', current_timestamp + interval '1 hour')

关于postgresql - Postgres 选择当前小时数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40063102/

相关文章:

python - GeoDjango:PostgreSQL 未运行迁移,对象没有属性“geo_db_type”

sql - 在 postgresql 表中查找最大条目,sql

sql - 返回右表中包含多条记录的一行

Postgresql earthdistance - 带半径的earth_box

php - 如何使用 PHP 将日语文本插入到 Postgres 表中?

postgresql - 如何在 pgAdmin III 中为多个表生成 CREATE 脚本?

postgresql - 如何根据 PostgreSQL part2 中的枚举列汇总所有行?

ruby-on-rails - Rails 建模比赛,postgres 数组的好时机?

c++ - 实现自定义 Postgres 索引作为扩展

performance - PostgreSQL 查询计划是否取决于表行数?