I'd like to do following athena query with redshift, but so far it's been impossible to reproduce it. The query should be called in a CREATE TABLE AS ()
statement, so generate_sequence() ideas might not work. Any ideas?
Athena query:
SELECT
*
FROM table_one t1
CROSS JOIN UNNEST(slice(sequence(t1.effective_date, t1.expiration_date, INTERVAL '1' MONTH), 1 ,12)) AS t (sequence_date)
As requested I add an example to show what I'm trying to do. Basically I have a record with a validity interval (year units 1, 2, 3...) and I'd like to replicate it N time times such that each new record is assigned to date YYYY-MM-DD + interval*12/N months (See examples)
Original record:
Date | variables |
---|---|
2021-05-06 | values |
To be (N=12 and interval of 1 year)
Date | variables |
---|---|
2021-05-06 | values/12 |
2021-06-06 | values/12 |
2021-07-06 | values/12 |
2021-08-06 | values/12 |
2021-08-06 | values/12 |
2021-10-06 | values/12 |
2021-11-06 | values/12 |
2021-12-06 | values/12 |
2022-01-06 | values/12 |
2022-02-06 | values/12 |
2022-03-06 | values/12 |
2022-04-06 | values/12 |
To be (N=4 and interval of two years)
Date | variables |
---|---|
2021-05-06 | values/2 |
2021-11-06 | values/2 |
2022-05-06 | values/2 |
2022-11-06 | values/2 |
Thanks for the help