Another possible generalization of the traditional comparison operators (=
, <>
, <
, <=
, etc.) to temporal types, is to determine whether the comparison is true or false at each instant. In this case, the result is a temporal Boolean. The temporal comparison operators are denoted by prefixing the traditional comparison operators with #
. Some examples are #=
or #<=
. Temporal equality and non-equality are available for all temporal types, while temporal inequalities are only available for temporal types whose base type has a total order defined, that is, tint
, tfloat
, or ttext
.
Temporal equal
{base, ttype} #= {base, ttype}: tbool
SELECT tfloat '[1@2012-01-01, 2@2012-01-04)' #= 3; -- "{[f@2012-01-01, f@2012-01-04)}" SELECT tfloat '[1@2012-01-01, 4@2012-01-04)' #= tint '[1@2012-01-01, 1@2012-01-04)'; -- "{[t@2012-01-01], (f@2012-01-01, f@2012-01-04)}" SELECT tfloat '[1@2012-01-01, 4@2012-01-04)' #= tfloat '[4@2012-01-02, 1@2012-01-05)'; -- "{[f@2012-01-02, t@2012-01-03], (f@2012-01-03, f@2012-01-04)}" SELECT tgeompoint '[Point(0 0)@2012-01-01, Point(2 2)@2012-01-03)' #= geometry 'Point(1 1)'; -- "{[f@2012-01-01, t@2012-01-02], (f@2012-01-02, f@2012-01-03)}" SELECT tgeompoint '[Point(0 0)@2012-01-01, Point(2 2)@2012-01-03)' #= tgeompoint '[Point(0 2)@2012-01-01, Point(2 0)@2012-01-03)'; -- "{[f@2012-01-01], (t@2012-01-01, t@2012-01-03)}"
Temporal different
{base, ttype} #<> {base, ttype}: tbool
SELECT tfloat '[1@2012-01-01, 4@2012-01-04)' #<> 2; -- "{[t@2012-01-01, f@2012-01-02], (t@2012-01-02, 2012-01-04)}" SELECT tfloat '[1@2012-01-01, 4@2012-01-04)' #<> tint '[2@2012-01-02, 2@2012-01-05)'; -- "{[f@2012-01-02], (t@2012-01-02, t@2012-01-04)}"
Temporal less than
{base, torder} #< {base, torder}: tbool
SELECT tfloat '[1@2012-01-01, 4@2012-01-04)' #< 2; -- "{[t@2012-01-01, f@2012-01-02, f@2012-01-04)}" SELECT tint '[2@2012-01-01, 2@2012-01-05)' #< tfloat '[1@2012-01-03, 3@2012-01-05)'; -- "{[f@2012-01-03, f@2012-01-04], (t@2012-01-04, t@2012-01-05)}"
Temporal greater than
{base, torder} #> {base, torder}: tbool
SELECT 1 #> tint '[1@2012-01-03, 1@2012-01-05)'; -- "[f@2012-01-03, f@2012-01-05)"
Temporal less than or equal to
{base, torder} #<= {base, torder}: tbool
SELECT tint '[1@2012-01-01, 1@2012-01-05)' #<= tfloat '{2@2012-01-03, 3@2012-01-04}'; -- "{t@2012-01-03, t@2012-01-04}"
Temporal greater than or equal to
{base, torder} #>= {base, torder}: tbool
SELECT 'AAA'::text #> ttext '{[AAA@2012-01-01, AAA@2012-01-03), [BBB@2012-01-04, BBB@2012-01-05)}'; -- "{[f@2012-01-01, f@2012-01-03), [t@2012-01-04, t@2012-01-05)}"