I'm trying to generate dates that comes after a certain start_date with the interval of a variable day/s of week.
If the start_date is 2023-01-01
and the days of the week are [2,3,5]
or ['tue','thu','sat']
, then it should generate the following:
2023-01-03
2023-01-05
2023-01-07
I tried running
with dates as
(
select
s.a AS dates,
extract (dow from s.a)::integer dw
from
'some-table' as st,
generate_series(start_date::timestamp, start_date::date + 365) s(a)
where
st.id = 'some-value'
)
select *
from dates
where dw in (2,5)
limit 10
Is there a better way to do this?
EDIT: Corrected the sample values