Re: [SQL] keeping last 30 entries of a log table

2006-06-21 Thread Ben K.
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

Re: [SQL] keeping last 30 entries of a log table

2006-06-21 Thread Jeff Frost
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 consid

Re: [SQL] keeping last 30 entries of a log table

2006-06-20 Thread Jeff Frost
On Tue, 20 Jun 2006, Dirk Jagdmann wrote: Column id should be indexed indeed. Anyway, I'm not sure about any performance improvement using that last method, as the most consuming operation might be the DELETE operation, not really the SELECT operation, when dealing with a huge volume of data.

Re: [SQL] keeping last 30 entries of a log table

2006-06-20 Thread Dirk Jagdmann
Column id should be indexed indeed. Anyway, I'm not sure about any performance improvement using that last method, as the most consuming operation might be the DELETE operation, not really the SELECT operation, when dealing with a huge volume of data. why worry, there are a maximum of 30 Ent

Re: [SQL] keeping last 30 entries of a log table

2006-06-19 Thread Daniel CAUNE
> >> 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

Re: [SQL] keeping last 30 entries of a log table

2006-06-19 Thread Jeff Frost
On Sat, 17 Jun 2006, Daniel CAUNE wrote: 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 me

Re: [SQL] keeping last 30 entries of a log table

2006-06-17 Thread Daniel CAUNE
> 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 i

[SQL] keeping last 30 entries of a log table

2006-06-16 Thread Jeff Frost
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