Is there a way in Rails to insert many records at once, with a single SQL command? I''ve noticed that loading a dump file of data from the command line is much faster to doing something like SomeModelClass.create(...) for each individual record. --Paul --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/6/08, Paul E. G. Lynch <plynchnlm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Is there a way in Rails to insert many records at once, with a single > SQL command? I''ve noticed that loading a dump file of data from the > command line is much faster to doing something like > SomeModelClass.create(...) for each individual record.create accepts an array of hashes as well as a single hash. http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001379 -- Greg Donald http://destiney.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6 Feb 2008, at 23:15, Greg Donald wrote:> > On 2/6/08, Paul E. G. Lynch <plynchnlm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Is there a way in Rails to insert many records at once, with a single >> SQL command? I''ve noticed that loading a dump file of data from the >> command line is much faster to doing something like >> SomeModelClass.create(...) for each individual record. > > create accepts an array of hashes as well as a single hash. > > http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001379 >Which won''t make any speed difference since if you pass it an array of hashes it just iterates over that array calling create on each element. In times like these I''ve occasionally fallen back to just creating an sql statement to insert all the values and executing it. You lose AR type conveniences(validations etc...) but it is a lot faster on large numbers of records. Fred> > -- > Greg Donald > http://destiney.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---