在 postgresql (Windows版本9.2.4) 中比较日期时,我遇到了奇怪的情况。
我的表中有一列叫做 update_date
,类型为 timestamp without timezone
。
客户端可以使用只带日期(例如:2013-05-03
)或日期和时间(例如:2013-05-03 12:20:00
)的方式搜索这个字段。
目前所有行的这一列都是时间戳,并且具有相同的日期部分2013-05-03
,但时间部分不同。
当我比较这一列时,得到的结果却不同。例如以下结果:
select * from table where update_date >= '2013-05-03' AND update_date <= '2013-05-03' -> No results
select * from table where update_date >= '2013-05-03' AND update_date < '2013-05-03' -> No results
select * from table where update_date >= '2013-05-03' AND update_date <= '2013-05-04' -> results found
select * from table where update_date >= '2013-05-03' -> results found
我的问题是如何让第一个查询能够获得结果,我的意思是为什么第三个查询有效但第一个查询无效?
NOW() + INTERVAL '1 hour'
。 - Ricardo