gpt4 book ai didi

PostgreSQL tsrange: lower_inf ('(-infinity,today)'::tsrange) 为假是否正确?

转载 作者:行者123 更新时间:2023-11-29 11:32:50 25 4
gpt4 key购买 nike

在编写接受来自用户的 tsrange 文字的程序的过程中,这些文字随后被插入到各种 SQL 查询中,今天我正在测试一些 tsrange 以查看 PostgreSQL 9.3.5 如何解释它们。

这一个,尤其是行为奇怪:'(-infinity,today)'::tsrange

lower_inf 函数表示下界不是无限的(!)

test=> SELECT lower_inf('(-infinity,today)'::tsrange);
lower_inf
-----------
f
(1 row)

但是 PostgreSQL 报告说这个 tsrange 包含一个像 '1000-01-01 BC' 这样的时间戳。 . .

test=> SELECT '(-infinity,today)'::tsrange @> '1000-01-01 BC'::timestamp;
?column?
----------
t
(1 row)

任何人都可以阐明这一点吗?

最佳答案

混淆源于此处“无限”的两种不同含义

  1. timestamp 类型接受 special values for infinity and -infinity .
  2. 范围类型对于没有下限/上限的范围有一个通用的概念。对其进行测试的函数称为 lower_inf() and upper_inf() ,但他们实际上是在测试范围内的“无界限”。没有上限/下限的范围包括 infinity/-infinity for timestamp 分别。

The manual:

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 Fiddle.

也许这些函数真的应该被称为 lower_nobound()upper_nobound() 以避免混淆......

关于PostgreSQL tsrange: lower_inf ('(-infinity,today)'::tsrange) 为假是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27103608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com