A common way to generalize the traditional operations to the temporal types is to apply the operation at each instant, which yields a temporal value as result. In that case, the operation is only defined on the intersection of the temporal extents of the operands; if the temporal extents are disjoint, then the result is null. For example, the temporal comparison operators, such as #<
, test whether the values taken by their operands at each instant satisfy the condition and return a temporal Boolean. Examples of the various generalizations of the operators are given next.
-- Temporal comparison SELECT tfloat '[2@2001-01-01, 2@2001-01-03)' #< tfloat '[1@2001-01-01, 3@2001-01-03)'; -- {[f@2001-01-01, f@2001-01-02], (t@2001-01-02, t@2001-01-03)} SELECT tfloat '[1@2001-01-01, 3@2001-01-03)' #< tfloat '[3@2001-01-03, 1@2001-01-05)'; -- NULL -- Temporal addition SELECT tint '[1@2001-01-01, 1@2001-01-03)' + tint '[2@2001-01-02, 2@2001-01-05)'; -- [3@2001-01-02, 3@2001-01-03) -- Temporal intersects SELECT tIntersects(tgeompoint '[Point(0 1)@2001-01-01, Point(3 1)@2001-01-04)', geometry 'Polygon((1 0,1 2,2 2,2 0,1 0))'); -- {[f@2001-01-01, t@2001-01-02, t@2001-01-03], (f@2001-01-03, f@2001-01-04]} -- Temporal distance SELECT tgeompoint '[Point(0 0)@2001-01-01 08:00:00, Point(0 1)@2001-01-03 08:10:00)' <-> tgeompoint '[Point(0 0)@2001-01-02 08:05:00, Point(1 1)@2001-01-05 08:15:00)'; -- [0.5@2001-01-02 08:05:00+00, 0.745184033794557@2001-01-03 08:10:00+00)
Another common requirement is to determine whether the operands ever or always satisfy a condition with respect to an operation. These can be obtained by applying the ever or always comparison operators. These operators are denoted by prefixing the traditional comparison operators with, respectively, ?
(ever) and %
(always). Examples of ever and always comparison operators are given next.
-- Does the operands ever intersect? SELECT eIntersects(tgeompoint '[Point(0 1)@2001-01-01, Point(3 1)@2001-01-04)', geometry 'Polygon((1 0,1 2,2 2,2 0,1 0))') ?= true; -- true -- Does the operands always intersect? SELECT aIntersects(tgeompoint '[Point(0 1)@2001-01-01, Point(3 1)@2001-01-04)', geometry 'Polygon((0 0,0 2,4 2,4 0,0 0))') %= true; -- true -- Is the left operand ever less than the right one ? SELECT (tfloat '[1@2001-01-01, 3@2001-01-03)' #< tfloat '[3@2001-01-01, 1@2001-01-03)') ?= true; -- true -- Is the left operand always less than the right one ? SELECT (tfloat '[1@2001-01-01, 3@2001-01-03)' #< tfloat '[2@2001-01-01, 4@2001-01-03)') %= true; -- true
For example, the eIntersects
function determines whether there is an instant at which the two arguments spatially intersect.
We describe next the functions and operators for temporal types. For conciseness, in the examples we mostly use sequences composed of two instants.