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 1oEEV8-0000JJ-SX for pgsql-general@arkaria.postgresql.org; Wed, 20 Jul 2022 18:32:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oEEV6-0000Zn-Bl for pgsql-general@arkaria.postgresql.org; Wed, 20 Jul 2022 18:32:48 +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 1oEEV6-0000Ww-1d for pgsql-general@lists.postgresql.org; Wed, 20 Jul 2022 18:32:48 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEEV3-0008LA-KL for pgsql-general@lists.postgresql.org; Wed, 20 Jul 2022 18:32:47 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B5A465C0061; Wed, 20 Jul 2022 14:32:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 20 Jul 2022 14:32:43 -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=fm2; t=1658341963; x= 1658428363; bh=Ro4outMScNoMadCKJ0kTpeeYnSRe/KH8xdAW8w5yDLs=; b=j jiPZMQzOG4lKialQ8sLZ5PKYOKCNv6XmlOq9b5PHG6rCnPAZwYo/+4QDDC+tKa47 VrilkakzZiuAZ7ec9rfxn543S8aU65ktUg9pbHmA1jr3eJYiajPYnHZYlABvMuzj a91rjXg1ZzzDQSbnwbEmZi807FbA0ZMsmMWy8+CBfUB+rmuklIZY4bZZIXXe22/D 0cMCWyLVYlvVo+ZxB9NXyt5vkgZHcbdCqEj1lO8vIZeLmNLxNGmG1IIZOWEY0ZZ4 iQswc00n1URAFFdZoBM8JksV2c13G6eqF+keNH64o5xC9kIlVuSa6PuF0T5jl8eT Mj3+J3qNt3PUn3048oQ5Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id: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=fm3; t=1658341963; x=1658428363; bh=R o4outMScNoMadCKJ0kTpeeYnSRe/KH8xdAW8w5yDLs=; b=itys5OIpfib76YE2W s4NDOx/L5RFIU2hb3Ac1t07QG4Ip+64kXQQ12r/Fid++KyI64ulHlwXinRJZ35y0 CG+0+Re0aDIbwFBffhKoP6A+CAMf97aAEltxsPbAEunrJzHuaTybDXpZ141OlGuv kwO4aGc2E94KfcUtNOoKabiDUoFH0VsdLc0prGO166TQBzXpNK+tVTMEsF2BZUH/ O9s5VbGW/iLaQ10MGY45qnPnybQzKQ3XhNsgiOdPM2/Powiv59WXJoNEEsIV3qyH FnjojLsqHjjBp4gFlip3kkVMWavi2eLDHRYa4Q2oHlI8GC1/OjSuPoGquHh94Rmx wbvtQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudelvddguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeevveefve efueegffekkefhgeeiueffgfetueejvdfghfeujeejhfekjeelgedtgeenucevlhhushht vghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrg hvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 20 Jul 2022 14:32:43 -0400 (EDT) Subject: Re: Batch process To: Ron , pgsql-general@lists.postgresql.org References: <5d0d0349-1e6f-3f8f-41cb-3d853712eff9@gmail.com> <1f2e957b-dbfc-5c17-2abd-77a944a6786c@gmail.com> From: Adrian Klaver Message-ID: <1f6f563f-2f58-8749-5492-4bed9f67df9f@aklaver.com> Date: Wed, 20 Jul 2022 11:32:42 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <1f2e957b-dbfc-5c17-2abd-77a944a6786c@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/20/22 11:16 AM, Ron wrote: > But the first thing he does is drop test_old. Then: Create table test_old as select * from sales where bill_date > On 7/20/22 09:52, Adrian Klaver wrote: >> On 7/20/22 01:28, Ron wrote: >>> On 7/20/22 00:08, Rama Krishnan wrote: >>>> Hi All, >>>> >>>> I am doing purge activity my sales table contains 5M records I am >>>> going to delete more than 1 year data (which was 3M) records so it >>>> was running more so I want to do batch wise deletion through plsql >>>> >>>> >>>> >>>> >>>>  created or replace function data_purge() returns void as$$ >>>> Declare >>>> Begin >>>> Drop table test_old; >>>> Create table test_old as select * from sales where bill_date>>> -interval '1 year'; >>>> >>>> Delete table sales where sales_id in (select sales_id from test_old; >>>> >>>> End; >>>> $$ language plpgsql; >>>> >>>> >>>> Kindly guide me >>> >>> Why not just DELETE FROM sales WHERE bill_date>> year';? >>> >> >> Because it looks like the OP is saving the old records in test_old. >> >> > -- Adrian Klaver adrian.klaver@aklaver.com