PostgreSQL: ERROR duplicate key value violates unique constraint (23505)

INSERT or UPDATE attempted to store a value already present in a UNIQUE index.

Runs locally in browser Free · No login Available (Noindex) · 2026-11-24 v1.0.0
Identifier: PostgreSQL: ERROR duplicate key value violates unique constraint (23505) Platform: PostgreSQL

Interactive Diagnostic Checklist

Safe Diagnostic Command:
\d+ <table_name>

Technical Explanation

INSERT or UPDATE attempted to store a value already present in a UNIQUE index. Recommended verified resolution path: Use `ON CONFLICT DO UPDATE/NOTHING` for idempotent upserts.

Worked Examples

  • Read-only diagnostic command: \d+ <table_name>

Limitations & Assumptions

  • Error codes can arise from multiple layers (client, CDN, reverse proxy, application, or OS). Always confirm which layer emitted the error before applying changes.

Source References & Verification

Resource ID: err-pg-unique-violation · Technical check: 2026-11-24 (noindex pending/withheld from search)

Related Resources