From: Jeff Frost <jeff@frostconsultingllc.com>
To: pgsql-sql@postgresql.org
Subject: keeping last 30 entries of a log table
Date: Fri, 16 Jun 2006 19:29:31 -0700 (PDT)
Message-ID: <Pine.LNX.4.64.0606161924550.27250@glacier.frostconsultingllc.com> (raw)
I need to write a function which inserts a log entry in a log table and only
keeps the last 30 records. I was thinking of using a subquery similar to the
following:
insert into log (account_id, message) values (1, 'this is a test);
delete from log where account_id = 1 and id not in ( select id from log
where account_id = 1 order by timestamp desc limit 30);
I'm wondering if there is a more performance oriented method of doing the
delete that I'm not thinking of.
--
Jeff Frost, Owner <jeff@frostconsultingllc.com>
Frost Consulting, LLC http://www.frostconsultingllc.com/
Phone: 650-780-7908 FAX: 650-649-1954
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-sql@postgresql.org
Cc: jeff@frostconsultingllc.com
Subject: Re: keeping last 30 entries of a log table
In-Reply-To: <Pine.LNX.4.64.0606161924550.27250@glacier.frostconsultingllc.com>
References: <Pine.LNX.4.64.0606161924550.27250@glacier.frostconsultingllc.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