【发布时间】:2015-07-15 11:44:07
【问题描述】:
我有一个表,其中列的数据类型为 timestamp
其中包含一天的多条记录 我想选择对应天的所有行
我该怎么做?
【问题讨论】:
标签: postgresql
我有一个表,其中列的数据类型为 timestamp
其中包含一天的多条记录 我想选择对应天的所有行
我该怎么做?
【问题讨论】:
标签: postgresql
假设您实际上是指 timestamp,因为 Postgres 中没有 datetime
将时间戳列转换为日期,这将删除时间部分:
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';
【讨论】:
where the_timestamp_column >= '2015-07-15' and the_timestamp_column < '2015-07-16'