require "active_record" ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") ActiveRecord::Migration.class_eval do create_table(:records) do |t| t.string :column end end data = 50_000.times.map { |i| Hash[column: "Column #{i}"] } # ============================================================= columns = data.first.keys values_list = data.map do |hash| hash.values.map do |value| ActiveRecord::Base.connection.quote(value) end end ActiveRecord::Base.connection.execute <<-SQL INSERT INTO records (#{columns.join(",")}) VALUES #{values_list.map { |values| "(#{values.join(",")})" }.join(", ")} SQL # Takes 2 seconds, because it does a single multi INSERT statement. # But the code is even uglier than with Arel.