加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – Postgres where子句比较时间戳

发布时间:2020-12-13 16:35:10 所属栏目:百科 来源:网络整理
导读:我有一个表,其中列是数据类型时间戳 其中包含一天记录的多条记录 我想选择与day相对应的所有行 我该怎么做? 假设你实际上是指时间戳,因为Postgres中没有日期时间 将timestamp列转换为日期,这将删除时间部分: select *from the_tablewhere the_timestamp
我有一个表,其中列是数据类型时间戳

其中包含一天记录的多条记录
我想选择与day相对应的所有行

我该怎么做?

假设你实际上是指时间戳,因为Postgres中没有日期时间

将timestamp列转换为日期,这将删除时间部分:

select *
from the_table
where the_timestamp_column::date = date '2015-07-15';

这将从7月15日返回所有行。

请注意,上面的内容不会使用the_timestamp_column上的索引。如果性能至关重要,则需要在该表达式上创建索引或使用范围条件:

select *
from the_table
where the_timestamp_column >= timestamp '2015-07-15 00:00:00'
  and the_timestamp_column < timestamp '2015-07-16 00:00:00';

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读