Using PostgreSQL 9.4:
SELECT x, lower(x), upper(x) FROM (SELECT '[1,2]'::numrange x) q;
> [1,2] | 1 | 2 -- looks OK
SELECT x, lower(x), upper(x) FROM (SELECT '[1,2]'::int4range x) q;
> [1,3) | 1 | >>3<< -- this is unexpected
Let's check further:
SELECT x, lower(x), upper(x) FROM (SELECT '[1,3)'::numrange x) q1;
> [1,3) | 1 | 3 -- looks OK
SELECT x, lower(x), upper(x) FROM (SELECT '[1,3]'::numrange x) q1;
> [1,3] | 1 | 3 -- looks OK
From pg documentation:
upper(anyrange) | range's element type | upper bound of range | upper(numrange(1.1,2.2)) | 2.2
While 3
technically is an upper bound of the integer range [1,3) ∩ ℕ = {1, 2}
, so are all natural numbers ≥ 2. I would expect the upper
function returns the supremum (least upper bound) of the range.
Am I missing something?