SQLSTATE 23514 ERROR Class 23: Integrity Constraint Violation

check_violation Check Violation — SQLSTATE 23514

A row failed a CHECK constraint.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Symptoms

A row failed a CHECK constraint.

  • The error is written to the server log and returned to the client carrying SQLSTATE 23514.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN check_violation THEN.

Environment

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).

Root Cause

The value did not satisfy a CHECK expression on the table or a domain.

Common causes:

  • Data outside the allowed range or set.
  • A newly added constraint that existing or incoming data violates.
  • A domain constraint on the type.

Diagnostic Queries

Recovery

Steps to resolve 23514:

  1. Read the constraint: SELECT conname, pg_get_constraintdef(oid) FROM pg_constraint WHERE conname = '...';.
  2. Correct the input data to satisfy the rule.
  3. If the rule itself is wrong, alter or drop the constraint.
  4. On large tables add it as NOT VALID, fix data, then VALIDATE CONSTRAINT.

Reference: PostgreSQL error codes — Class 23 (Integrity Constraint Violation).

Was this helpful?