嗨,我有一个 Rails 应用程序,我想在单个查询中创建多个记录
这是我的代码
inserts = []
1000.times do
inserts.push "user name"
end
inserts = inserts.map {|bar| "(#{bar.to_s})"}.join(",")
ActiveRecord::Base.connection.execute "INSERT INTO `user_dat`.`user_inserts` (`name`) VALUES #{inserts}"
我得到的错误是mysql语法中的错误
INSERT INTO `batch_insert`.`batch_inserts` (`name`) VALUES (user name),(user name),(user name),(user name),(user name),(user name),(user name).... upto 1000
我知道我想要它(“用户名”),(“用户名”),但我无法实现它有人可以告诉我如何实现这种格式的值