Postgres error 42P05: duplicate prepared statement
prepared statement "s0" already exists
The driver tried to create a named prepared statement that already exists on this server connection.
Common causes
- A transaction-mode connection pooler (such as PgBouncer in transaction mode) handed the same server connection to different clients, and their prepared statement names collided.
- A driver that names statements reusing names after a reconnect.
How to fix it
- Turn off named prepared statements in the driver when using a transaction pooler (Prisma: pgbouncer=true; node-postgres: do not set a statement name; psycopg: prepare_threshold=None).
- Or connect in session mode / directly for workloads that need prepared statements.
Through a REST API
PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 400 for this error and returns the SQLSTATE in the code field of the JSON error body.
Questions
What does Postgres error 42P05 mean?
42P05 is duplicate_prepared_statement in class 42 (Syntax Error or Access Rule Violation). The driver tried to create a named prepared statement that already exists on this server connection.
How do I fix 42P05?
Turn off named prepared statements in the driver when using a transaction pooler (Prisma: pgbouncer=true; node-postgres: do not set a statement name; psycopg: prepare_threshold=None). Or connect in session mode / directly for workloads that need prepared statements.
What HTTP status does a REST API return for 42P05?
PostgREST, the REST layer behind supabase-js, answers 400.