SQLSTATE 42P03Severity lowLab verified

Incident brief

Duplicate cursor

Declaring a cursor with a name already open in the same transaction raises this error; cursor names must be unique within a transaction.

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Reviewed by Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What
Duplicate cursor
What triggers it
Open a transaction and DECLARE a cursor with a given name.
The fix
Give each cursor a unique name within the transaction.
Proof
Reproduced on PostgreSQL 18.4 → Inside one transaction the reproduction declares a cursor, then re-declares the same name: the second DECLARE raises SQLSTATE 42P03.

The fix

What to do right now

The immediate, application-level response to this error.

  • Give each cursor a unique name within the transaction.
  • Or CLOSE the existing cursor before re-declaring the name.
Fix — SQL
-- Use a distinct name for each open cursor.
BEGIN;
DECLARE dc CURSOR FOR SELECT 1;
DECLARE dc2 CURSOR FOR SELECT 2;
COMMIT;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Reviewed by
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed