Raw query failed when trying to insert batch of data
See original GitHub issueBug description
I have a rawInsert
function which is in charge of executing a raw query to insert multiple rows in a table. Function header looks like this:
export default async <T extends Record<string, any>>( table: string, fields: DistributiveKeyof<T>[], values: T[], opts?: { onConflict?: { target: (keyof T)[]; action: 'update' } }, ): Promise<number>
When I try to load test my API using k6 this function throws an error. This error happens when my batch size gets more than ~5000 rows. Error:
Raw query failed. Code: `N/A`. Message: `N/A`
How to reproduce
- generate a query like below and execute it using
executeRaw
. make sure you insert more than 5000 rows in this query.INSERT INTO table_name (col1, col2, col3, col4, col5, col6) VALUES ($1, $2, $3, $4, $5, $6), ($7, $8, $9, $10, $11, $12), ...
- run a load test over this query using k6. iterating through this also reproduces this error.
- run the exact same query using
pg
driver and everything is working just fine.
Expected behavior
To have a clear error message and insert all of my batch data rows into table.
Prisma information
generator client {
provider = "prisma-client-js"
previewFeatures = ["selectRelationCount"]
}
datasource db {
provider = "postgresql"
}
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version :v14.17.6
Prisma Version
prisma : 3.0.2
@prisma/client : Not found
Current platform : darwin
Query Engine (Node-API) : libquery-engine 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at ../../.npm/_npx/52649/lib/node_modules/prisma/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at ../../.npm/_npx/52649/lib/node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at ../../.npm/_npx/52649/lib/node_modules/prisma/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at ../../.npm/_npx/52649/lib/node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 2452cc6313d52b8b9a96999ac0e974d0aedf88db
Studio : 0.423.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
MySQL batch insert fails, no error - Stack Overflow
I'm trying to insert thousands of records of user-data into a different format in the same database, later to be exported to a...
Read more >Working With Line Numbers and Errors Using Bulk Insert
In this blog post, we look at these techniques using T-SQL's native bulk insert (Line Numbers and Errors Using Bulk Insert).
Read more >Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >How to INSERT If Row Does Not Exist (UPSERT) in MySQL
This means that an INSERT IGNORE statement which contains a duplicate value in a UNIQUE index or PRIMARY KEY field does not produce...
Read more >INSERT INTO - Amazon Athena - AWS Documentation
When running an INSERT query on a table with underlying data that is encrypted in ... Attempting to do so may result in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Internal conversation https://prisma-company.slack.com/archives/C040N0UADF0/p1662679627797069 Reproduction https://github.com/prisma/prisma/pull/15246 Todo Update snapshots once fix landed in the engines
Hi, we discovered this issue was due to a validation check in the Postgres driver we use that we didn’t expect. Specifically, even though prepared statements in Postgres support up to
65535
parameters (also known as bind variables), the driver we currently use supports half that parameters (one can create prepared SQL statements in Prisma via e.g.$executeRaw
and$queryRawUnsafe
). This caused us to fall back to the generic error message:With the latest release,
prisma@4.4.0
, we now show a clearer error message (with error codeP2035
) when the Prisma client prepares more than32767
bind variables:Thus, we now consider this issue solved.
Example
Given this schema:
Here’s an example of a query that fails with error code
P2035
due to hitting the maximum amount of bind variables:The same query with
n <= 32767
succeeds.