SQL OVERLAPS运算符问题,如何摆脱它 [英] SQL OVERLAPS operator problem, how to get rid of it
问题描述
我希望该日期段从 2011-01-28到 2011-02-01的重叠期从 2011-02-01到 2011-02-01(在同一天),但事实并非如此!
I expect that date period from '2011-01-28' to '2011-02-01' OVERLAPS period from '2011-02-01' to '2011-02-01' (that's the same day here), but it does not!
PostgreSQL期望精确终点的匹配不匹配...如何摆脱这种情况?我希望将上述情况视为重叠。
PostgreSQL expecting the match of exact ending point is NOT a match...how to get rid of this? I would like to have it treat the above scenario as overlap.
SELECT (DATE '2011-01-28', DATE '2011-02-01') OVERLAPS
(DATE '2011-02-01', DATE '2011-02-01');
返回false,而我希望它返回true。
returns false, while I expect it to return true.
推荐答案
一种解决方法,即对您的情况可能有意义,也可能没有意义-将日期转换为时间戳:
A kind of a workaround, i.e. it may or may not make sense for your case - convert the dates to timestamps:
SELECT (TIMESTAMP '2011-01-28 00:00:00', TIMESTAMP '2011-02-01 23:59:59') OVERLAPS (TIMESTAMP '2011-02-01 00:00:00', TIMESTAMP '2011-02-01 23:59:59');
从技术上讲,仅转换第一个期间的端点就足够了,至少对于您已经完成的示例而言
Technically it's sufficient to convert only the endpoint of the first period, at least for the example you've given.
这篇关于SQL OVERLAPS运算符问题,如何摆脱它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!