We give next the constructor functions for the various subtypes. Using the constructor function is frequently more convenient than writing a literal constant.
Constructors for temporal types having a constant value
These contructors have two arguments, a base type and a time value, where the latter is a timestamptz
, a tstzset
, a tstzspan
, or a tstzspanset
value for constructing, respectively, an instant, a sequence with discrete interpolation, a sequence with linear or step interpolation, or a sequence set value. The functions for sequence or sequence set values with continuous base type have an optional third argument stating whether the resulting temporal value has linear or step interpolation. Linear interpolation is assumed by default if the argument is not specified.
ttype(base,timestamptz) → ttypeInst
ttype(base,tstzset) → ttypeDiscSeq
ttype(base,tstzspan,interp='linear') → ttypeContSeq
ttype(base,tstzspanset,interp='linear') → ttypeSeqSet
SELECT tbool(true, timestamptz '2001-01-01'); SELECT tint(1, timestamptz '2001-01-01'); SELECT tfloat(1.5, tstzset '{2001-01-01, 2001-01-02}'); SELECT ttext('AAA', tstzset '{2001-01-01, 2001-01-02}'); SELECT tfloat(1.5, tstzspan '[2001-01-01, 2001-01-02]'); SELECT tfloat(1.5, tstzspan '[2001-01-01, 2001-01-02]', 'step'); SELECT tgeompoint('Point(0 0)', tstzspan '[2001-01-01, 2001-01-02]'); SELECT tgeogpoint('SRID=7844;Point(0 0)', tstzspanset '{[2001-01-01, 2001-01-02], [2001-01-03, 2001-01-04]}', 'step');
Constructors for temporal types of sequence subtype
These contructors have a first mandatory argument, which is an array of values of the corresponding instant values and additional optional arguments. The second argument states the interpolation. If the argument is not given, it is by default step for discrete base types such as integer, and linear for continuous base types such as float. An error is raised when linear interpolation is stated for temporal values with discrete base types. For continuous sequences, the third and fourth arguments are Boolean values stating, respectively, whether the left and right bounds are inclusive or exclusive. These arguments are assumed to be true by default if they are not specified.
ttypeSeq(ttypeInst[],interp={'step','linear'},leftInc bool=true,
rightInc bool=true) → ttypeSeq
SELECT tboolSeq(ARRAY[tbool 'true@2001-01-01 08:00:00','false@2001-01-01 08:05:00'], 'discrete'); SELECT tintSeq(ARRAY[tint '1@2001-01-01 08:00:00', '2@2001-01-01 08:05:00']); SELECT tintSeq(ARRAY[tint '1@2001-01-01 08:00:00', '2@2001-01-01 08:05:00'], 'linear'); -- ERROR: The temporal type cannot have linear interpolation SELECT tfloatSeq(ARRAY[tfloat '1.0@2001-01-01 08:00:00', '2.0@2001-01-01 08:05:00'], 'step', false, true); SELECT ttextSeq(ARRAY[ttext 'AAA@2001-01-01 08:00:00', 'BBB@2001-01-01 08:05:00']); SELECT tgeompointSeq(ARRAY[tgeompoint 'Point(0 0)@2001-01-01 08:00:00', 'Point(0 1)@2001-01-01 08:05:00', 'Point(1 1)@2001-01-01 08:10:00'], 'discrete'); SELECT tgeogpointSeq(ARRAY[tgeogpoint 'Point(1 1)@2001-01-01 08:00:00', 'Point(2 2)@2001-01-01 08:05:00']);
Constructors for temporal types of sequence set subtype
ttypeSeqSet(ttypeContSeq[]) → ttypeSeqSet
ttypeSeqSetGaps(ttypeInst[],maxt=NULL,maxdist=NULL,interp='linear') → ttypeSeqSet
A first set of contructors have a single argument, which is an array of values of the corresponding sequence values. The interpolation of the resulting temporal value depends on the interpolation of the composing sequences. An error is raised if the sequences composing the array have different interpolation.
SELECT tboolSeqSet(ARRAY[tbool '[false@2001-01-01 08:00:00, false@2001-01-01 08:05:00)', '[true@2001-01-01 08:05:00]','(false@2001-01-01 08:05:00, false@2001-01-01 08:10:00)']); SELECT tintSeqSet(ARRAY[tint '[1@2001-01-01 08:00:00, 2@2001-01-01 08:05:00, 2@2001-01-01 08:10:00, 2@2001-01-01 08:15:00)']); SELECT tfloatSeqSet(ARRAY[tfloat '[1.0@2001-01-01 08:00:00, 2.0@2001-01-01 08:05:00, 2.0@2001-01-01 08:10:00]', '[2.0@2001-01-01 08:15:00, 3.0@2001-01-01 08:20:00)']); SELECT tfloatSeqSet(ARRAY[tfloat 'Interp=Step;[1.0@2001-01-01 08:00:00, 2.0@2001-01-01 08:05:00, 2.0@2001-01-01 08:10:00]', 'Interp=Step;[3.0@2001-01-01 08:15:00, 3.0@2001-01-01 08:20:00)']); SELECT ttextSeqSet(ARRAY[ttext '[AAA@2001-01-01 08:00:00, AAA@2001-01-01 08:05:00)', '[BBB@2001-01-01 08:10:00, BBB@2001-01-01 08:15:00)']); SELECT tgeompointSeqSet(ARRAY[tgeompoint '[Point(0 0)@2001-01-01 08:00:00, Point(0 1)@2001-01-01 08:05:00, Point(0 1)@2001-01-01 08:10:00)', '[Point(0 1)@2001-01-01 08:15:00, Point(0 0)@2001-01-01 08:20:00)']); SELECT tgeogpointSeqSet(ARRAY[tgeogpoint 'Interp=Step;[Point(0 0)@2001-01-01 08:00:00, Point(0 0)@2001-01-01 08:05:00)', 'Interp=Step;[Point(1 1)@2001-01-01 08:10:00, Point(1 1)@2001-01-01 08:15:00)']); SELECT tfloatSeqSet(ARRAY[tfloat 'Interp=Step;[1.0@2001-01-01 08:00:00, 2.0@2001-01-01 08:05:00, 2.0@2001-01-01 08:10:00]', '[3.0@2001-01-01 08:15:00, 3.0@2001-01-01 08:20:00)']); -- ERROR: The temporal values must have the same interpolation
Another set of constructors for sequence set values have as first argument an array of the corresponding instant values, and two optional arguments stating a maximum time interval and a maximum distance such that a gap is introduced between sequences of the result whenever two consecutive input instants have a time gap or a distance greater than these values. For temporal points, the distance is specified in units of the coordinate system. When none of the gap arguments are given, the resulting value will be a singleton sequence set. In addition, when the base type is continuous, an additional last argument states whether the interpolation is step or linear. It this argument is not specified it is assumed to be linear by default.
The parameters of the function depend on the temporal type. For example, the interpolation parameter is not allowed for temporal types with discrete subtype such as tint
. Similarly, the parameter maxdist
is not allowed for scalar types such as ttext
that do not have a standard distance function.
SELECT tintSeqSetGaps(ARRAY[tint '1@2001-01-01', '3@2001-01-02', '4@2001-01-03', '5@2001-01-05']); -- {[1@2001-01-01, 3@2001-01-02, 4@2001-01-03, 5@2001-01-05]} SELECT tintSeqSetGaps(ARRAY[tint '1@2001-01-01', '3@2001-01-02', '4@2001-01-03', '5@2001-01-05'], '1 day', 1); -- {[1@2001-01-01], [3@2001-01-02, 4@2001-01-03], [5@2001-01-05]} SELECT ttextSeqSetGaps(ARRAY[ttext 'AA@2001-01-01', 'BB@2001-01-02', 'AA@2001-01-03', 'CC@2001-01-05'], '1 day'); -- {["AA"@2001-01-01, "BB"@2001-01-02, "AA"@2001-01-03], ["CC"@2001-01-05]} SELECT asText(tgeompointSeqSetGaps(ARRAY[tgeompoint 'Point(1 1)@2001-01-01', 'Point(2 2)@2001-01-02', 'Point(3 2)@2001-01-03', 'Point(3 2)@2001-01-05'], '1 day', 1, 'step')); /* Interp=Step;{[POINT(1 1)@2001-01-01], [POINT(2 2)@2001-01-02, POINT(3 2)@2001-01-03], [POINT(3 2)@2001-01-05]} */