Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qiz0b-008n1u-NP for pgsql-general@arkaria.postgresql.org; Wed, 20 Sep 2023 15:20:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qiz0Z-000ssL-A7 for pgsql-general@arkaria.postgresql.org; Wed, 20 Sep 2023 15:20:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qiz0Y-000ss2-V8 for pgsql-general@lists.postgresql.org; Wed, 20 Sep 2023 15:20:54 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qiz0W-005e6F-B4 for pgsql-general@lists.postgresql.org; Wed, 20 Sep 2023 15:20:53 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id AFBB25C006A; Wed, 20 Sep 2023 11:20:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 20 Sep 2023 11:20:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1695223251; x= 1695309651; bh=8UCE0Z1Wbe/9HPFtkdlCTFvjYUcAujkKQ1pfgScdj80=; b=A kBmrLNKxHGVuVf4SNu9bZ+iY9IMoNRv/tfRrfFLMGPU0+J2IDEkgqkLDwkoQs6Cl 6V/UBkK2TiVVcYXngmBmSRzL4wBxehcXhm6aTw9oIQtQM6/zh015iQgzpMdBF4Qi ixzuICI9Sy8HoLfMPujrd1VIQBJtVZfHGpSwPLQZwvLBuCIokRGZddUgX175WXND Uva43+DDLlm/4IrLv8OLnMK0htyPec2T4WQMT5McdqzvEb08xbZOvhYtqdSsAyeQ JN2mA/JWjOZJnQRfcyYMrGMWYoDI3k8YJQYUS/46mCC7FhYzSaXS9rB3vZn7Z3vP X/09IFuadPWmpfS6c/t+A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekfedgkeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 20 Sep 2023 11:20:50 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 20952C5; Wed, 20 Sep 2023 17:20:49 +0200 (CEST) Date: Wed, 20 Sep 2023 17:20:49 +0200 From: Alvaro Herrera To: Anthony Apollis Cc: pgsql-general@lists.postgresql.org Subject: Re: Calculating Days/Time(Are Loops Neccessary?) Message-ID: <202309201520.jqs4jeruhezh@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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).