When I run the SQL Query:
select generate_series(0,g)
from ( select date(date1) - date(date2) as g from mytable ;
It returns an error:
You can use a window function to achieve a similar result. This requires an existing table (like stv_blocklist
) to seed off that has at least the number of rows you need but not too many which might slow things down.
with days as (
select (dateadd(day, -row_number() over (order by true), sysdate::date)) as day
from [other_existing_table] limit 30
)
select day from days order by 1 asc
You can use this method to get other time ranges as well for bucketing purposes. This version generates all the minutes for the previous day so you could do a left join against it and bucket your data.
with buckets AS (
select (dateadd(minute, -row_number() over (order by true), sysdate::date)) as minute
from [other_table] limit 1440
)
select minute from buckets order by 1 asc
I may have first seen this here.