E0037 check-constraint-violation
Literal value that violates a CHECK constraint in INSERT ... VALUES or UPDATE ... SET.
| Code | Name | Category | Default |
|---|---|---|---|
E0037 | check-constraint-violation | correctness | error |
What it reports
An INSERT ... VALUES or UPDATE ... SET statement where every column a CHECK constraint reads is assigned a literal or constant expression in the same row, and evaluating the constraint definitely yields false.
In SQL, a CHECK constraint passes if its condition evaluates to TRUE or NULL (unknown); it rejects the row only when it evaluates to FALSE. In PostgreSQL, SQLite, and MySQL (since 8.0.16), writing a literal that violates a CHECK constraint is rejected at runtime by the database engine.
Example
Given a table with CHECK constraints:
CREATE TABLE users (
id INT PRIMARY KEY,
age INT CONSTRAINT users_age_check CHECK (age >= 0),
status TEXT CONSTRAINT users_status_check CHECK (status IN ('active', 'banned'))
);
An invalid insert:
INSERT INTO users (id, age) VALUES (1, -1);
error[E0037]: Value violates check constraint 'users_age_check' for table 'users'
--> q.sql:1:36
|
1 | INSERT INTO users (id, age) VALUES (1, -1);
| ^^
= help: Ensure assigned values satisfy 'users_age_check' (age >= 0)
Or an invalid update:
UPDATE users SET status = 'actve' WHERE id = 1;
error[E0037]: Value violates check constraint 'users_status_check' for table 'users'
--> q.sql:1:27
|
1 | UPDATE users SET status = 'actve' WHERE id = 1;
| ^^^^^^^
= help: Ensure assigned values satisfy 'users_status_check' (status IN ('active', 'banned'))
When it is not reported
Nothing is reported when:
- A column in the
CHECKconstraint is assigned a non-constant expression (such asNOW(), another column, or a query parameter), because its runtime value cannot be statically determined. - Not all columns referenced by a multi-column
CHECKconstraint are assigned in the statement (for instance, anUPDATEthat changes only one of two columns compared byCHECK (lo <= hi)). - The
CHECKconstraint evaluates toNULL(for example, insertingNULLinto a column withCHECK (age >= 0)). In SQL,NULLsatisfiesCHECKconstraints. - Any referenced column is not a plain integer, numeric/decimal, or text/varchar column (e.g. date, timestamp, enum, boolean, floating-point, or untyped columns where engine coercion and collation semantics vary), or has an explicit
COLLATEclause. - For string columns, comparisons other than
=,<>, andIN, or string comparisons in MySQL (where default collations are case-insensitive). - Numeric literals whose fractional scale exceeds the column's scale (which databases round).
- The constraint is marked
NOT ENFORCEDor was dropped withALTER TABLE ... DROP CONSTRAINT. - Running in dialects that treat
CHECKconstraints as informational or unenforced (such as Snowflake or Redshift).
How to fix it
Provide literal values that satisfy the condition:
INSERT INTO users (id, age) VALUES (1, 18);
UPDATE users SET status = 'active' WHERE id = 1;
To silence for an individual statement:
-- sqlsift:disable check-constraint-violation
INSERT INTO users (id, age) VALUES (1, -1);
Or in sqlsift.toml:
[rules]
check-constraint-violation = "off"