How to do a bulk insert with node-postgres How to do a bulk insert with node-postgres express express

How to do a bulk insert with node-postgres


Following the clarification provided by the author, to insert up to 1000 records at a time, the solution as suggested within Multi-row insert with pg-promise is exactly what the author needs, in terms of both performance and flexibility.

UPDATE

A must-read article: Data Imports.


You can use this package https://www.npmjs.com/package/pg-essential. It will apply a patch on node-postgres and You just need to call it's executeBulkInsertion function. You can create an array of the objects to be inserted and pass it to the executeBulkInsertion function.

let bulkData = [];foreach( user in users){ bulkData.push(user);}await db.executeBulkInsertion(bulkData,[array of column names],[table name]);