我有一个表,其中列的数据类型timestamp
其中包含一天的多条记录
我想选择与日期对应的所有行
我该怎么做?
Assuming you actually mean timestamp
because there is no datetime
in Postgres
将时间戳列转换为日期,这将删除时间部分:
select *
from the_table
where the_timestamp_column::date = date '2015-07-15';
这将返回 7 月 15 日以来的所有行。
请注意,上面将not使用索引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';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)