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.
This one, in particular, behaves strangely: '(-infinity,today)'::tsrange
The lower_inf function says the lower bound is not infinite (!)
test=> SELECT lower_inf('(-infinity,today)'::tsrange);
lower_inf
-----------
f
(1 row)
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?
The confusion stems from two different meanings of "infinity" here.
timestamptypes accept special values forinfinityand-infinity.lower_inf()andupper_inf(), but they are really testing for "no bound" in the range. Ranges with no upper / lower bound include the valueinfinity/-infinityfortimestamprespectively.The manual:
SQL Fiddle.
Maybe those functions should really be called something like
lower_nobound()andupper_nobound()to avoid confusion ...