Each temporal type has constructor functions with the same name as the type and with a suffix for the duration, where the suffix ‘inst
’, ‘i
’, ‘seq
’, and ‘s
’ correspond, respectively, to the durations instant, instant set, sequence, and sequence set. Examples are tintseq
or tgeompoints
. Using the constructor function is frequently more convenient than writing a literal constant.
A first set of constructor functions have two arguments, a base type and a time type, where the latter is a timestamptz
, a timestampset
, a period
, or a periodset
value for constructing, respectively, a temporal instant, instant set, sequence, or sequence set value. The constructors for temporal sequence or sequence set values with continuous base type have in addition an optional third argument which is a Boolean for stating whether the resulting temporal value has linear interpolation or not. By default this argument is true if it is not specified.
Another set of constructor functions for temporal instant set values have a single argument, which is an array of values of the corresponding instant values.
Another set of constructor functions for temporal sequence values have one argument for the array of values of the corresponding instant duration and two optional Boolean arguments stating, respectively, whether the left and right bounds are inclusive or exclusive. It the these arguments are not specified they are assumed to be true by default. In addition, the constructor functions for temporal sequence values with continuous base type have an additional Boolean argument stating whether the interpolation is linear or not. It this argument is not specified it is assumed to be true by default.
Another set of constructor functions for temporal sequence set values have a single argument, which is an array of values of the corresponding sequence values. For temporal sequence values with continuous base type, 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.
We give next the constructor functions for the various durations.
Constructor for temporal types of instant duration
ttypeinst(base, timestamptz): ttypeinst
SELECT tboolinst(true, '2001-01-01'); SELECT tfloatinst(1.5, '2001-01-01'); SELECT tgeompointinst('Point(0 0)', '2001-01-01');
Constructor for temporal types of instant set duration
ttypei(base, timestampset): ttypei
ttypei(ttypeinst[]]): ttypei
SELECT tinti(2, '{2001-01-01, 2001-01-02, 2001-01-03}'); SELECT tgeompointi('Point(0 0)', '{2001-01-01, 2001-01-02}'); SELECT tbooli(ARRAY[tbool 'true@2001-01-01 08:00:00', 'false@2001-01-01 08:05:00']); SELECT tinti(ARRAY[tint '1@2001-01-01 08:00:00', '2@2001-01-01 08:05:00']); SELECT tfloati(ARRAY[tfloat '1.0@2001-01-01 08:00:00', '2.0@2001-01-01 08:05:00']); SELECT ttexti(ARRAY[ttext 'AAA@2001-01-01 08:00:00', 'BBB@2001-01-01 08:05:00']); SELECT tgeompointi(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']); SELECT tgeogpointi(ARRAY[tgeogpoint 'Point(1 1)@2001-01-01 08:00:00', 'Point(2 2)@2001-01-01 08:05:00']);
Constructor for temporal types of sequence duration
tdiscseq(base, period): tdiscseq
tdiscseq(ttypeinst[], left_inc = true, right_inc = true}): tdiscseq
tcontseq(base, period, linear = true): tcontseq
tcontseq(ttypeinst[], left_inc = true, right_inc = true, linear = true}): tcontseq
SELECT tfloatseq(1.5, '[2001-01-01, 2001-01-02]'); SELECT tfloatseq(2.0, '[2001-01-01, 2001-01-02]', false); SELECT tboolseq(ARRAY[tbool 'true@2001-01-01 08:00:00', 'true@2001-01-03 08:05:00'], true, true); SELECT tintseq(ARRAY[tintinst(2,'2001-01-01 08:00:00'), tintinst(2,'2001-01-01 08:10:00')], true, false); SELECT tfloatseq(ARRAY[tfloat '2.0@2001-01-01 08:00:00', '3@2001-01-03 08:05:00', '1@2001-01-03 08:10:00'], true, false); SELECT tfloatseq(ARRAY[tfloat '2.0@2001-01-01 08:00:00', '3@2001-01-03 08:05:00', '1@2001-01-03 08:10:00'], true, true, false); SELECT ttextseq(ARRAY[ttextinst('AAA', '2001-01-01 08:00:00'), ttextinst('BBB', '2001-01-03 08:05:00'), ttextinst('BBB', '2001-01-03 08:10:00')]); SELECT tgeompointseq(ARRAY[tgeompoint 'Point(0 0)@2001-01-01 08:00:00', 'Point(0 1)@2001-01-03 08:05:00', 'Point(1 1)@2001-01-03 08:10:00']); SELECT tgeogpointseq(ARRAY[tgeogpoint 'Point(0 0)@2001-01-01 08:00:00', 'Point(0 0)@2001-01-03 08:05:00'], true, true, false);
Constructors for temporal types of sequence set duration
tdiscs(base, periodset): tdiscs
tconts(base, periodset, linear = true): tconts
ttypes(ttypeseq[]): ttypes
SELECT ttexts('AAA', '{[2001-01-01, 2001-01-02], [2001-01-03, 2001-01-04]}'); SELECT tgeogpointseq('Point(1 1)', '[2001-01-01, 2001-01-02]', false); SELECT tbools(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 tints(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 tfloats(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 tfloats(ARRAY[tfloat 'Interp=Stepwise;[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=Stepwise;[3.0@2001-01-01 08:15:00, 3.0@2001-01-01 08:20:00)']); SELECT ttexts(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 tgeompoints(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 tgeogpoints(ARRAY[tgeogpoint 'Interp=Stepwise;[Point(0 0)@2001-01-01 08:00:00, Point(0 0)@2001-01-01 08:05:00)', 'Interp=Stepwise;[Point(1 1)@2001-01-01 08:10:00, Point(1 1)@2001-01-01 08:15:00)']); SELECT tfloats(ARRAY[tfloat 'Interp=Stepwise;[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: Input sequences must have the same interpolation