PostgreSQL tsrange:Lower_inf('(-infinity,today)':: tsrange)为假是否正确? [英] PostgreSQL tsrange: is it correct for lower_inf('(-infinity,today)'::tsrange) to be false?
问题描述
在编写一个程序时,该程序接受来自用户的tsrange文字,然后将其插入各种SQL查询中,今天我正在测试一些tsranges,以查看它们如何被PostgreSQL 9.3.5解释。
In the course of writing a program that accepts tsrange literals from the user, which are then plugged into various SQL queries, today I was testing some tsranges to see how they are interpreted by PostgreSQL 9.3.5.
这个特别的表现很奇怪:'(-infinity,today)':: tsrange
This one, in particular, behaves strangely: '(-infinity,today)'::tsrange
lower_inf函数表示下界不是无限(!)
The lower_inf function says the lower bound is not infinite (!)
test=> SELECT lower_inf('(-infinity,today)'::tsrange);
lower_inf
-----------
f
(1 row)
但是PostgreSQL报告该tsrange包含类似'1000-01-01 BC'的时间戳。 。 。
Yet PostgreSQL reports that this tsrange contains a timestamp like '1000-01-01 BC' . . .
test=> SELECT '(-infinity,today)'::tsrange @> '1000-01-01 BC'::timestamp;
?column?
----------
t
(1 row)
有人可以阐明这一点吗?
Can anyone shed light on this?
推荐答案
混乱源自无限的两种不同含义 。
-
时间戳
类型接受无穷大$的特殊值c $ c>和
。-infinity
- 范围类型的一般概念是没有下限/上限的范围。用于测试它的函数称为
lower_inf()
和upper_inf()
,但他们确实在测试该范围内的无界。没有上限/下限的范围 值无穷大
/无穷大
分别表示时间戳
。
timestamp
types accept special values forinfinity
and-infinity
.- Range types have a general concept for ranges without lower / upper bound. The functions to test for it are called
lower_inf()
andupper_inf()
, but they are really testing for "no bound" in the range. Ranges with no upper / lower bound include the valueinfinity
/-infinity
fortimestamp
respectively.
此外,某些元素类型具有无限的概念,但是就范围类型机制而言,这只是
的另一个值。以
为例,在时间戳范围内, [today,]
的含义与
[today,)$相同c $ c>。但是
[today,infinity]
的含义与
[today,infinity)
有所不同-后者不包括特殊时间戳记值 infinity
。
Also, some element types have a notion of "infinity", but that is just another value so far as the range type mechanisms are concerned. For example, in timestamp ranges,
[today,]
means the same thing as[today,)
. But[today,infinity]
means something different from[today,infinity)
— the latter excludes the special timestamp valueinfinity
.
也许函数实际上应该称为 lower_nobound()
和 upper_nobound()
之类的东西,以避免混淆...
Maybe those functions should really be called something like lower_nobound()
and upper_nobound()
to avoid confusion ...
这篇关于PostgreSQL tsrange:Lower_inf('(-infinity,today)':: tsrange)为假是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!