Hope you are fine I am trying to generate a table like this on Redshift using CTEs
Date | Hour | Minute |
---|---|---|
2001-12-02 | 0 | 0 |
2001-12-02 | 0 | 1 |
2001-12-02 | 0 | 2 |
2001-12-02 | 0 | 3 |
2001-12-02 | 0 | 4 |
2001-12-02 | 1 | 0 |
2001-12-02 | 0 | 1 |
In order to create a table that will every minute and hour for every day,
I achieved something like this with this query, but only for one day:
WITH test AS (
SELECT trunc(sysdate) as dt,
generate_series(0,23,1) as hour, minutes
FROM (
select generate_series(0,59,1) minutes)
)
SELECT * FROM test
It makes sense to have a table function written or something like that. But is not at option at present
I have DATE_TABLE is a table contains all the dates. But when I execute something like this:
WITH test AS (
SELECT (SELECT date_dt from DATE_TABLE LIMIT 10) as dt, generate_series(0,23,1) as hour, minutes FROM (select generate_series(0,59,1) minutes)
)
SELECT * FROM test
I get an error:
Function "generate_series(integer,integer,integer)" not supported.
Function "generate_series(integer,integer,integer)" not supported.
Tried this:
with recursive cte(N,minutes) as
(
select 0 as N,minutes FROM (select generate_series(0,59,1) minutes)
union all
select cte.N + 1,minutes
from cte
where cte.N <23
)
select * from cte
Didnt work probably because I dont understand it
Do you have any suggestion on how to achieve this? Probably a recursive query?