PostgreSQL Error Codes

Look up PostgreSQL SQLSTATE error codes by code or message text.

Searchable reference for PostgreSQL SQLSTATE error codes from the official appendix, with class, symbolic condition name and meaning — filterable by code, class or condition. Runs in your browser.

What is a PostgreSQL SQLSTATE?

A SQLSTATE is the 5-character error code PostgreSQL returns, following the SQL standard. PostgreSQL also gives each one a symbolic condition name like unique_violation, which is the recommended thing to match on in PL/pgSQL exception handlers.

This is a searchable reference for PostgreSQL error codes — the SQLSTATE values and symbolic condition names from Appendix A of the PostgreSQL manual. PostgreSQL pairs every standard 5-character SQLSTATE with a readable condition name like unique_violation or undefined_table, and that name is what you should match in exception handlers.

How it works

Each PostgreSQL error has a 5-character SQLSTATE whose first two characters are the class. Class 00 is success, 01 warning, 02 no-data, and everything else is an exception — 08 connection, 22 data, 23 integrity constraint, 40 transaction rollback, 42 syntax/access, 53 insufficient resources, 57 operator intervention. Alongside the code, PostgreSQL exposes a condition name that is stable across versions. This tool lets you search by SQLSTATE, by class, by condition name (with or without underscores) or by keyword, and shows the class, condition name and meaning for each.

Why match the condition name

In PL/pgSQL you can write WHEN unique_violation THEN instead of hard-coding '23505'. The named form is self-documenting and survives small changes in the standard. Match a whole class with the SQLSTATE class form only when you genuinely want to catch every member, such as all 23xxx constraint violations.

Example

Handling a duplicate insert gracefully in PL/pgSQL:

BEGIN
  INSERT INTO users(email) VALUES ($1);
EXCEPTION
  WHEN unique_violation THEN
    -- SQLSTATE 23505: row already exists, ignore or update
    UPDATE users SET seen_at = now() WHERE email = $1;
END;

The unique_violation handler catches SQLSTATE 23505 and turns a hard failure into an upsert. Everything in this tool runs in your browser; nothing is uploaded.