# Constraint Error: A CHECK constraint rejected the row

> An INSERT or UPDATE produced a row that failed a CHECK expression declared on the table.

Source: https://sqlly.app/errors/duckdb/constraint-check
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Exception: `Constraint Error`
- Category: Constraint Error

Error message:

```text
Constraint Error: CHECK constraint failed on table "t" with expression CHECK((a > 0))
```

## What it means

A CHECK constraint is an expression evaluated per row on INSERT and UPDATE. When it comes out false, DuckDB rejects the row and the whole statement fails: in a multi-row insert nothing lands. NULL passes, as in standard SQL, because a CHECK only rejects rows where the expression evaluates false.

The message shows the table and the exact expression, which is usually enough to see what was refused. When the expression itself throws instead of returning false, for example a cast inside the CHECK, recent DuckDB versions append the inner error as `(Error: ...)`, so read that part too.

## Common causes

- An INSERT or UPDATE with a value the expression refuses, such as a negative quantity or a date before a lower bound.
- A default that itself violates the CHECK, so omitting the column fails the insert.
- A COPY or INSERT INTO ... SELECT where some source rows fail the expression even though the statement as a whole looks correct.
- An UPDATE that changes one column of a multi-column CHECK and leaves the row inconsistent.

## How to fix it

1. List the rows that would fail before inserting. NULLs pass, so the check excludes them:

   ```sql
   SELECT * FROM stage
   WHERE quantity IS NOT NULL AND NOT (quantity > 0);
   ```
2. Repair or filter the source, then insert:

   ```sql
   INSERT INTO orders
   SELECT * FROM stage WHERE quantity > 0;
   ```
3. DuckDB cannot add or drop a CHECK with ALTER TABLE, so a wrong constraint means rebuilding the table:

   ```sql
   CREATE TABLE orders_new (quantity INTEGER CHECK (quantity > 0));
   INSERT INTO orders_new SELECT * FROM orders;
   ALTER TABLE orders RENAME TO orders_old;
   ALTER TABLE orders_new RENAME TO orders;
   ```

## Reproduce it safely

```sql
CREATE TABLE t(a INT CHECK (a > 0));
INSERT INTO t VALUES (0);   -- Constraint Error: CHECK constraint failed on table "t" with expression CHECK((a > 0))
```

## Questions

### Does NULL pass a CHECK constraint?

Yes. A CHECK rejects only rows where the expression evaluates false. To forbid NULL as well, declare the column NOT NULL.

### Which row failed?

The message names the constraint, not the row, and the statement fails as a whole. Run the insert as a SELECT with NOT (expression) against the source to list the offending rows.

## Related errors

- [`Constraint Error`](https://sqlly.app/errors/duckdb/constraint-not-null): A NOT NULL column received NULL
- [`Constraint Error`](https://sqlly.app/errors/duckdb/constraint-unique): A duplicate key violates a unique constraint
- [`23514`](https://sqlly.app/errors/postgresql/23514): PostgreSQL: check constraint violation
- [`SQLITE_CONSTRAINT`](https://sqlly.app/errors/sqlite/sqlite-constraint): SQLite: constraint failed

The code and message text are from the [DuckDB documentation](https://duckdb.org/docs/).
