有没有办法从node.js在Postgresql中进行批量插入?

时间:2016-09-25 13:28:57

标签: node.js postgresql bulkinsert

我正在使用pg模块(以及承诺版本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 port
  • 我无法执行sh psql < "COPY..."
  • 之类的内容

如何批量插入单独发送数据?

1 个答案:

答案 0 :(得分:1)

我认为你应该看看同一作者的插件,就像数据库客户端库https://github.com/brianc/node-pg-copy-streams一样,它完全是为COPY命令做的。