Forum: Ruby on Rails Bulk Inserts. Fast way to insert 1000s records?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris Richards (chris)
on 2006-05-09 12:01
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
89441a6c74647d292f5cc951eae24cfa?d=identicon&s=25 Jack Christensen (Guest)
on 2006-05-09 15:05
(Received via mailing list)
Chris Richards wrote:

>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
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Richard Williams (Guest)
on 2006-05-09 15:33
(Received via mailing list)
On Tuesday, May 09, 2006, at 12:01 PM, Chris Richards wrote:
>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/rails


At 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.
This topic is locked and can not be replied to.