From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Anthony Apollis <anthony.apollis@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Calculating Days/Time(Are Loops Neccessary?)
Date: Wed, 20 Sep 2023 17:20:49 +0200
Message-ID: <202309201520.jqs4jeruhezh@alvherre.pgsql> (raw)
In-Reply-To: <CAJyMCYJ8=a49j5v9C+PWPZ5C2yOnSQ697e+KYFmGv7BOCuX81w@mail.gmail.com>
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).
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: alvherre@alvh.no-ip.org, anthony.apollis@gmail.com
Subject: Re: Calculating Days/Time(Are Loops Neccessary?)
In-Reply-To: <202309201520.jqs4jeruhezh@alvherre.pgsql>
References: <CAJyMCYJ8=a49j5v9C+PWPZ5C2yOnSQ697e+KYFmGv7BOCuX81w@mail.gmail.com> <202309201520.jqs4jeruhezh@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox