1

postgresql中的“BETWEEN”和“OVERLAPS”有什么区别?

你能举个例子吗?重叠语法 (NULL, x) OVERLAPS (?, ?) 中是否可能有 NULL 值。

4

1 回答 1

1

使用 a、b、c 整数,a between b and c用简单的英语表示它的含义:

b <= a and a <= c

对于 a、b、c、d 整数,[a,b] overlaps [c,d]意味着它们具有共同的元素:

not(b <= c) and not(d <= a)

(处理重叠时的思维界限。)

在处理范围类型时,null 值意味着无穷大。


例子:

denis=# select int4range(-1, 0), int4range(0, 1);
 int4range | int4range 
-----------+-----------
 [-1,0)    | [0,1)
(1 row)

denis=# select int4range(null, 0), int4range(0, null);
 int4range | int4range 
-----------+-----------
 (,0)      | [0,)
(1 row)

denis=# select int4range(null, 0) && int4range(0, null) as test;
 test 
------
 f
(1 row)

denis=# select int4range(null, 1) && int4range(0, null) as test;
 test 
------
 t
(1 row)
于 2013-10-30T09:41:39.727 回答