A possible generalization of the traditional comparison operators (=
, <>
, <
, <=
, etc.) to temporal types, is to determine whether the comparison is ever or always true. In this case, the result is a Boolean value. MobilityDB provides operators to test whether the comparison of a temporal value and a value of the base type is ever or always true. These operators are denoted by prefixing the traditional comparison operators with, respectively, ?
(ever) and %
(always). Some examples are ?=
, %<>
, or ?<=
. Ever/always equality and non-equality are available for all temporal types, while ever/always inequalities are only available for temporal types whose base type has a total order defined, that is, tint
, tfloat
, or ttext
. The ever and always comparisons are inverse operators: for example, ?=
is the inverse of %<>
, and ?>
is the inverse of %<=
.
Is the temporal value ever equal to the value?
ttype ?= base: bool
The function does not take into account whether the bounds are inclusive or not.
SELECT tfloat '[1@2012-01-01, 3@2012-01-04)' ?= 2; -- true SELECT tfloat '[1@2012-01-01, 3@2012-01-04)' ?= 3; -- true SELECT tgeompoint '[Point(0 0)@2012-01-01, Point(2 2)@2012-01-04)' ?= geometry 'Point(1 1)'; -- true
Is the temporal value ever different from the value?
ttype ?<> base: bool
SELECT tfloat '[1@2012-01-01, 3@2012-01-04)' ?<> 2; -- false SELECT tfloat '[2@2012-01-01, 2@2012-01-04)' ?<> 2; -- true SELECT tgeompoint '[Point(1 1)@2012-01-01, Point(1 1)@2012-01-04)' ?<> geometry 'Point(1 1)'; -- true
Is the temporal value ever less than the value?
tnumber ?< number: bool
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)}"
Is the temporal value ever greater than the value?
tnumber ?> number: bool
SELECT tint '[1@2012-01-03, 1@2012-01-05)' ?> 1; -- "[f@2012-01-03, f@2012-01-05)"
Is the temporal value ever less than or equal to the value?
tnumber ?<= number: bool
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}"
Is the temporal value ever greater than or equal to the value?
tnumber ?>= number: bool
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)}"
Is the temporal value always equal to the value?
ttype %= base: bool
The function does not take into account whether the bounds are inclusive or not.
SELECT tfloat '[1@2012-01-01, 3@2012-01-04)' %= 2; -- true SELECT tfloat '[1@2012-01-01, 3@2012-01-04)' %= 3; -- true SELECT tgeompoint '[Point(0 0)@2012-01-01, Point(2 2)@2012-01-04)' %= geometry 'Point(1 1)'; -- true
Is the temporal value always different to the value?
ttype %<> base: bool
SELECT tfloat '[1@2012-01-01, 3@2012-01-04)' %<> 2; -- false SELECT tfloat '[2@2012-01-01, 2@2012-01-04)' %<> 2; -- true SELECT tgeompoint '[Point(1 1)@2012-01-01, Point(1 1)@2012-01-04)' %<> geometry 'Point(1 1)'; -- true
Is the temporal value always less than the value?
tnumber %< number: bool
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)}"
Is the temporal value always greater than the value?
tnumber %> number: bool
SELECT tint '[1@2012-01-03, 1@2012-01-05)' %> 1; -- "[f@2012-01-03, f@2012-01-05)"
Is the temporal value always less than or equal to the value?
tnumber %<= number: bool
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}"
Is the temporal value always greater than or equal to the value?
tnumber %>= number: bool
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)}"