Temporal addition
{number,tnumber} + {number,tnumber} → tnumber
SELECT tint '[2@2001-01-01, 2@2001-01-04)' + 1; -- [3@2001-01-01, 3@2001-01-04) SELECT tfloat '[2@2001-01-01, 2@2001-01-04)' + tfloat '[1@2001-01-01, 4@2001-01-04)'; -- [3@2001-01-01, 6@2001-01-04) SELECT tfloat '[1@2001-01-01, 4@2001-01-04)' + tfloat '{[1@2001-01-01, 2@2001-01-02), [1@2001-01-02, 2@2001-01-04)}'; -- {[2@2001-01-01, 4@2001-01-04), [3@2001-01-02, 6@2001-01-04)}
Temporal subtraction
{number,tnumber} - {number,tnumber} → tnumber
SELECT tint '[1@2001-01-01, 1@2001-01-04)' - tint '[2@2001-01-03, 2@2001-01-05)'; -- [-1@2001-01-03, -1@2001-01-04) SELECT tfloat '[3@2001-01-01, 6@2001-01-04)' - tfloat '[2@2001-01-01, 2@2001-01-04)'; -- [1@2001-01-01, 4@2001-01-04)
Temporal multiplication
{number,tnumber} * {number,tnumber} → tnumber
SELECT tint '[1@2001-01-01, 4@2001-01-04]' * 2; -- [2@2001-01-01, 8@2001-01-04] SELECT tfloat '[1@2001-01-01, 4@2001-01-04)' * tfloat '[2@2001-01-01, 2@2001-01-04)'; -- [2@2001-01-01, 8@2001-01-04) SELECT tfloat '[1@2001-01-01, 3@2001-01-03)' * '[3@2001-01-01, 1@2001-01-03)' -- {[3@2001-01-01, 4@2001-01-02, 3@2001-01-03)}
Temporal division
{number,tnumber} / {number,tnumber} → tnumber
The function will raise an error if the denominator will ever be equal to zero during the common timespan of the arguments.
SELECT 2 / tfloat '[1@2001-01-01, 3@2001-01-04)'; -- [2@2001-01-01, 0.666666666666667@2001-01-04) SELECT tfloat '[1@2001-01-01, 5@2001-01-05)' / tfloat '[5@2001-01-01, 1@2001-01-05)'; -- {[0.2@2001-01-01, 1@2001-01-03,2001-01-03, 5@2001-01-03,2001-01-05)} SELECT 2 / tfloat '[-1@2001-01-01, 1@2001-01-02]'; -- ERROR: Division by zero SELECT tfloat '[-1@2001-01-04, 1@2001-01-05]' / tfloat '[-1@2001-01-01, 1@2001-01-05]'; -- [-2@2001-01-04, 1@2001-01-05]
Return the absolute value of the temporal number
abs(tnumber) → tnumber
SELECT abs(tfloat '[1@2001-01-01, -1@2001-01-03, 1@2001-01-05]'); -- [1@2001-01-01, 0@2001-01-02, 1@2001-01-03, 0@2001-01-04, 1@2001-01-05] SELECT abs(tint '[1@2001-01-01, -1@2001-01-03, 1@2001-01-05]'); -- [1@2001-01-01, 1@2001-01-05]
Return the value difference between consecutive instants of the temporal number
deltaValue(tnumber) → tnumber
SELECT deltaValue(tint '[1@2001-01-01, 2@2001-01-02, 1@2001-01-03]'); -- [1@2001-01-01, -1@2001-01-02, -1@2001-01-03) SELECT deltaValue(tfloat '{[1.5@2001-01-01, 2@2001-01-02, 1@2001-01-03], [2@2001-01-04, 2@2001-01-05]}'); /* Interp=Step;{[0.5@2001-01-01, -1@2001-01-02, -1@2001-01-03), [0@2001-01-04, 0@2001-01-05)} */
Round up or down to the neareast integer
floor(tfloat) → tfloat
ceil(tfloat) → tfloat
SELECT floor(tfloat '[0.5@2001-01-01, 1.5@2001-01-02]'); -- [0@2001-01-01, 1@2001-01-02] SELECT ceil(tfloat '[0.5@2001-01-01, 0.6@2001-01-02, 0.7@2001-01-03]'); -- [1@2001-01-01, 1@2001-01-03]
Round to a number of decimal places
round(tfloat,integer=0) → tfloat
SELECT round(tfloat '[0.785398163397448@2001-01-01, 2.356194490192345@2001-01-02]', 2); -- [0.79@2001-01-01, 2.36@2001-01-02]
Convert to degrees or radians
degrees({float,tfloat},normalize=false) → tfloat
radians(tfloat) → tfloat
The additional parameter in the degrees
function can be used to normalize the values between 0 and 360 degrees.
SELECT degrees(pi() * 5); -- 900 SELECT degrees(pi() * 5, true); -- 180 SELECT round(degrees(tfloat '[0.785398163397448@2001-01-01, 2.356194490192345@2001-01-02]')); -- [45@2001-01-01, 135@2001-01-02] SELECT radians(tfloat '[45@2001-01-01, 135@2001-01-02]'); -- [0.785398163397448@2001-01-01, 2.356194490192345@2001-01-02]
Return the derivative over time of the temporal float in units per second
derivative(tfloat) → tfloat
The temporal float must have linear interpolation
SELECT derivative(tfloat '{[0@2001-01-01, 10@2001-01-02, 5@2001-01-03], [1@2001-01-04, 0@2001-01-05]}') * 3600 * 24; /* Interp=Step;{[-10@2001-01-01, 5@2001-01-02, 5@2001-01-03], [1@2001-01-04, 1@2001-01-05]} */ SELECT derivative(tfloat 'Interp=Step;[0@2001-01-01, 10@2001-01-02, 5@2001-01-03]'); -- ERROR: The temporal value must have linear interpolation