PostgreSQL error code
PostgreSQL error 44000
44000 is the SQLSTATE PostgreSQL reports for with check option violation, in class 44, WITH CHECK OPTION Violation.
| SQLSTATE | 44000 |
|---|---|
| Condition name | with_check_option_violation |
| Class | 44 — WITH CHECK OPTION Violation |
Reproduce it, then fix it
WITH CHECK OPTION stops changes through the view that would push a row out of it, and a customer moved to CA would no longer be a US customer. Make the change on the table. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
CREATE VIEW us_customers AS SELECT * FROM customers WHERE country = 'US' WITH CHECK OPTION; UPDATE us_customers SET country = 'CA' WHERE id = 1;
CREATE VIEW us_customers AS SELECT * FROM customers WHERE country = 'US' WITH CHECK OPTION; UPDATE customers SET country = 'CA' WHERE id = 1 RETURNING id, country;