来自精美手册:http ://www.postgresql.org/docs/9.4/static/functions-range.html
该upper_inf
功能会告诉你。
# select upper_inf(int8range(1, null));
upper_inf
-----------
t
(1 row)
# select upper_inf(int8range(1, 2));
upper_inf
-----------
f
(1 row)
如果您需要对此进行查询,我认为索引不会对您有所帮助。
http://www.postgresql.org/docs/9.4/static/rangetypes.html
A GiST or SP-GiST index can accelerate queries involving these range
operators: =, &&, <@, @>, <<, >>, -|-, &<, and &> (see Table 9-47
for more information).
不过,您可以创建一个有助于该查询的部分索引。例如
# create table foo (id int primary key, bar int8range);
CREATE TABLE
# create index on foo(bar) where upper_inf(bar) = true;
CREATE INDEX
# \d foo
Table "freshop.foo"
Column | Type | Modifiers
--------+-----------+-----------
id | integer | not null
bar | int8range |
Indexes:
"foo_pkey" PRIMARY KEY, btree (id)
"foo_bar_idx" btree (bar) WHERE upper_inf(bar) = true
然后,如果您放入upper_inf(bar) = true
查询中,优化器应该了解使用foo_upper_inf_idx
索引。