pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Batch process
Date: Wed, 20 Jul 2022 13:56:41 -0500
Message-ID: <068d478e-1302-bf5c-9481-3b2c532f8ffc@gmail.com> (raw)
In-Reply-To: <1f6f563f-2f58-8749-5492-4bed9f67df9f@aklaver.com>
References: <CAJWX+ENJm8tsZ2y9z075w-4Vbtv4GQaLOQpVb8b-VYiOea1oPw@mail.gmail.com>
	<5d0d0349-1e6f-3f8f-41cb-3d853712eff9@gmail.com>
	<eab2ed8d-785f-8992-3890-fb28dd38ec78@aklaver.com>
	<1f2e957b-dbfc-5c17-2abd-77a944a6786c@gmail.com>
	<1f6f563f-2f58-8749-5492-4bed9f67df9f@aklaver.com>

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<now() 
> -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<NOW() -INTERVAL '1 year';
>
>
>>
>> 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<now() 
>>>>> -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<NOW() -INTERVAL '1 year';?
>>>>
>>>
>>> Because it looks like the OP is saving the old records in test_old.
>>>
>>>
>>
>
>

-- 
Angular momentum makes the world go 'round.





view thread (11+ messages)  latest in thread

Message-ID: <068d478e-1302-bf5c-9481-3b2c532f8ffc@gmail.com>
Permalink:  ../068d478e-1302-bf5c-9481-3b2c532f8ffc@gmail.com/
Also on:    postgresql.org/message-id/068d478e-1302-bf5c-9481-3b2c532f8ffc@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Batch process
  In-Reply-To: <068d478e-1302-bf5c-9481-3b2c532f8ffc@gmail.com>
  References: <CAJWX+ENJm8tsZ2y9z075w-4Vbtv4GQaLOQpVb8b-VYiOea1oPw@mail.gmail.com> <5d0d0349-1e6f-3f8f-41cb-3d853712eff9@gmail.com> <eab2ed8d-785f-8992-3890-fb28dd38ec78@aklaver.com> <1f2e957b-dbfc-5c17-2abd-77a944a6786c@gmail.com> <1f6f563f-2f58-8749-5492-4bed9f67df9f@aklaver.com> <068d478e-1302-bf5c-9481-3b2c532f8ffc@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox