Chris Richards
2006-May-09 10:02 UTC
[Rails] Bulk Inserts. Fast way to insert 1000s records?
Hi, This code loops through my results and saves them : @results.each{|r| r.save} There are potentially thousands of results. This takes ages to complete. Is there a quicker way to do this? Any help is greately appreciated Thanks Chris -- Posted via http://www.ruby-forum.com/.
Jack Christensen
2006-May-09 13:02 UTC
[Rails] Bulk Inserts. Fast way to insert 1000s records?
Chris Richards wrote:>Hi, > >This code loops through my results and saves them : > >@results.each{|r| r.save} > >There are potentially thousands of results. This takes ages to >complete. >Is there a quicker way to do this? > >Any help is greately appreciated >Thanks >Chris > > >Wrapping this in a transaction block should offer some improvement provided your db supports transactions. -- Jack Christensen jackc@hylesanderson.edu
Richard Williams
2006-May-09 13:31 UTC
[Rails] Bulk Inserts. Fast way to insert 1000s records?
On Tuesday, May 09, 2006, at 12:01 PM, Chris Richards wrote:>Hi, > >This code loops through my results and saves them : > >@results.each{|r| r.save} > >There are potentially thousands of results. This takes ages to >complete. >Is there a quicker way to do this? > >Any help is greately appreciated >Thanks >Chris > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsAt the extreme - - you can write your data to a temporary CSV file then use the native database bulk loader (assuming there is one) to do the load. -- Posted with http://DevLists.com. Sign up and save your mailbox.