Re: Limit record count

From: Rodrigo Gonzalez <rjgonzale(at)gmail(dot)com>
To: "Sean Z(dot)" <sean09182006(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Limit record count
Date: 2007-12-17 22:24:44
Message-ID: 4766F72C.5040002@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

DELETE FROM <table> WHERE <id> NOT IN (SELECT <id> FROM <table> ORDER BY
<id> DESC LIMIT 50)

Sean Z. escribió:
> Hi,
>
> I need to write a maintenance function to delete oldest records of a
> table, leaving only a certain number of records, say 50. The task
> should run once per day. How can I write it?
> The oldest record carries the smallest ID.
>
> Thanks a lot!
> Sean
>
> ------------------------------------------------------------------------
> Never miss a thing. Make Yahoo your homepage.
> <http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Smith 2007-12-17 22:54:17 Re: install problem
Previous Message Dave Page 2007-12-17 22:24:05 Re: spreadsheet interface