From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | Anthony Apollis <anthony(dot)apollis(at)gmail(dot)com> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Calculating Days/Time(Are Loops Neccessary?) |
Date: | 2023-09-20 15:20:49 |
Message-ID: | 202309201520.jqs4jeruhezh@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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).
From | Date | Subject | |
---|---|---|---|
Next Message | Erik Wienhold | 2023-09-20 16:33:48 | Re: Changed functionality from 14.3 to 15.3 |
Previous Message | Adrian Klaver | 2023-09-20 15:04:02 | Re: Calculating Days/Time(Are Loops Neccessary?) |