Return the memory size in bytes
memSize(ttype) → integer
SELECT memSize(tint '{1@2001-01-01, 2@2001-01-02, 3@2001-01-03}');
-- 176
Return the temporal type
tempSubtype(ttype) → {'Instant','Sequence','SequenceSet'}
SELECT tempSubtype(tint '[1@2001-01-01, 2@2001-01-02, 3@2001-01-03]'); -- Sequence
Return the interpolation
interp(ttype) → {'None', 'Discrete','Step','Linear'}
SELECT interp(tbool 'true@2001-01-01');
-- None
SELECT interp(tfloat '{1@2001-01-01, 2@2001-01-02, 3@2001-01-03}');
-- Discrete
SELECT interp(tint '[1@2001-01-01, 2@2001-01-02, 3@2001-01-03]');
-- Step
SELECT interp(tfloat '[1@2001-01-01, 2@2001-01-02, 3@2001-01-03]');
-- Linear
SELECT interp(tfloat 'Interp=Step;[1@2001-01-01, 2@2001-01-02, 3@2001-01-03]');
-- Step
SELECT interp(tgeompoint 'Interp=Step;[Point(1 1)@2001-01-01,
Point(2 2)@2001-01-02, Point(3 3)@2001-01-03]');
-- Step
Return the value or the timestamp of an instant
getValue(ttypeInst) → base
getTimestamp(ttypeInst) → timestamptz
SELECT getValue(tint '1@2001-01-01'); -- 1 SELECT getTimestamp(tfloat '1@2001-01-01'); -- 2001-01-01
Return the values or the time on which a temporal value is defined
getValues(talpha) → {bool[],spanset,textset}
getTime(ttype) → tstzspanset
SELECT getValues(tbool '[false@2001-01-01, true@2001-01-02, false@2001-01-03]');
-- {f,t}
SELECT getValues(tint '[1@2001-01-01, 3@2001-01-02, 1@2001-01-03]');
-- {[1, 2), [3, 4)}
SELECT getValues(tint '{[1@2001-01-01, 2@2001-01-02, 1@2001-01-03],
[4@2001-01-04, 4@2001-01-05]}');
-- {[1, 3), [4, 5)}
SELECT getValues(tfloat '{1@2001-01-01, 2@2001-01-02, 1@2001-01-03}');
-- {[1, 1], [2, 2]}
SELECT getValues(tfloat 'Interp=Step;{[1@2001-01-01, 2@2001-01-02, 1@2001-01-03],
[3@2001-01-04, 3@2001-01-05]}');
-- {[1, 1], [2, 2], [3, 3]}
SELECT getValues(tfloat '[1@2001-01-01, 2@2001-01-02, 1@2001-01-03]');
-- {[1, 2]}
SELECT getValues(tfloat '{[1@2001-01-01, 2@2001-01-02, 1@2001-01-03],
[3@2001-01-04, 3@2001-01-05]}');
-- {[1, 2], [3, 3]}
SELECT getTime(ttext 'walking@2001-01-01');
-- {[2001-01-01, 2001-01-01]}
SELECT getTime(tfloat '{1@2001-01-01, 2@2001-01-02, 1@2001-01-03}');
-- {[2001-01-01, 2001-01-01], [2001-01-02, 2001-01-02], [2001-01-03, 2001-01-03]}
SELECT getTime(tint '[1@2001-01-01, 1@2001-01-15)');
-- {[2001-01-01, 2001-01-15)}
SELECT getTime(tfloat '{[1@2001-01-01, 1@2001-01-10), [12@2001-01-12, 12@2001-01-15]}');
-- {[2001-01-01, 2001-01-10), [2001-01-12, 2001-01-15]}
Return the value span and the time span ignoring the potential gaps
valueSpan(tnumber) → numspan
timeSpan(ttype) → tstzspan
SELECT valueSpan(tint '{[1@2001-01-01, 1@2001-01-03), [4@2001-01-03, 6@2001-01-05]}');
-- [1,7)
SELECT valueSpan(tfloat '{1@2001-01-01, 2@2001-01-03, 3@2001-01-05}');
-- [1,3])
SELECT timeSpan(tint '{1@2001-01-01, 2@2001-01-03, 3@2001-01-05}');
-- [2001-01-01, 2001-01-05]
SELECT timeSpan(tfloat '{[1@2001-01-01, 1@2001-01-02), [2@2001-01-03, 3@2001-01-04)}');
-- [2001-01-01, 2001-01-04)
Return the values of the temporal number or point as a set
valueSet(tnumber, tpoint) → {numset,geoset}
SELECT valueSet(tint '[1@2001-01-01, 2@2001-01-03]');
-- {1, 2}
SELECT valueSet(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 4@2001-01-05)}');
-- {1, 2, 3, 4}
SELECT asText(valueSet(tgeompoint '{[Point(0 0)@2001-01-01, Point(0 1)@2001-01-02),
[Point(0 1)@2001-01-03, Point(1 1)@2001-01-04)}'));
-- {"POINT(0 0)", "POINT(1 1)", "POINT(0 1)"}
Return the start, end, or n-th value
startValue(ttype) → base
endValue(ttype) → base
valueN(ttype,int) → base
The functions do not take into account whether the bounds are inclusive or not.
SELECT startValue(tfloat '(1@2001-01-01, 2@2001-01-03)');
-- 1
SELECT endValue(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 5@2001-01-05)}');
-- 5
SELECT valueN(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 5@2001-01-05)}', 3);
-- 3
Return the minimum or maximum value
minValue(torder) → base
maxValue(torder) → base
The functions do not take into account whether the bounds are inclusive or not.
SELECT minValue(tfloat '{1@2001-01-01, 2@2001-01-03, 3@2001-01-05}');
-- 1
SELECT maxValue(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 5@2001-01-05)}');
-- 5
Return the instant with the minimum or maximum value
minInstant(torder) → base
maxInstant(torder) → base
The function does not take into account whether the bounds are inclusive or not. If several instants have the minimum value, the first one is returned.
SELECT minInstant(tfloat '{1@2001-01-01, 2@2001-01-03, 3@2001-01-05}');
-- 1@2001-01-01
SELECT maxInstant(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 5@2001-01-05)}');
-- 5@2001-01-05
Return the value at a timestamp
valueAtTimestamp(ttype,timestamptz) → base
SELECT valueAtTimestamp(tfloat '[1@2001-01-01, 4@2001-01-04)', '2001-01-02'); -- 2
Return the time interval
duration(ttype,boundspan=false) → interval
An additional parameter can be set to true to compute the duration of the bounding time span, thus ignoring the potential time gaps
SELECT duration(tfloat '{1@2001-01-01, 2@2001-01-03, 2@2001-01-05}');
-- 00:00:00
SELECT duration(tfloat '{1@2001-01-01, 2@2001-01-03, 2@2001-01-05}', true);
-- 4 days
SELECT duration(tfloat '[1@2001-01-01, 2@2001-01-03, 2@2001-01-05)');
-- 4 days
SELECT duration(tfloat '{[1@2001-01-01, 2@2001-01-03), [2@2001-01-04, 2@2001-01-05)}');
-- 3 days
SELECT duration(tfloat '{[1@2001-01-01, 2@2001-01-03), [2@2001-01-04, 2@2001-01-05)}',
true);
-- 4 days
Is the start/end instant inclusive?
lowerInc(ttype) → bool
upperInc(ttype) → bool
SELECT lowerInc(tint '[1@2001-01-01, 2@2001-01-02)');
-- true
SELECT upperInc(tfloat '{[1@2001-01-01, 2@2001-01-02), (2@2001-01-02, 3@2001-01-03)}');
-- false
Return the number of different instants
numInstants(ttype) → integer
SELECT numInstants(tfloat '{[1@2001-01-01, 2@2001-01-02), (2@2001-01-02, 3@2001-01-03)}');
-- 3
Return the start, end, or n-th instant
startInstant(ttype) → ttypeInst
endInstant(ttype) → ttypeInst
instantN(ttype,integer) → ttypeInst
The functions do not take into account whether the bounds are inclusive or not.
SELECT startInstant(tfloat '{[1@2001-01-01, 2@2001-01-02),
(2@2001-01-02, 3@2001-01-03)}');
-- 1@2001-01-01
SELECT endInstant(tfloat '{[1@2001-01-01, 2@2001-01-02), (2@2001-01-02, 3@2001-01-03)}');
-- 3@2001-01-03
SELECT instantN(tfloat '{[1@2001-01-01, 2@2001-01-02), (2@2001-01-02, 3@2001-01-03)}', 3);
-- 3@2001-01-03
Return the different instants
instants(ttype) → ttypeInst[]
SELECT instants(tfloat '{[1@2001-01-01, 2@2001-01-02), (2@2001-01-02, 3@2001-01-03)}');
-- {"1@2001-01-01","2@2001-01-02","3@2001-01-03"}
Return the number of different timestamps
numTimestamps(ttype) → integer
SELECT numTimestamps(tfloat '{[1@2001-01-01, 2@2001-01-03),
[3@2001-01-03, 5@2001-01-05)}');
-- 3
Return the start, end, or n-th timestamp
startTimestamp(ttype) → timestamptz
endTimestamp(ttype) → timestamptz
timestampN(ttype,integer) → timestamptz
The functions do not take into account whether the bounds are inclusive or not.
SELECT startTimestamp(tfloat '[1@2001-01-01, 2@2001-01-03)');
-- 2001-01-01
SELECT endTimestamp(tfloat '{[1@2001-01-01, 2@2001-01-03),
[3@2001-01-03, 5@2001-01-05)}');
-- 2001-01-05
SELECT timestampN(tfloat '{[1@2001-01-01, 2@2001-01-03),
[3@2001-01-03, 5@2001-01-05)}', 3);
-- 2001-01-05
Return the different timestamps
timestamps(ttype) → timestamptz[]
SELECT timestamps(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 5@2001-01-05)}');
-- {"2001-01-01", "2001-01-03", "2001-01-05"}
Return the number of sequences
numSequences({ttypeContSeq,ttypeSeqSet}) → integer
SELECT numSequences(tfloat '{[1@2001-01-01, 2@2001-01-03),
[3@2001-01-03, 5@2001-01-05)}');
-- 2
Return the start, end, or n-th sequence
startSequence({ttypeContSeq,ttypeSeqSet}) → ttypeContSeq
endSequence({ttypeContSeq,ttypeSeqSet}) → ttypeContSeq
sequenceN({ttypeContSeq,ttypeSeqSet},integer) → ttypeContSeq
SELECT startSequence(tfloat '{[1@2001-01-01, 2@2001-01-03),
[3@2001-01-03, 5@2001-01-05)}');
-- [1@2001-01-01, 2@2001-01-03)
SELECT endSequence(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 5@2001-01-05)}');
-- [3@2001-01-03, 5@2001-01-05)
SELECT sequenceN(tfloat '{[1@2001-01-01, 2@2001-01-03),
[3@2001-01-03, 5@2001-01-05)}', 2);
-- [3@2001-01-03, 5@2001-01-05)
Return the sequences
sequences({ttypeContSeq,ttypeSeqSet}) → ttypeContSeq[]
SELECT sequences(tfloat '{[1@2001-01-01, 2@2001-01-03), [3@2001-01-03, 5@2001-01-05)}');
-- {"[1@2001-01-01, 2@2001-01-03)", "[3@2001-01-03, 5@2001-01-05)"}
Return the segments
segments({ttypeContSeq,ttypeSeqSet}) → ttypeContSeq[]
SELECT segments(tint '{[1@2001-01-01, 3@2001-01-02, 2@2001-01-03],
(3@2001-01-03, 5@2001-01-05]}');
/* {"[1@2001-01-01, 1@2001-01-02)","[3@2001-01-02, 3@2001-01-03)","[2@2001-01-03]",
"(3@2001-01-03, 3@2001-01-05)","[5@2001-01-05]"} */
SELECT segments(tfloat '{[1@2001-01-01, 3@2001-01-02, 2@2001-01-03],
(3@2001-01-03, 5@2001-01-05]}');
/* {"[1@2001-01-01, 3@2001-01-02)","[3@2001-01-02, 2@2001-01-03]",
"(3@2001-01-03, 5@2001-01-05]"} */
Return the area under the curve
integral(tnumber) → float
SELECT integral(tint '[1@2001-01-01,2@2001-01-02]') / (24 * 3600 * 1e6); -- 1 SELECT integral(tfloat '[1@2001-01-01,2@2001-01-02]') / (24 * 3600 * 1e6); -- 1.5
Return the time-weighted average
twAvg(tnumber) → float
SELECT twAvg(tfloat '{[1@2001-01-01, 2@2001-01-03), [2@2001-01-04, 2@2001-01-06)}');
-- 1.75