Re: How to delete the oldest X number of rows? - Mailing list pgsql-novice

From A. Kretschmer
Subject Re: How to delete the oldest X number of rows?
Date
Msg-id 20051212164716.GA32526@webserv.wug-glas.de
Whole thread Raw
In response to How to delete the oldest X number of rows?  ("John Roberts" <jsrober@hotmail.com>)
Responses Re: How to delete the oldest X number of rows?
List pgsql-novice
am  12.12.2005, um 11:29:58 -0500 mailte John Roberts folgendes:
> Hi,
>
> I have a table that logs the performance of a system. I get an entry in
> this table each time the system does something.
>
> I want to keep the last 50,000 rows in the table. I'd like to run a cron
> job every 5 minutes that will delete all rows > 50,000, oldest first.
> What's the most efficient way to do this query/delete?
>
> DELETE FROM log WHERE timestamp < ????

Something like:

select timestamp from log order by timestamp limit 1 offset 49999;

to get the oldest timestamp to keep and delete the early rows?


*untestet*

delete from fol where timestamp < (select timestamp from log order by
timestamp limit 1 offset 49999);

HTH, Andreas
--
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    ===

pgsql-novice by date:

Previous
From: Mathieu Arnold
Date:
Subject: Re: How to delete the oldest X number of rows?
Next
From:
Date:
Subject: Re: Bind Variables and Quoting / Dequoting Input