【发布时间】:2015-07-26 14:49:25
【问题描述】:
如何在 SQL OVERLAPS 中包含开始和结束日期?
喜欢 =。怎么做?
因为在我看来,OVERLAPS 只检查两者之间的范围,但是例如:
2001 年 1 月 1 日 - 2001 年 1 月 5 日的日期已经在数据库中,
我选择 1 月 5 日作为新系列的第一个日期,它对我说这很好。相反,我想要OVERLAPS = true,因为 2001 年 1 月 5 日已经在数据库中,我不能从 1 月 5 日开始新的范围,而是从 1 月 6 日开始。
如何在 OVERLAPS 中包含极端日期?
【问题讨论】:
-
来自documentation:
Each time period is considered to represent the half-open interval start <= time < end, unless start and end are equal in which case it represents that single time instant. This means for instance that two time periods with only an endpoint in common do not overlap. -
@Marth,有解决方案吗?你能帮帮我吗?
-
我可能会使用@gordonlinoff 的解决方案。另一种方法(也不包括“添加 1 天”~hack)是构造封闭的
dateranges,然后使用&&运算符。但是我没有这些解决方案的任何基准,但如果你有,请分享! -
@Marth,我不明白你的
daterange's解决方案。你能解释得更好吗? -
刚刚发布它作为答案。请询问是否仍有不清楚的地方。
标签: sql postgresql date overlap