eggman2001 wrote: > I have a few thousand rows of stock market data - one row for each > day. I'm using ActiveRecord to perform database operations. > > I'm interested in performing a calculation on each row while > incorporating the result of the calculation on the previous row [...] > I figure that I'll start with an array of size 3,000. Then I would > probably want to iterate over it, possibly saving the result of the > operation of each row to a new array but this area is a little foggy. > > Any suggestions?
Well, some ideas: * Get the whole dataset (or each batch of 3000) into memory with one query before operating. No sense in making the database bottleneck any worse than it has to be. * Find a way to do the calculations on the DB side, using aggregate functions and/or (gasp!) stored procedures. This will probably be easier if you're using PostgreSQL or Oracle, since mySQL's procedural language is so weak as to be unusable for non-trivial work. * Provide more detail and we might be able to help more. Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

