使用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
,anddaterange
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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。