我有一个表,其中一列的数据类型是timestamp
其中包含了同一天的多条记录,我想选择所有与那一天相符的行
我应该如何操作?
我有一个表,其中一列的数据类型是timestamp
其中包含了同一天的多条记录,我想选择所有与那一天相符的行
我应该如何操作?
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'
- moveson