Return the memory size in bytes
memSize({set,spanset}) → integer
SELECT memSize(tstzset '{2001-01-01, 2001-01-02, 2001-01-03}'); -- 48 SELECT memSize(tstzspanset '{[2001-01-01, 2001-01-02], [2001-01-03, 2001-01-04], [2001-01-05, 2001-01-06]}'); -- 112
Return the lower or upper bound
lower(spans) → base
upper(spans) → base
SELECT lower(tstzspan '[2001-01-01, 2001-01-05)'); -- 2001-01-01 SELECT lower(intspanset '{[1,2],[4,5]}'); -- 1
SELECT lower(tstzspan '[2001-01-01, 2001-01-05)'); -- 2001-01-01 SELECT upper(intspanset '{[1,2],[4,5]}'); -- 6 SELECT lower(tstzspan '[2001-01-01, 2001-01-05)'); -- 2001-01-01 SELECT lower(intspanset '{[1,2],[4,5]}'); -- 1
SELECT upper(floatspan '[20.5, 25.3)'); -- 25.3 SELECT upper(tstzspan '[2001-01-01, 2001-01-05)'); -- 2001-01-05
Is the lower or upper bound inclusive?
lowerInc(spans) → boolean
upperInc(spans) → boolean
SELECT lowerInc(datespan '[2001-01-01, 2001-01-05)'); -- true SELECT lowerInc(intspanset '{[1,2],[4,5]}'); -- true
SELECT upper(floatspan '[20.5, 25.3]'); -- true SELECT upperInc(tstzspan '[2001-01-01, 2001-01-05)'); -- false
Return the width of the span as a float
width(numspan) → float
width(numspanset,boundspan=false) → float
An additional parameter can be set to true to compute the width of the bounding span, thus ignoring the potential value gaps
SELECT width(floatspan '[1, 3)'); -- 2 SELECT width(intspanset '{[1,3),[5,7)}'); -- 4 SELECT width(intspanset '{[1,3),[5,7)}', true); -- 6
Return the duration
duration({datespan,tstzspan}) → interval
duration({datespanset,tstzspanset},boundspan bool=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(datespan '[2001-01-01, 2001-01-03)'); -- 2 days SELECT duration(tstzspanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-05)}'); -- 3 days SELECT duration(tstzspanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-05)}', true); -- 4 days
Return the number of values
numValues(set) → integer
SELECT numValues(intset '{1,3,5,7}'); -- 4
Return the start, end, or n-th value
startValue(set) → base
endValue(set) → base
valueN(set,integer) → base
SELECT startValue(intset '{1,3,5,7}'); -- 1 SELECT endValue(dateset '{2001-01-01, 2001-01-03, 2001-01-05, 2001-01-07}'); -- 2001-01-07 SELECT valueN(floatset '{1,3,5,7}',2); -- 3
Return the values
getValues(set) → base[]
SELECT getValues(tstzset '{2001-01-01, 2001-01-03, 2001-01-05, 2001-01-07}'); -- {"2001-01-01","2001-01-03","2001-01-05","2001-01-07"}
Return the number of spans
numSpans(spanset) → integer
SELECT numSpans(intspanset '{[1,3),[4,5),[6,7)}'); -- 3 SELECT numSpans(datespanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-05), [2001-01-06, 2001-01-07)}'); -- 3
Return the start, end, or n-th span
startSpan(spanset) → span
endSpan(spanset) → span
spanN(spanset,integer) → span
SELECT startSpan(intspanset '{[1,3),[4,5),[6,7)}'); -- [1,3) SELECT startSpan(datespanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-05), [2001-01-06, 2001-01-07)}'); -- [2001-01-01,2001-01-03)
SELECT endSpan(floatspanset '{[1,3),[4,4],[6,7)}'); -- [6,7) SELECT endSpan(tstzspanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-04], [2001-01-05, 2001-01-06)}'); -- [2001-01-05,2001-01-06)
SELECT spanN(floatspanset '{[1,3),[4,4],[6,7)}',2); -- [4,4] SELECT spanN(tstzspanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-04], [2001-01-05, 2001-01-06)}', 2); -- [2001-01-04,2001-01-04]
Return the spans
spans(spanset) → span[]
SELECT spans(floatspanset '{[1,3),[4,4],[6,7)}'); -- {"[1,3)","[4,4]","[6,7)"} SELECT spans(tstzspanset '{[2001-01-01, 2001-01-03), [2001-01-04, 2001-01-04], [2001-01-05, 2001-01-06)}'); -- {"[2001-01-01,2001-01-03)", "[2001-01-04,2001-01-04]", "[2001-01-05,2001-01-06)"}
Return the number of different dates or timestamps
numDates(datespanset) → integer
numTimestamps(tstzspanset) → integer
SELECT numDates(datespanset '{[2001-01-01, 2001-01-02), [2001-01-03, 2001-01-04)}'); -- 4 SELECT numTimestamps(tstzspanset '{[2001-01-01, 2001-01-03), (2001-01-03, 2001-01-05)}'); -- 3
Return the start, end, or n-th date or timestamp
startDate(datespanset) → date
endDate(datespanset) → date
dateN(datespanset,integer) → date
startTimestamp(tstzspanset) → timestamptz
endTimestamp(tstzspanset) → timestamptz
timestampN(tstzspanset,integer) → timestamptz
The functions do not take into account whether the bounds are inclusive or not.
SELECT startDate(datespanset '{[2001-01-01, 2001-01-02), [2001-01-03, 2001-01-04)}'); -- 2001-01-01 SELECT endTimestamp(tstzspanset '{[2001-01-01, 2001-01-03), (2001-01-03, 2001-01-05)}'); -- 2001-01-05 SELECT timestampN(tstzspanset '{[2001-01-01, 2001-01-03), (2001-01-03, 2001-01-05)}', 3); -- 2001-01-05
Return the set of distinct dates or timestamps
dates(datespanset) → dateset
timestamps(tstzspanset) → tstzset
The function does not take into account whether the bounds are inclusive or not.
SELECT dates(datespanset '{[2001-01-01, 2001-01-02), [2001-01-03, 2001-01-04)}'); -- {2001-01-01, 2001-01-02, 2001-01-03, 2001-01-04} SELECT timestamps(tstzspanset '{[2001-01-01, 2001-01-03), (2001-01-03, 2001-01-05)}'); -- {"2001-01-01 00:00:00", "2001-01-03 00:00:00", "2001-01-05 00:00:00"}