加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – Postgres int4range上限意外值

发布时间:2020-12-13 16:08:00 所属栏目:百科 来源:网络整理
导读:使用PostgreSQL 9.4: SELECT x,lower(x),upper(x) FROM (SELECT '[1,2]'::numrange x) q; [1,2] | 1 | 2 -- looks OKSELECT x,2]'::int4range x) q; [1,3) | 1 | 3 -- this is unexpected 让我们进一步检查: SELECT x,3)'::numrange x) q1; [1,3) | 1 | 3
使用PostgreSQL 9.4:

SELECT x,lower(x),upper(x) FROM (SELECT '[1,2]'::numrange x) q;
> [1,2] | 1 | 2      -- looks OK

SELECT x,2]'::int4range x) q;
> [1,3) | 1 | >>3<<  -- this is unexpected

让我们进一步检查:

SELECT x,3)'::numrange x) q1;
> [1,3) | 1 | 3      -- looks OK

SELECT x,3]'::numrange x) q1;
> [1,3] | 1 | 3      -- looks OK

来自pg文档:

upper(anyrange) | range’s element type | upper bound of range | upper(numrange(1.1,2.2)) | 2.2

虽然技术上3是整数范围的上限[1,3]∩?= {1,2},所以所有自然数≥2.我希望上面的函数返回范围的上限(最小上限) .

我错过了什么吗?

解决方法

这是因为int4range是一个 discrete range.这样的范围总是自动转换为它们的规范表示,以便能够测试等价,f.:

SELECT '[4,8]'::int4range = '(3,9)'::int4range

The built-in range types int4range,int8range,and daterange all use a canonical form that includes the lower bound and excludes the upper bound; that is,[). User-defined range types can use other conventions,however.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读