A temporal value can be converted into a compatible type using the notation CAST(ttype1 AS ttype2)
or ttype1::ttype2
.
Convert a temporal number to a span or to a bounding box
tnumber::{span,tbox}
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::intspan; -- [1, 3) SELECT tfloat '(1@2001-01-01, 3@2001-01-03, 2@2001-01-05]'::floatspan; -- (1, 3] SELECT tfloat 'Interp=Step;(1@2001-01-01, 3@2001-01-03, 2@2001-01-05]'::floatspan; -- [1, 3]
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::tbox; -- TBOXINT XT((1,2),[2001-01-01,2001-01-03]) SELECT tfloat '(1@2001-01-01, 3@2001-01-03, 2@2001-01-05]'::tbox; -- TBOXFLOAT XT((1,3),[2001-01-01,2001-01-05])
Convert between a temporal Boolean and a temporal integer
tbool::tint
SELECT tbool '[true@2001-01-01, false@2001-01-03]'::tint; -- [1@2001-01-01, 0@2001-01-03]
Convert between a temporal integer and a temporal float
tint::tfloat
tfloat::tint
SELECT tint '[1@2001-01-01, 2@2001-01-03]'::tfloat; -- Interp=Step;[1@2001-01-01, 2@2001-01-03] SELECT tint '[1@2001-01-01, 2@2001-01-03, 3@2001-01-05]'::tfloat; -- Interp=Step;[1@2001-01-01, 2@2001-01-03, 3@2001-01-05] SELECT tfloat 'Interp=Step;[1.5@2001-01-01, 2.5@2001-01-03]'::tint; -- [1@2001-01-01, 2@2001-01-03] SELECT tfloat '[1.5@2001-01-01, 2.5@2001-01-03]'::tint; -- ERROR: Cannot cast temporal float with linear interpolation to temporal integer