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 1oEEFk-0007zz-Ay for pgsql-general@arkaria.postgresql.org; Wed, 20 Jul 2022 18:16:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oEEFi-0000qr-7t for pgsql-general@arkaria.postgresql.org; Wed, 20 Jul 2022 18:16:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEEFh-0000qh-Rp for pgsql-general@lists.postgresql.org; Wed, 20 Jul 2022 18:16:53 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oEEFf-00006h-FJ for pgsql-general@lists.postgresql.org; Wed, 20 Jul 2022 18:16:52 +0000 Received: by mail-ot1-x32a.google.com with SMTP id a14-20020a0568300b8e00b0061c4e3eb52aso14766728otv.3 for ; Wed, 20 Jul 2022 11:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=0l1Jg+KHXM0NWOc2J2Dw7vsS621Z+OU8DoizIFPRy8Y=; b=pF+6Dn2XhhCO5nQAwitX/uZnOh5Afe5v7OecFUXjQlQcfmyz249Oi/3+xakkn0Rbo1 aMjqoQTOXg9Z/a/+TZGJ3ciWEADxs87fX6QNjMss/adIhqbNUsWky06xa6OnZu68DoTL dKBqCilmPKdpkL3R/HsAiPiny6yy804fYIo9djid1hHRuhVWlNe59ORKhmG/gI4ys/t2 TQb/5jagheqn2MlyMR9HQJw021ojSdh2RjEe/Pe4xzH+AZu5KEzS3tDZNQZTBGBDyPl3 ZmX9xh8CBPGvsC9PxEUMCSn1W3YPF98s0Lq86QUijk4g9M49YjIBKTGqut0oU/dKn06B qmyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=0l1Jg+KHXM0NWOc2J2Dw7vsS621Z+OU8DoizIFPRy8Y=; b=fwA3oWCvuK6zNfSXqBdzt2CTEJwXU92iCfTSD8LW59Zm8sDceE9MCE/xG1KbHvvy9J 3ei/ZpuiT0X+Dk8h/pFEQepmO/CB0Iot5zJpfgvGJwfTIbDhehCjp0T+njgE9mLiJek7 RD1C7um5W3vcNdVAJJbk3lmuL7ecPn7uLz1WQiM1up93oqTDOgEW7zzNa9Dg8+vPBo7m 0m1aTt04GBF7QNIW7gqjfSJ0Urbh/Q5BMvsLI9ZkW/wzeSsuUwHyAgVMmxvE2VtTl0kF r2W1nEORXpE+vnPqJXLO9cadzxtzf0qL1w1ZnQmphs7B+MeKSQNK3hqDLikN0IqvyXUX peXQ== X-Gm-Message-State: AJIora8reMs58OIhRCDED/vHt1Mqc9T+r+1v4ruWR2ndKYECRjLCxFEs T7nZCOgesO3sIbb4jZEDK30M3y0k9xI= X-Google-Smtp-Source: AGRyM1uhindUulEXB1t3S8/e2Ihmj8TbRvAuShVsO5wiPeL9OK/FhBMI4q7Eo/MnCiXOmG2If9B2BQ== X-Received: by 2002:a05:6830:40c6:b0:61c:869f:5899 with SMTP id h6-20020a05683040c600b0061c869f5899mr10612730otu.36.1658341010572; Wed, 20 Jul 2022 11:16:50 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id cb1-20020a056830618100b00616c46f6daasm7646623otb.31.2022.07.20.11.16.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Jul 2022 11:16:50 -0700 (PDT) Message-ID: <1f2e957b-dbfc-5c17-2abd-77a944a6786c@gmail.com> Date: Wed, 20 Jul 2022 13:16:49 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Batch process Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <5d0d0349-1e6f-3f8f-41cb-3d853712eff9@gmail.com> From: Ron 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 But the first thing he does is drop test_old. 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> > > Because it looks like the OP is saving the old records in test_old. > > -- Angular momentum makes the world go 'round.