X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A6A969FA65C for ; Wed, 21 Jun 2006 14:57:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 29319-01 for ; Wed, 21 Jun 2006 14:57:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from glacier.frostconsultingllc.com (glacier.frostconsultingllc.com [64.127.99.90]) by postgresql.org (Postfix) with ESMTP id C70F49F9CC1 for ; Wed, 21 Jun 2006 14:57:27 -0300 (ADT) Received: from localhost ([127.0.0.1]:55434) by glacier.frostconsultingllc.com with esmtp (Exim 4.62) (envelope-from ) id 1Ft6xA-0001PX-Li; Wed, 21 Jun 2006 10:57:24 -0700 Date: Wed, 21 Jun 2006 10:57:24 -0700 (PDT) From: Jeff Frost To: "Ben K." cc: pgsql-sql@postgresql.org Subject: Re: keeping last 30 entries of a log table In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: jeff@frostconsultingllc.com X-SA-Exim-Scanned: No (on glacier.frostconsultingllc.com); SAEximRunCond expanded to false X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/239 X-Sequence-Number: 25475 On Wed, 21 Jun 2006, Ben K. wrote: > Just for the sake of alternatives - > > create sequence cy30 maxvalue 30 cycle; > > insert into log values(select generate_series(1,30), 'dummy'); > INSERT 0 30 > > update log set des='....' where account_id=(select nextval('cy30')); > UPDATE 1 > > > There are details to consider I guess. For example what if an update fails > and the sequence already advanced... Also, since we cycle the id, for > sorting, we'll need to add timestamp or something similar. > Only problem with this approach is that I need to be able to keep track of the last 30 items per each account_id...so each account_id will have his last 30 messages in the table. -- Jeff Frost, Owner Frost Consulting, LLC http://www.frostconsultingllc.com/ Phone: 650-780-7908 FAX: 650-649-1954