PostgreSQL tsrange:Lower_inf('(-infinity,today)':: tsrange)为假是否正确? [英] PostgreSQL tsrange: is it correct for lower_inf('(-infinity,today)'::tsrange) to be false?

查看:162
本文介绍了PostgreSQL tsrange:Lower_inf('(-infinity,today)':: tsrange)为假是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写一个程序时,该程序接受来自用户的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?

推荐答案

混乱源自无限的两种不同含义


  1. 时间戳类型接受 无穷大 -infinity

  2. 范围类型的一般概念是没有下限/上限的范围。用于测试它的函数称为 lower_inf() upper_inf() ,但他们确实在测试该范围内的无界。没有上限/下限的范围 无穷大 / 无穷大分别表示时间戳

  1. timestamp types accept special values for infinity and -infinity.
  2. Range types have a general concept for ranges without lower / upper bound. The functions to test for it are called lower_inf() and upper_inf(), but they are really testing for "no bound" in the range. Ranges with no upper / lower bound include the value infinity / -infinity for timestamp respectively.

手册:

此外,某些元素类型具有无限的概念,但是就范围类型机制而言,这只是
的另一个值。以
为例,在时间戳范围内, [today,] 的含义与
[today,)。但是 [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 value infinity.

SQL小提琴。

也许函数实际上应该称为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆