I am trying to generate a list of dates on Redshift to join it with another table with a start and end date of events so that I can have a list of event ids for each date.
This query produces the list of dates:
select date '2023-03-01' + i AS dt
from generate_series(0, ((current_date - 5) - date '2023-03-01')) i)
dt |
---|
2023-03-01 |
2023-03-02 |
2023-03-03 |
... |
This looks into the events table:
select e_id, start_date, end_date
from tableA
e_id | start_date | end_date |
---|---|---|
1 | 2023-03-01 | 2023-03-04 |
2 | 2023-03-03 | 2023-03-05 |
3 | 2023-03-02 | 2023-03-03 |
I have tried this query:
with dl as (
select date '2023-03-01' + i AS dt
from generate_series(0, ((current_date - 5) - date '2023-03-01')) i)
)
, e as (
select e_id, start_date, end_date
from tableA
)
select dt, e_id
from dl
left join e on dl.dt >= e.start_date and dl.dt <= e.end_date
but I get the following error:
NOTICE: Function "generate_series(integer,integer)" not supported.
Specified types or functions (one per INFO message) not supported on Redshift tables.
Given the examples above, I would expect the following result:
dt | e_id |
---|---|
2023-03-01 | 1 |
2023-03-02 | 1 |
2023-03-02 | 3 |
2023-03-03 | 1 |
2023-03-03 | 2 |
2023-03-03 | 3 |
2023-03-04 | 1 |
2023-03-04 | 2 |
2023-03-05 | 2 |