I use the active_record_import gem. https://github.com/zdennis/activerecord-import https://github.com/zdennis/activerecord-import/wiki
It works well and is fairly mature and still maintained. I don't believe it implements COPY, as that tend to be very DBMS-specific in syntax, but the way it optimizes use of INSERTs is much faster than anything you can do with regular active_record. You can also work with (import) raw columns and arrays of values instead of instantiating active_record model objects, which can save a ton of memory when dealing with many records. On Tuesday, January 5, 2016 at 6:23:24 AM UTC-8, Andrew Kaspick wrote: > > Sounds useful, but likely a better fit for a standalone gem... at least to > start. > > > On Tue, Jan 5, 2016 at 9:20 AM, Andrey Novikov <[email protected] > <javascript:>> wrote: > >> Hi Greg. >> >> I am interested in bulk inserts as active Rails user. >> >> The use cases for that are somewhat rare, but when you need for example >> import some dictionary from 15 GB XML file to your DB, that will take >> literally days to complete, and one of the bottlenecks (except XML parsing) >> will be a lot of INSERTS with waiting for completion of each statement. >> Bulk INSERTs may really help there. >> >> Sorry, I'm just a user and can't help you with any guidance in >> ActiveRecord (really I need such a guidance too in my own work). >> >> With best regards, Andrey Novikov. >> >> вторник, 5 января 2016 г., 13:38:28 UTC+3 пользователь Greg Navis написал: >>> >>> Hey! >>> >>> I'd love to receive some feedback and guidance. The most important thing >>> for me is: is this something we'd like to have in Active Record? If so, I'd >>> be able to start working on this next week. If not, I'd love to contribute >>> in another way. >>> >>> Best regards >>> -- >>> Greg Navis >>> >>> On Fri, Dec 11, 2015 at 9:16 AM, <[email protected]> wrote: >>> >>>> Hey! >>>> >>>> I'm thinking about adding bulk inserts to Active Record. My preliminary >>>> research indicates that: >>>> >>>> 1. Bulk inserts haven't been raised in an issue (I browsed through all >>>> issues, open and closed, with the word "insert"). >>>> 2. Same for PRs labeled with "activerecord". >>>> 3. I found https://github.com/zdennis/activerecord-import (maintained) >>>> and https://github.com/zdennis/ar-extensions/tree/master/ar-extensions >>>> (unmaintained). >>>> 4. I searched this group for "bulk insert", "mass insert", "insert >>>> multiple" and "insert many" but it seems the issue hasn't been discussed. >>>> >>>> The scope of work is: >>>> >>>> 1. Designing an ActiveRecord API for the feature. >>>> 2. Adding support for bulk INSERTs to arel. >>>> 3. Implementing the API from 1 using the functionality from 2. >>>> 4. Enhancing the documentation. >>>> >>>> My question is: are bulk inserts something we'd like to see in >>>> ActiveRecord? >>>> >>>> Best regards >>>> -- >>>> Greg Navis >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Core" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> Visit this group at http://groups.google.com/group/rubyonrails-core. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/rubyonrails-core. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
