The set and span types have associated set operators, namely union, difference, and intersection, which are represented, respectively by +
, -
, and *
. The set operators for the set and span types are given next.
Union of set or span values
{set,spans} + {set,spans} → {set,spans}
SELECT dateset '{2001-01-01, 2001-01-03, 2001-01-05}' + dateset '{2001-01-03, 2001-01-06}'; -- {2001-01-01, 2001-01-03, 2001-01-05, 2001-01-06} SELECT intspan '[1, 3)' + intspan '[3, 5)'; -- [1, 5) SELECT floatspan '[1, 3)' + floatspan '[4, 5)'; -- {[1, 3), [4, 5)} SELECT tstzspanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-05)}' + tstzspan '[2001-01-03, 2001-01-04)'; -- {[2001-01-01, 2001-01-05)}
Difference of set or span values
{set,spans} - {set,spans} → {set,spans}
SELECT intset '{1, 3, 5}' - intset '{3, 6}'; -- {1, 5} SELECT datespan '[2001-01-01, 2001-01-05)' - datespan '[2001-01-03, 2001-01-07)'; -- {[2001-01-01, 2001-01-03)} SELECT floatspan '[1, 5]' - floatspan '[3, 4]'; -- {[1, 3), (4, 5]} SELECT tstzspanset '{[2001-01-01, 2001-01-06], [2001-01-07, 2001-01-10]}' - tstzspanset '{[2001-01-02, 2001-01-03], [2001-01-04, 2001-01-05], [2001-01-08, 2001-01-09]}'; /* {[2001-01-01,2001-01-02), (2001-01-03,2001-01-04), (2001-01-05,2001-01-06], [2001-01-07,2001-01-08), (2001-01-09,2001-01-10]} */
Intersection of set or span values
{set,spans} * {set,spans} → {set,spans}
SELECT tstzset '{2001-01-01, 2001-01-03}' * tstzset '{2001-01-03, 2001-01-05}'; -- {2001-01-03} SELECT intspan '[1, 5)' * intspan '[3, 6)'; -- [3, 5) SELECT floatspanset '{[1, 5),[6, 8)}' * floatspan '[1, 6)'; -- {[1, 5)} SELECT tstzspan '[2001-01-01, 2001-01-05)' * tstzspan '[2001-01-03, 2001-01-07)'; -- [2001-01-03, 2001-01-05)