A temporal value can be transformed to another subtype. An error is raised if the subtypes are incompatible.
Transform a temporal value to another subtype
ttypeInst(ttype) → ttypeInst
ttypeSeq(ttype) → ttypeSeq
ttypeSeqSet(ttype) → ttypeSeqSet
SELECT tboolInst(tbool '{[true@2001-01-01]}'); -- t@2001-01-01 SELECT tboolInst(tbool '{[true@2001-01-01, true@2001-01-02]}'); -- ERROR: Cannot transform input value to a temporal instant SELECT tintSeq(tint '1@2001-01-01'); -- [1@2001-01-01] SELECT tfloatSeqSet(tfloat '2.5@2001-01-01'); -- {[2.5@2001-01-01]} SELECT tfloatSeqSet(tfloat '{2.5@2001-01-01, 1.5@2001-01-02, 3.5@2001-01-03}'); -- {[2.5@2001-01-01],[1.5@2001-01-02],[3.5@2001-01-03]}
Transform a temporal value to another interpolation
setInterp(ttype, interp) → ttype
SELECT setInterp(tbool 'true@2001-01-01','discrete'); -- {t@2001-01-01} SELECT setInterp(tfloat '{[1@2001-01-01], [2@2001-01-02], [1@2001-01-03]}', 'discrete'); -- {1@2001-01-01, 2@2001-01-02, 1@2001-01-03} SELECT setInterp(tfloat 'Interp=Step;[1@2001-01-01, 2@2001-01-02, 1@2001-01-03, 2@2001-01-04]', 'linear'); /* {[1@2001-01-01, 1@2001-01-02), [2@2001-01-02, 2@2001-01-03), [1@2001-01-03, 1@2001-01-04), [2@2001-01-04]} */ SELECT asText(setInterp(tgeompoint 'Interp=Step;{[Point(1 1)@2001-01-01, Point(2 2)@2001-01-02], [Point(3 3)@2001-01-05, Point(4 4)@2001-01-06]}', 'linear')); /* {[POINT(1 1)@2001-01-01, POINT(1 1)@2001-01-02), [POINT(2 2)@2001-01-02], [POINT(3 3)@2001-01-05, POINT(3 3)@2001-01-06), [POINT(4 4)@2001-01-06]} */
Shift the value or time span of a temporal value by a value or interval
shiftValue(tnumber,base) → tnumber
shiftTime(ttype,interval) → ttype
SELECT shiftValue(tint '{1@2001-01-01, 2@2001-01-03, 1@2001-01-05}', 1); -- {2@2001-01-02, 3@2001-01-04, 2@2001-01-06} SELECT shiftValue(tfloat '{[1@2001-01-01,2@2001-01-02],[3@2001-01-03,4@2001-01-04]}', -1); -- {[0@2001-01-01, 1@2001-01-02], [2@2001-01-03, 3@2001-01-04]}
SELECT shiftTime(tint '{1@2001-01-01, 2@2001-01-03, 1@2001-01-05}', '1 day'); -- {1@2001-01-02, 2@2001-01-04, 1@2001-01-06} SELECT shiftTime(tfloat '[1@2001-01-01, 2@2001-01-03]', '1 day'); -- [1@2001-01-02, 2@2001-01-04] SELECT asText(shiftTime(tgeompoint '{[Point(1 1)@2001-01-01, Point(2 2)@2001-01-03], [Point(2 2)@2001-01-04, Point(1 1)@2001-01-05]}', '1 day')); /* {[POINT(1 1)@2001-01-02, POINT(2 2)@2001-01-04], [POINT(2 2)@2001-01-05, POINT(1 1)@2001-01-06]} */
Scale the value or time span of a temporal value to a value or interval
scaleValue(tnumber,width) → tnumber
scaleTime(ttype,interval) → ttype
If the value or time span of the temporal value is zero (for example, for a temporal instant), the result is the temporal value. The given width or interval must be strictly greater than zero.
SELECT scaleValue(tint '1@2001-01-01', 1); -- 1@2001-01-01 SELECT scaleValue(tfloat '{[1@2001-01-01,2@2001-01-02], [3@2001-01-03,4@2001-01-04]}', 6); -- {[1@2001-01-01, 3@2001-01-03], [5@2001-01-05, 7@2001-01-07]} SELECT scaleValue(tint '1@2001-01-01', -1); -- ERROR: The value must be strictly positive: -1
SELECT scaleTime(tint '1@2001-01-01', '1 day'); -- 1@2001-01-01 SELECT scaleTime(tint '{1@2001-01-01, 2@2001-01-03, 1@2001-01-05}', '1 day'); -- {1@2001-01-01 00:00:00+01, 2@2001-01-01 12:00:00+01, 1@2001-01-02 00:00:00+01} SELECT scaleTime(tfloat '[1@2001-01-01, 2@2001-01-03]', '1 day'); -- [1@2001-01-01, 2@2001-01-02] SELECT asText(scaleTime(tgeompoint '{[Point(1 1)@2001-01-01, Point(2 2)@2001-01-02, Point(1 1)@2001-01-03], [Point(2 2)@2001-01-04, Point(1 1)@2001-01-05]}', '1 day')); /* {[POINT(1 1)@2001-01-01 00:00:00+01, POINT(2 2)@2001-01-01 06:00:00+01, POINT(1 1)@2001-01-01 12:00:00+01], [POINT(2 2) @2001-01-01 18:00:00+01, POINT(1 1)@2001-01-02 00:00:00+01]} */ SELECT scaleTime(tint '1@2001-01-01', '-1 day'); -- ERROR: The interval must be positive: -1 days
Shift and scale the value or time span of a temporal value to the two values or intervals
shiftScaleValue(tnumber,base,base) → tnumber
shiftScaleTime(ttype,interval,interval) → ttype
These functions combine the functions shiftValue
and scaleValue
or shiftTime
and scaleTime
.
SELECT shiftScaleValue(tint '1@2001-01-01', 1, 1); -- 2@2001-01-01 SELECT shiftScaleValue(tfloat '{[1@2001-01-01,2@2001-01-02],[3@2001-01-03,4@2001-01-04]}', -1, 6); -- {[0@2001-01-01, 2@2001-01-02], [4@2001-01-03, 6@2001-01-04]}
SELECT shiftScaleTime(tint '1@2001-01-01', '1 day', '1 day'); -- 1@2001-01-02 SELECT shiftScaleTime(tint '{1@2001-01-01, 2@2001-01-03, 1@2001-01-05}', '1 day','1 day'); -- {1@2001-01-02 00:00:00+01, 2@2001-01-02 12:00:00+01, 1@2001-01-03 00:00:00+01} SELECT shiftScaleTime(tfloat '[1@2001-01-01, 2@2001-01-03]', '1 day', '1 day'); -- [1@2001-01-02, 2@2001-01-03] SELECT asText(shiftScaleTime(tgeompoint '{[Point(1 1)@2001-01-01, Point(2 2)@2001-01-02, Point(1 1)@2001-01-03], [Point(2 2)@2001-01-04, Point(1 1)@2001-01-05]}', '1 day', '1 day')); /* {[POINT(1 1)@2001-01-02 00:00:00+01, POINT(2 2)@2001-01-02 06:00:00+01, POINT(1 1)@2001-01-02 12:00:00+01], [POINT(2 2) @2001-01-02 18:00:00+01, POINT(1 1)@2001-01-03 00:00:00+01]} */
Extract from a temporal sequence (set) with linear interpolation the subsequences where the objects stays within an area with a specified maximum size (maxDist
) for at least the given duration (minDuration
)
stops({tcontSeq,ttypeSeqSet},maxDist=0.0,minDuration='0 minutes') → ttypeSeqSet
For spatial types, the size of the area is computed as the diagonal of the minimum rotated rectangle of the points in the subsequence. For scalar types, the size is computed as the width of the enclosing interval. If maxDist
is not given it is assumed 0.0 and thus, the function extracts the constant segments of the given temporal value. For temporal points, the distance is computed in the units of the coordinate system. Note that even though the function accepts 3D geometries, the computation is always performed in 2D.
SELECT stops(tfloat '[1@2001-01-01, 1@2001-01-02, 2@2001-01-03]'); -- {[1@2001-01-01, 1@2001-01-02)} SELECT stops(tfloat '[1@2001-01-01, 1@2001-01-02, 2@2001-01-03]', 0.0, '2 days'); -- NULL SELECT asText(stops(tgeompoint '[Point(1 1)@2001-01-01, Point(1 1)@2001-01-02, Point(2 2)@2001-01-03, Point(2 2)@2001-01-04]')); /* {[POINT(1 1)@2001-01-01, POINT(1 1)@2001-01-02), [POINT(2 2)@2001-01-03, POINT(2 2)@2001-01-04]} */ SELECT asText(stops(tgeompoint '[Point(1 1 1)@2001-01-01, Point(1 1 1)@2001-01-02, Point(2 2 2)@2001-01-03, Point(2 2 2)@2001-01-04]', 1.75)); /* {[POINT Z (1 1 1)@2001-01-01, POINT Z (1 1 1)@2001-01-02, POINT Z (2 2 2)@2001-01-03, POINT Z (2 2 2)@2001-01-04]} */
Transform a nonlinear temporal value into a set of rows, each one is a pair composed of a base value and a period set during which the temporal value has the base value
unnest(ttype) → {(value,time)}
SELECT (un).value, (un).time FROM (SELECT unnest(tfloat '{1@2001-01-01, 2@2001-01-02, 1@2001-01-03}') AS un) t; -- 1 | {[2001-01-01, 2001-01-01], [2001-01-03, 2001-01-03]} -- 2 | {[2001-01-02, 2001-01-02]} SELECT (un).value, (un).time FROM (SELECT unnest(tint '[1@2001-01-01, 2@2001-01-02, 1@2001-01-03]') AS un) t; -- 1 | {[2001-01-01, 2001-01-02), [2001-01-03, 2001-01-03]} -- 2 | {[2001-01-02, 2001-01-03)} SELECT (un).value, (un).time FROM (SELECT unnest(tfloat '[1@2001-01-01, 2@2001-01-02, 1@2001-01-03]') AS un) t; -- ERROR: The temporal value cannot have linear interpolation SELECT ST_AsText((un).value), (un).time FROM (SELECT unnest(tgeompoint 'Interp=Step;[Point(1 1)@2001-01-01, Point(2 2)@2001-01-02, Point(1 1)@2001-01-03]') AS un) t; -- POINT(1 1) | {[2001-01-01, 2001-01-02), [2001-01-03, 2001-01-03]} -- POINT(2 2) | {[2001-01-02, 2001-01-03)}