RVince wrote:
> Yes, I can see there is no easy, rails-way to do this. In effect, I
> need to
> 
> 1. read in the X most recent records (Select * from Chanelnotes order
> by tstamp DESC limit 10)
> 2. Delete the entire table (delete * in Channelnotes)
> 3. Do an insert on the ten records I read in.
> 
> There's no other way.

Sure there is.  Find the IDs of the 10 most recent records, then delete 
any record whose ID is not in that set.  SQL would be something like 
(from memory):

DELETE FROM channelnotes
WHERE id NOT IN
(SELECT id from channelnotes
ORDER BY tstamp
LIMIT 10)

See?  You only touch the records you're deleting.  No reinsert 
necessary.

BTW, why is your timestamp column called tstamp instead of created_at ?

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to