Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ngsjS-0007ae-Qn for pgsql-general@arkaria.postgresql.org; Tue, 19 Apr 2022 18:37:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ngsjR-000149-Cb for pgsql-general@arkaria.postgresql.org; Tue, 19 Apr 2022 18:37:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ngsjQ-000140-B3 for pgsql-general@lists.postgresql.org; Tue, 19 Apr 2022 18:37:45 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ngsjM-0000se-IB for pgsql-general@postgresql.org; Tue, 19 Apr 2022 18:37:43 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 7A8B23201C39; Tue, 19 Apr 2022 14:37:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 19 Apr 2022 14:37:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1650393456; x= 1650479856; bh=+QcxHZCrgiaaDZoaFRg37oxTsrw3hs4KdWH0YCdhUkM=; b=W EMs10SsUlbpz2kSWg4WWzZ0SotYHORIy8kih1BrKLKqVLqCbZQxf2ECDi8QYz/wO YxUrIRsJbOTzD+05atVjqGeJOyu7KkNBb7z7T7HE7dJnH6jn0J3DOlOW80a7OD19 2JQ/z6gDrBQb1jmWXZQLfdT+jhcTs/wzzL6TDiPvgvdTCp8mjLSc9lIdESMg6PId bexBjerZDhhIyHNJxP9tb8X/5e/ECC1NUkc6qJYAdq82pfBa8doujnf/KJN8ZdmN hHEj+epx0GX/E97rSKD/Yx6HM8MSgCtqznyosUNbrV1vAnrQhOGr57u25ntG6rub VhvG5VkLt/vQwbqwQc5vw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1650393456; x=1650479856; bh=+QcxHZCrgiaaDZoaFRg37oxTsrw3 hs4KdWH0YCdhUkM=; b=F9Zcwt+zQyCqgB7zscyJxzNvcOiBNzxyH9hbHd+I8xFk t4qtEYafvwuV3aIM0PxtW53ZaDxcOvEQSuBxpikMdDrs5/xPd8g3k0opXr75pNmx Q9N2poWbUUh7gVSD6v02/hCkW3y6eRZNlC5FyDvzjiQ8R8uVN2kayzx5k9ykP9up DsVEuBZ/BFTklsnXq6xtbzHQ0apEV9D0zmaIXesUHbWg01Qh00sC3AuL2CBjDsl/ yq8CdHnjZvD4NWGi2wDa3u0SVYD02yrkPsD5ACp3avJNFSfp0ZxJUbbC77gdBSl6 jWQ/2D37wX1LcXWJE37fQhgIT/Cw34HBzY/JFh8UPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrvddtfedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth ekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpedugfeule egveffhfegleejhefhtedtgeeileeggfehfefffeevgeejtdeutefftdenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrg hvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 19 Apr 2022 14:37:36 -0400 (EDT) Message-ID: <150d21a4-4fcf-dd4d-85ea-063194d89d7c@aklaver.com> Date: Tue, 19 Apr 2022 11:37:35 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: Joining with calendar table Content-Language: en-US To: =?UTF-8?Q?P=c3=b3l_Ua_L=2e?= , "pgsql-general@postgresql.org" References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/19/22 00:34, Pól Ua L. wrote: > > > Bonjour a tous/Hello all, > > > Small problem - I hope it not to trivial for here. > > We created a table, then someone deleted some records and we want to put > them back, but we not sure how. > > CREATE TABLE dat AS >   SELECT >     GENERATE_SERIES >     ( >       '2022-03-01'::DATE, >       '2022-04-18'::DATE, >       '1 DAY' >     ) AS jour; > > So, all days from March 01 to Easter Monday. > > Then someone delete the weekends. > > > delete from dat where extract(isodow from jour) IN (6, 7); > > > > But, there are also actvities on these days  also, so I would like to > put them back in. > > I think I need a left join with the calendar table, but am not sure how > to do this so we have full months again. > > Could someone show me how this to be done please? BEGIN; insert into dat select j.a from GENERATE_SERIES ( '2022-03-01'::DATE, '2022-04-18'::DATE, '1 DAY' ) as j(a) left join dat on j.a = dat.jour where dat.jour is null; INSERT 0 14 Verify the dates where added then: COMMIT; -- Adrian Klaver adrian.klaver@aklaver.com