question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

node-postgres not being able to handle large inserts?

See original GitHub issue

I am getting this error while executing a large transaction.

{ 
[error: bind message supplies 14472 parameters, but prepared statement "" requires 80008] 
}
  1. I am inserting 10001 rows and each row has 8 columns.
  2. I can confirm that I did supply all 80008 parameters but for some reason, I keep getting this bind message supplies 14472 parameters error
  3. My work_mem is 1mb and maintenance_work_mem is 16mb

My resolution: I had to write the sql query into a file (‘insert.sql’) and then I went into postgres console and did \i insert.sql and then it was fine.

Note: With node-postgres, I use node-sql to generate prepared statements, however, when I did \i insert.sql I produced a raw sql statement.

Some guesses: Idea 1: Maybe because I am inserting so many rows at once that postgres dies after processing 14472 parameters?

I have had similar problems with node-postgres in the past where when I used node-postgres to do large inserts, it seemed not to be able to handle it well. And with large inserts I always resort back to \i insert.sql

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
brianccommented, Dec 28, 2020

Yeah I think it should be super cheap, can just do

if (params.length > 65535) {
  throw new Error('Postgres only supports up to 65535 parameters in a prepared statement')
}
2reactions
brianccommented, Dec 28, 2020

The 16-bit hard cap on params is specified as part of the postgres protocol and is a constraint within postgres itself. Here’s the code that writes the count of params. This library could probably throw a friendlier error rather than just having the query crash with a param count mis-match…but it’s nothing that we can actually “fix” on our side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node-postgres will not insert data, but doesn't throw errors either
js and I have a problem inserting data. The function: function addItems(listId, listItems, handle) { if (!listItems) { ...
Read more >
Optimizing Conditional Bulk Insert in Node.js + PostgreSQL
I described term conditional bulk insert as an operation where many records need to be inserted to DB at once, while ensuring there's...
Read more >
Processing large volumes of data safely and fast using Node ...
About designing a PostgreSQL client for Node.js. Last week I have shared lessons learned scaling PostgreSQL database to 1.2bn records/month. In ...
Read more >
Documentation: 15: 13.2. Transaction Isolation - PostgreSQL
If MERGE attempts an INSERT and a unique index is present and a duplicate row is concurrently inserted, then a uniqueness violation error...
Read more >
7 Best Practice Tips for PostgreSQL Bulk Data Loading - EDB
The UNLOGGED mode ensures PostgreSQL is not sending table write operations to the Write Ahead Log (WAL). This can make the load process ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found