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 1oEEsM-0001XN-7f for pgsql-general@arkaria.postgresql.org; Wed, 20 Jul 2022 18:56: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 1oEEsK-00035y-2B for pgsql-general@arkaria.postgresql.org; Wed, 20 Jul 2022 18:56: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 1oEEsJ-000332-MI for pgsql-general@lists.postgresql.org; Wed, 20 Jul 2022 18:56:47 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oEEsH-0000Dh-54 for pgsql-general@lists.postgresql.org; Wed, 20 Jul 2022 18:56:47 +0000 Received: by mail-ot1-x32b.google.com with SMTP id k25-20020a056830169900b0061c6f68f451so14834204otr.9 for ; Wed, 20 Jul 2022 11:56:44 -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=pHMY+DTwetzj0b+LxNDGihhuCvRhK771rSm1cg8z5Mc=; b=dzI6lTzHBDG/faWpaRhL1Ygeo2KhFVZssCwPbE8rMo4l1RTfAwrmXvS9B6oXd/7nVR GFGhW5Ml2LpWRP6VZ/2rRg874x7ajz4eF90AG0iW3i2C3IuFEjTYCl7NjeE4GEMlx9QV hiubsZTWz5BP3Ggys1LBi8yYiTKmP5BJFw+Pd+DDIxIYPZMkqCkH0fdfq9uGEQZaXHQS XiGiNuSiWyoTWEgyELj3cBuSsdTjKP1ivJNFWoFJ5a0vG0rMqZRXR0ksN1dHPDuhkWem M9chh5CSs/mDAIHjDd0qHRoXMmtW4dVQiNweQYJJHnG5jEpPxfHBA2Nke6QVfm8+n3J5 eukw== 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=pHMY+DTwetzj0b+LxNDGihhuCvRhK771rSm1cg8z5Mc=; b=4s1f38e3fh5EwmM4Dw+B960iTxfRZtZXmWgYHN7ssMvFRzhkA2tie+g7ec7DZErWP9 By7eHxXxVAn1Yc6DqnE4JEY/e6lWdjRCeRtsG0mKkhCzdXiPxxEPLZTAvMT8XH1evc0M IFjPwHGyhPyi2QTK0jMXQreVDA72P9ZHIFzIAygEA9SBxBh5c31hCeqvGVf7VC9JYlnz luAuxsx83Jy9Gf0g5vXY2+nqQdmjsQFO+/GP0iRPtMENoKqcz3wSxroGJJ+JTv3C9PE5 7J0ZJEfsgH6uTdy4MwRaZ5+GRY42XtM6bU3N9yk+NQ72JBZs7/G2k6iOwF/c0sM1z2vl AVSg== X-Gm-Message-State: AJIora+xXWdCmEmmjo93DVVe9iss9Euued4hQHLS10k5RMVqa3v/S4QV EEWcTzQD2xbTDXP9E+gUr01jVWXct5g= X-Google-Smtp-Source: AGRyM1sdX4WXIZzMVAhn+1ciqot4my2x9EpQ1HAYZM5Gr/fxFJr4xSe2xQLGzsBv7kG2L8eRdN69Vg== X-Received: by 2002:a9d:6e84:0:b0:61c:af4f:7fa2 with SMTP id a4-20020a9d6e84000000b0061caf4f7fa2mr5437774otr.314.1658343402309; Wed, 20 Jul 2022 11:56:42 -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 k10-20020a9d7dca000000b0061cae9aba22sm2830177otn.71.2022.07.20.11.56.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Jul 2022 11:56:41 -0700 (PDT) Message-ID: <068d478e-1302-bf5c-9481-3b2c532f8ffc@gmail.com> Date: Wed, 20 Jul 2022 13:56:41 -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> <1f2e957b-dbfc-5c17-2abd-77a944a6786c@gmail.com> <1f6f563f-2f58-8749-5492-4bed9f67df9f@aklaver.com> From: Ron In-Reply-To: <1f6f563f-2f58-8749-5492-4bed9f67df9f@aklaver.com> 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 How will DELETE WHERE sales_id IN (...); , given that test_old has no index? Of course, we don't know if there's an index on sales.bill_date, since OP's only response has been another "tell me how to do it". On 7/20/22 13:32, Adrian Klaver wrote: > 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 -interval '1 year'; > > At that point you could do either: > > Delete from sales where sales_id in (select sales_id from test_old); > > or > > DELETE 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>>> >>> >>> Because it looks like the OP is saving the old records in test_old. >>> >>> >> > > -- Angular momentum makes the world go 'round.