ruby - Sql中的多行插入

标签 ruby sequel

是否可以在 Sequel 中插入多行,如何实现? 谁能给我解释一下?

我试过这样的:

DB[:table].insert([:x, :y], [[1, 2], [3, 4]])

但是没用。

最佳答案

您可以使用 Dataset#multi_insert .

虽然文档描述它发布了两个 INSERT,但它似乎只发布了一个具有多个值的 INSERT,至少对于 PostgreSQL 是这样。

>> DB[:table].multi_insert([{x:1,y:2}, {x:3,y:4}])
INSERT INTO "table" ("x", "y") VALUES (1, 2), (3, 4)

关于ruby - Sql中的多行插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688324/

相关文章:

ruby-on-rails - 如何使用 Rails XML Builder 创建单个元素 JSON 数组?

ruby - 如何使用 Sequel 连接到 postgres 数据库?

ruby - 续集 gem 身份/自然元素

python - 什么是 Ruby 类方法的 Python 等价物?

Ruby:注释 "frozen_string_literal: true"有什么作用?

ruby - def myobject.mymeth 和 class << myobject; 之间的区别定义我的方法

ruby-on-rails - 如果我的服务器不支持 GCC 4.7 怎么办? sass 包

ruby - 使用 sequel 和 puma 创建与 postgresql 数据库的连接

ruby - 续集 gem : Create tables based on schema provided at runtime

Ruby Sequel : Array returned by query is being returned as a String object, 不是数组对象