Error 23514 signals that an INSERT or UPDATE row failed a CHECK constraint.
PostgreSQL Error 23514 – check_violation – means the data you tried to write breaks a CHECK constraint on the table. Fix it by either correcting the offending values or altering the constraint so that it matches real-world data.
PostgreSQL Error 23514
The server returns SQLSTATE 23514 when a row fails a CHECK constraint during INSERT or UPDATE. The message names the table, the failed constraint, and the offending column values.
A CHECK constraint contains a Boolean expression that must evaluate to true for every row.
When the expression evaluates to false or NULL, PostgreSQL raises check_violation and aborts the statement.
Most occurrences stem from bad data that falls outside an allowed range, regex pattern, or cross-column rule defined in the CHECK clause.
The error can also arise when application logic changes without updating constraints, or when bulk loads bypass validation logic assumed by the database designer.
First, inspect the failing values shown in the error.
Adjust your INSERT or UPDATE to comply with the constraint.
If the business rule changed, alter the constraint instead. Run ALTER TABLE ... DROP CONSTRAINT then add a revised CHECK clause.
Galaxy’s AI copilot can suggest the correct SQL quickly.
Negative quantity rejected by quantity_positive CHECK – update the row with a non-negative number.
Incorrect ISO code blocked by country_code_format CHECK – validate input client-side and add a BEFORE INSERT trigger if needed.
Validate data in application code and use parameterized queries so only compliant values reach the database.
Version constraints alongside code.
Galaxy Collections let teams endorse the latest constraint-aware queries, reducing drift.
Error 23505 unique_violation appears when a UNIQUE or PRIMARY KEY rule fails. Resolve it by changing values or handling duplicates.
Error 23502 not_null_violation fires when NULL is inserted into a NOT NULL column. Supply a value or relax the column definition.
.
Yes, set session_replication_role to replica or drop the constraint, but always re-validate afterward.
No. Triggers and CHECK constraints are independent. Disabling triggers will not bypass CHECK enforcement.
Query pg_constraint or use \d+ table_name in psql to list them.
Galaxy’s AI copilot surfaces table metadata and constraint definitions inline, helping you craft compliant queries before they run.