Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
Generate an array of time-based values, from start to stop with a given step size.
Syntax
array_generate_series(<start>, <stop>, <step>)
Arguments
Required
<start>: The start value of the series. Can be of typeDATE,TIMESTAMP, orTIMESTAMP WITH TIME ZONE.<stop>: The end value of the series. Must be of the same type as<start>.<step>: The step size as anINTERVAL. Unlike the numerical version ofARRAY_GENERATE_SERIES, the step size is always required for time-based series.
Returns
Returns an ARRAY containing the generated series of values.
Considerations
This function is equivalent to the generate_series (Time-based) function, with the only difference that it returns an array instead of a set of rows.
Read the documentation on generate_series (Time-based) for more details.
All considerations also apply to array_generate_series with the following differences:
Examples
Basic Usage with Dates
Generate an array of months between two dates.
SELECT array_generate_series('2017-01-01'::date, '2017-03-01'::date, '1 month'::interval);
returns ["2017-01-01","2017-02-01","2017-03-01"]
Usage with Timestamps
SELECT array_generate_series('2017-01-01 01:02:03'::timestamp, '2017-03-01 01:02:03'::timestamp, '1 month'::interval);
returns ["2017-01-01 01:02:03","2017-02-01 01:02:03","2017-03-01 01:02:03"]
Additional Examples
Take a look at the generate_series examples for additional examples.
They also apply to array_generate_series.
Related Documentation
- Array Functions
ARRAY_GENERATE_SERIES(Numerical) - the numerical version of this functiongenerate_series(Time-based) - the set-returning version of this function