有没有办法从 node.js 在 Postgresql 中进行批量插入?
Is there a way to do bulk insert in Postgresql from node.js?
我正在使用 pg
模块(和 promise 版本 pg-promise-strict
)。
当我需要插入1k条记录时,我必须一条一条地发送到服务器。
我无法构建 1k 记录 INSERT,因为我的组织政策:数据必须单独发送(如 https://github.com/brianc/node-postgres/wiki/Client#method-query-parameterized 中所示)
我尝试编写一个 plsql
函数来执行批量插入并将所有数据发送到数组中(或字符串中,我都尝试两者):
client.query("select bulk_insert", [allTheData], cb);
我收到以下消息:
index row requires 38656 bytes, maximum size is 8191
注释
- 数据库在其他服务器
- 我只能连接 de postgres 端口
- 我无法执行类似
sh psql < "COPY..."
的操作
如何批量插入单独发送数据?
我认为你应该看看来自同一作者的插件,作为你的数据库客户端库:https://github.com/brianc/node-pg-copy-streams 正是为 COPY
命令制作的。
我正在使用 pg
模块(和 promise 版本 pg-promise-strict
)。
当我需要插入1k条记录时,我必须一条一条地发送到服务器。
我无法构建 1k 记录 INSERT,因为我的组织政策:数据必须单独发送(如 https://github.com/brianc/node-postgres/wiki/Client#method-query-parameterized 中所示)
我尝试编写一个 plsql
函数来执行批量插入并将所有数据发送到数组中(或字符串中,我都尝试两者):
client.query("select bulk_insert", [allTheData], cb);
我收到以下消息:
index row requires 38656 bytes, maximum size is 8191
注释
- 数据库在其他服务器
- 我只能连接 de postgres 端口
- 我无法执行类似
sh psql < "COPY..."
的操作
如何批量插入单独发送数据?
我认为你应该看看来自同一作者的插件,作为你的数据库客户端库:https://github.com/brianc/node-pg-copy-streams 正是为 COPY
命令制作的。