On 2023-Sep-19, Anthony Apollis wrote: > I have inherited this code, problem is it is over code, i believe. The > package is gonna run once a month and this code run is a loop. How can this > loop be running and checking data up until last day, if it only run once a > month?
I didn't stop to understand your problem fully, but if you need the set of calendar days in one month, you can use the generate_series() function around some arithmetic that gives you the start of the month plus when it ends, something like this: with onedate(theday) as (values (date '2023-02-03')) select g::date from onedate, generate_series(date_trunc('month', onedate.theday), date_trunc('month', onedate.theday) + interval '1 month' - interval '1 day', '1 day') g ; -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "El sabio habla porque tiene algo que decir; el tonto, porque tiene que decir algo" (Platon).