There are two complementary sets of restriction functions. The first set functions restricts the temporal value with respect to a value or a time extent. Examples are atValues
or atTime
. The second set functions restricts the temporal value with respect to the complement of a value or a time extent. Examples are minusValues
or minusTime
Restrict to (the complement of) a set of values
atValues(ttype,values) → ttype
minusValues(ttype,values) → ttype
SELECT atValues(tint '[1@2001-01-01, 1@2001-01-15)', 1); -- [1@2001-01-01, 1@2001-01-15) SELECT asText(atValues(tgeompoint '[Point(0 0 0)@2001-01-01, Point(2 2 2)@2001-01-03)', geometry 'Point(1 1 1)')); -- {[POINT Z (1 1 1)@2001-01-02]} SELECT atValues(tfloat '[1@2001-01-01, 4@2001-01-4)', floatset '{1, 3, 5}'); -- {[1@2001-01-01], [3@2001-01-03]} SELECT asText(atValues(tgeompoint '[Point(0 0)@2001-01-01, Point(2 2)@2001-01-03)', geomset '{"Point(0 0)", "Point(1 1)"}')); -- {[POINT(0 0)@2001-01-01], [POINT(1 1)@2001-01-02]} SELECT atValues(tfloat '[1@2001-01-01, 4@2001-01-4)', floatspan '[1,3]'); -- [1@2001-01-01, 3@2001-01-03] SELECT atValues(tfloat '[1@2001-01-01, 5@2001-01-05)', floatspanset '{[1,2], [3,4]}'); -- {[1@2001-01-01, 2@2001-01-02],[3@2001-01-03, 4@2001-01-04]}
SELECT minusValues(tint '[1@2001-01-01, 2@2001-01-02, 2@2001-01-03)', 1); -- {[2@2001-01-02, 2@2001-01-03)} SELECT asText(minusValues(tgeompoint '[Point(0 0 0)@2001-01-01, Point(2 2 2)@2001-01-03)', geometry 'Point(1 1 1)')); /* {[POINT Z (0 0 0)@2001-01-01, POINT Z (1 1 1)@2001-01-02), (POINT Z (1 1 1)@2001-01-02, POINT Z (2 2 2)@2001-01-03)} */ SELECT minusValues(tfloat '[1@2001-01-01, 4@2001-01-4)', floatset '{2, 3}'); /* {[1@2001-01-01, 2@2001-01-02), (2@2001-01-02, 3@2001-01-03), (3@2001-01-03, 4@2001-01-04)} */ SELECT asText(minusValues(tgeompoint '[Point(0 0 0)@2001-01-01, Point(3 3 3)@2001-01-04)', geomset '{"Point(1 1 1)', 'Point(2 2 2)"}')); /* {[POINT Z (0 0 0)@2001-01-01, POINT Z (1 1 1)@2001-01-02), (POINT Z (1 1 1)@2001-01-02, POINT Z (2 2 2)@2001-01-03), (POINT Z (2 2 2)@2001-01-03, POINT Z (3 3 3)@2001-01-04)} */ SELECT minusValues(tfloat '[1@2001-01-01, 4@2001-01-4)', floatspan '[2,3]'); -- {[1@2001-01-01, 2@2001-01-02), (3@2001-01-03, 4@2001-01-04)} SELECT minusValues(tfloat '[1@2001-01-01, 5@2001-01-05)', floatspanset '{[1,2], [3,4]}'); -- {(2@2001-01-02, 3@2001-01-03), (4@2001-01-04, 5@2001-01-05)}
Restrict to (the complement of) the minimum value
atMin(torder) → torder
minusMin(torder) → torder
The function returns null if the minimum value only happens at exclusive bounds.
SELECT atMin(tint '{1@2001-01-01, 2@2001-01-03, 1@2001-01-05}'); -- {1@2001-01-01, 1@2001-01-05} SELECT atMin(tint '(1@2001-01-01, 3@2001-01-03]'); -- {(1@2001-01-01, 1@2001-01-03)} SELECT atMin(tfloat '(1@2001-01-01, 3@2001-01-03]'); -- NULL SELECT atMin(ttext '{(AA@2001-01-01, AA@2001-01-03), (BB@2001-01-03, AA@2001-01-05]}'); -- {(AA@2001-01-01, AA@2001-01-03), [AA@2001-01-05]}
SELECT minusMin(tint '{1@2001-01-01, 2@2001-01-03, 1@2001-01-05}'); -- {2@2001-01-03} SELECT minusMin(tfloat '[1@2001-01-01, 3@2001-01-03]'); -- {(1@2001-01-01, 3@2001-01-03]} SELECT minusMin(tfloat '(1@2001-01-01, 3@2001-01-03)'); -- {(1@2001-01-01, 3@2001-01-03)} SELECT minusMin(tint '{[1@2001-01-01, 1@2001-01-03), (1@2001-01-03, 1@2001-01-05)}'); -- NULL
Restrict to (the complement of) the maximum value
atMax(torder) → torder
minusMax(torder) → torder
The function returns null if the maximum value only happens at exclusive bounds.
SELECT atMax(tint '{1@2001-01-01, 2@2001-01-03, 3@2001-01-05}'); -- {3@2001-01-05} SELECT atMax(tfloat '(1@2001-01-01, 3@2001-01-03)'); -- NULL SELECT atMax(tfloat '{(2@2001-01-01, 1@2001-01-03), [2@2001-01-03, 2@2001-01-05)}'); -- {[2@2001-01-03, 2@2001-01-05]} SELECT atMax(ttext '{(AA@2001-01-01, AA@2001-01-03), (BB@2001-01-03, AA@2001-01-05]}'); -- {("BB"@2001-01-03, "BB"@2001-01-05)}
SELECT minusMax(tint '{1@2001-01-01, 2@2001-01-03, 3@2001-01-05}'); -- {1@2001-01-01, 2@2001-01-03} SELECT minusMax(tfloat '[1@2001-01-01, 3@2001-01-03]'); -- {[1@2001-01-01, 3@2001-01-03)} SELECT minusMax(tfloat '(1@2001-01-01, 3@2001-01-03)'); -- {(1@2001-01-01, 3@2001-01-03)} SELECT minusMax(tfloat '{[2@2001-01-01, 1@2001-01-03), [2@2001-01-03, 2@2001-01-05)}'); -- {(2@2001-01-01, 1@2001-01-03)} SELECT minusMax(tfloat '{[1@2001-01-01, 3@2001-01-03), (3@2001-01-03, 1@2001-01-05)}'); -- {[1@2001-01-01, 3@2001-01-03), (3@2001-01-03, 1@2001-01-05)}
Restrict to (the complement of) a geometry, a Z span, and/or a period
atGeometry(tgeompoint,geometry[,zspan]) → tgeompoint
minusGeometry(tgeompoint,geometry[,zspan]) → tgeompoint
atGeometryTime(tgeompoint,geometry[,zspan],period) → tgeompoint
minusGeometryTime(tgeompoint,geometry[,zspan],period) → tgeompoint
The geometry must be in 2D and the computation with respect to it is done in 2D. The result preserves the Z dimension of the temporal point, if it exists.
SELECT asText(atGeometry(tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)', geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))')); -- {"[POINT(1 1)@2001-01-02, POINT(2 2)@2001-01-03]"} SELECT astext(atGeometry(tgeompoint '[Point(0 0 0)@2001-01-01, Point(4 4 4)@2001-01-05]', geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))')); -- {[POINT Z (1 1 1)@2001-01-02, POINT Z (2 2 2)@2001-01-03]} SELECT asText(atGeometry(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 1 1)@2001-01-03, Point(3 1 3)@2001-01-05]', 'Polygon((2 0,2 2,2 4,4 0,2 0))', '[0,2]')); -- {[POINT Z (2 1 1)@2001-01-02, POINT Z (3 1 1)@2001-01-03, POINT Z (3 1 2)@2001-01-04]}
SELECT asText(atGeometryTime(tgeompoint '[Point(1 1)@2001-01-01, Point(5 1)@2001-01-05, Point(1 1)@2001-01-09]', geometry 'Polygon((2 0,2 2,4 2,4 0,2 0))', tstzspan '[2001-01-03, 2001-01-05]')); -- {[POINT(3 1)@2001-01-03, POINT(4 1)@2001-01-04]} SELECT asText(atGeometryTime(tgeompoint '[Point(1 1 1)@2001-01-01, Point(5 1 5)@2001-01-05, Point(1 1 9)@2001-01-09]', geometry 'Polygon((2 0,2 2,4 2,4 0,2 0))', floatspan '[0,5]', tstzspan '[2001-01-03, 2001-01-06]')); -- {[POINT Z (3 1 3)@2001-01-03, POINT Z (4 1 4)@2001-01-04]}
SELECT asText(minusGeometry(tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)', geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))')); /* {[POINT(0 0)@2001-01-01, POINT(1 1)@2001-01-02), (POINT(2 2)@2001-01-03, POINT(3 3)@2001-01-04)} */ SELECT astext(minusGeometry(tgeompoint '[Point(0 0 0)@2001-01-01, Point(4 4 4)@2001-01-05]', geometry 'Polygon((1 1,1 2,2 2,2 1,1 1))')); /* {[POINT Z (0 0 0)@2001-01-01, POINT Z (1 1 1)@2001-01-02), (POINT Z (2 2 2)@2001-01-03, POINT Z (4 4 4)@2001-01-05]} */ SELECT asText(minusGeometry(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 1 1)@2001-01-03, Point(3 1 3)@2001-01-05]', 'Polygon((2 0,2 2,2 4,4 0,2 0))', '[0,2]')); /* {[POINT Z (1 1 1)@2001-01-01, POINT Z (2 1 1)@2001-01-02), (POINT Z (3 1 2)@2001-01-04, POINT Z (3 1 3)@2001-01-05]} */
SELECT asText(minusGeometryTime(tgeompoint '[Point(1 1)@2001-01-01, Point(5 1)@2001-01-05, Point(1 1)@2001-01-09]', geometry 'Polygon((2 0,2 2,4 2,4 0,2 0))', tstzspan '[2001-01-03, 2001-01-05]')); /* {[POINT(1 1)@2001-01-01, POINT(3 1)@2001-01-03), (POINT(4 1)@2001-01-04, POINT(5 1)@2001-01-05, POINT(1 1)@2001-01-09]} */ SELECT asText(minusGeometryTime(tgeompoint '[Point(1 1 1)@2001-01-01, Point(5 1 5)@2001-01-05, Point(1 1 9)@2001-01-09]', geometry 'Polygon((2 0,2 2,4 2,4 0,2 0))', floatspan '[0,5]', tstzspan '[2001-01-03, 2001-01-06]')); /* {[POINT Z (1 1 1)@2001-01-01, POINT Z (3 1 3)@2001-01-03), (POINT Z (4 1 4)@2001-01-04, POINT Z (5 1 5)@2001-01-05, POINT Z (1 1 9)@2001-01-09]} */
Restrict to (the complement of) a time value
atTime(ttype,times) → ttype
minusTime(ttype,times) → ttype
SELECT atTime(tfloat '[1@2001-01-01, 5@2001-01-05)', timestamptz '2001-01-02'); -- 2@2001-01-02 SELECT atTime(tint '[1@2001-01-01, 1@2001-01-15)', tstzset '{2001-01-01, 2001-01-03}'); -- {1@2001-01-01, 1@2001-01-03} SELECT atTime(tfloat '{[1@2001-01-01, 3@2001-01-03), [3@2001-01-04, 1@2001-01-06)}', tstzspan '[2001-01-02,2001-01-05)'); -- {[2@2001-01-02, 3@2001-01-03), [3@2001-01-04, 2@2001-01-05)} SELECT atTime(tint '[1@2001-01-01, 1@2001-01-15)', tstzspanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-05)}'); -- {[1@2001-01-01, 1@2001-01-03),[1@2001-01-04, 1@2001-01-05)}
SELECT minusTime(tfloat '[1@2001-01-01, 5@2001-01-05)', timestamptz '2001-01-02'); -- {[1@2001-01-01, 2@2001-01-02), (2@2001-01-02, 5@2001-01-05)} SELECT minusTime(tint '[1@2001-01-01, 1@2001-01-15)', tstzset '{2001-01-02, 2001-01-03}'); /* {[1@2001-01-01, 1@2001-01-02), (1@2001-01-02, 1@2001-01-03), (1@2001-01-03, 1@2001-01-15)} */ SELECT minusTime(tfloat '{[1@2001-01-01, 3@2001-01-03), [3@2001-01-04, 1@2001-01-06)}', tstzspan '[2001-01-02,2001-01-05)'); -- {[1@2001-01-01, 2@2001-01-02), [2@2001-01-05, 1@2001-01-06)} SELECT minusTime(tint '[1@2001-01-01, 1@2001-01-15)', tstzspanset '{[2001-01-02, 2001-01-03), [2001-01-04, 2001-01-05)}'); /* {[1@2001-01-01, 1@2001-01-02), [1@2001-01-03, 1@2001-01-04), [1@2001-01-05, 1@2001-01-15)} */
Restrict to (the complement of) a tbox
atTbox(tnumber,tbox) → tnumber
minusTbox(tnumber,tbox) → tnumber
SELECT atTbox(tfloat '[0@2001-01-01, 3@2001-01-04)', tbox 'TBOXFLOAT XT((0,2),[2001-01-02, 2001-01-04])'); -- {[1@2001-01-02, 2@2001-01-03]}
SELECT minusTbox(tfloat '[1@2001-01-01, 4@2001-01-04)', 'TBOXFLOAT XT((1,4),[2001-01-03, 2001-01-04])'); -- {[1@2001-01-01, 3@2001-01-03)} WITH temp(temp, box) AS ( SELECT tfloat '[1@2001-01-01, 4@2001-01-04)', tbox 'TBOXFLOAT XT((1,2),[2001-01-03, 2001-01-04])' ) SELECT minusValues(minusTime(temp, box::tstzspan), box::floatspan) FROM temp; -- {[1@2001-01-01], [2@2001-01-02, 3@2001-01-03)}
Notice that when the bounding box has both value and time dimensions, the difference is computed by restricting the temporal number to the box using the function atTbox
, computing the time extent of this restriction, and restricting the temporal number to the difference of the time extent. This is required to ensure that tnumber = merge(atTbox(tnumber,tbox), minusTbox(tnumber,tbox))
(see the function merge
). In other words, while the function atTbox
restricts the temporal number with respect to the span and the period defining the bounding box, the function minusTbox
restricts the temporal number with respect to the span or the period. To obtain the restriction using an and semantics, both the minusValues
and minusTime
functions must be applied.
Restrict to (the complement of) an stbox
atStbox(tgeompoint,stbox,borderInc bool=true) → tgeompoint
minusStbox(tgeompoint,stbox,borderInc bool=true) → tgeompoint
The third optional argument is used for multidimensional tiling (see the section called “Multidimensional Tiling”) to exclude the upper border of the tiles when a temporal value is split in multiple tiles, so that all fragments of the temporal point are exclusive.
SELECT asText(atStbox(tgeompoint '[Point(0 0)@2001-01-01, Point(3 3)@2001-01-04)', stbox 'STBOX XT(((0,0),(2,2)),[2001-01-02, 2001-01-04])')); -- {[POINT(1 1)@2001-01-02, POINT(2 2)@2001-01-03]} SELECT asText(atStbox(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 3 3)@2001-01-03, Point(3 3 2)@2001-01-04, Point(3 3 7)@2001-01-09]', stbox 'STBOX Z((2,2,2),(3,3,3))')); /* {[POINT Z (2 2 2)@2001-01-02, POINT Z (3 3 3)@2001-01-03, POINT Z (3 3 2)@2001-01-04, POINT Z (3 3 3)@2001-01-05]} */
SELECT asText(atStbox(tgeompoint '[Point(1 1)@2001-01-01, Point(1 0)@2001-01-02, Point(0 0)@2001-01-03, Point(0 1)@2001-01-04, Point(1 1)@2001-01-05]', stbox 'STBOX X((0,0),(2,2))', false)); /* {Point(1 1)@2001-01-01, Point(1 0)@2001-01-02, Point(0 0)@2001-01-03, Point(0 1)@2001-01-04, Point(1 1)@2001-01-05} */ SELECT asText(atStbox(tgeompoint '[Point(1 1)@2001-01-01, Point(1 2)@2001-01-02, Point(2 2)@2001-01-03, Point(2 1)@2001-01-04, Point(1 1)@2001-01-05]', stbox 'STBOX X((0,0),(2,2))', false)); /* {[POINT(1 1)@2001-01-01, POINT(1 2)@2001-01-02), (POINT(2 1)@2001-01-04, POINT(1 1)@2001-01-05]} */
SELECT asText(minusStbox(tgeompoint '[Point(1 1)@2001-01-01, Point(4 4)@2001-01-04)', stbox 'STBOX XT(((1,1),(4,4)),[2001-01-03,2001-01-04])')); -- {[POINT(1 1)@2001-01-01), POINT(3 3)@2001-01-03)} SELECT asText(minusStbox(tgeompoint '[Point(1 1 1)@2001-01-01, Point(3 3 3)@2001-01-03, Point(3 3 2)@2001-01-04, Point(3 3 7)@2001-01-09]', stbox 'STBOX Z((2,2,2),(3,3,3))')); /* {[POINT Z (1 1 1)@2001-01-01, POINT Z (2 2 2)@2001-01-02), (POINT Z (3 3 3)@2001-01-05, POINT Z (3 3 7)@2001-01-09]} */ WITH temp(temp, box) AS ( SELECT tgeompoint '[Point(1 1)@2001-01-01, Point(4 4)@2001-01-04)', stbox 'STBOX XT(((1,1),(2,2)),[2001-01-03,2001-01-04])') SELECT asText(minusGeometry(minusTime(temp, box::tstzspan), box::geometry)) FROM temp; -- {(POINT(2 2)@2001-01-02, POINT(3 3)@2001-01-03)}
Similarly to function minusTbox
, when the bounding box has both space and time dimensions, the function minusStbox
restricts the temporal point with respect to the space or the time extents of the box. To obtain the restriction using an and semantics, both the minusGeometry
and minusTime
functions must be applied.