PostgreSQL WITH CHECK OPTION (Views)
PostgreSQL WITH CHECK OPTION (Views) is a SQL statement in the Views category. WITH CHECK OPTION prevents INSERT/UPDATE through a view that would produce rows invisible to the view. The syntax is CREATE VIEW v AS SELECT * FROM t WHERE condition WITH CHECK OPTION;. It returns view with check option. A typical example: CREATE VIEW high_value_products AS SELECT * FROM products WHERE price > 100 WITH CHECK OPTION; -- This INSERT works: INSERT INTO high_value_products (id, name, price) VALUES (1, 'Premium Widget', 199.99); -- This INSERT FAILS: INSERT INTO high_value_products (id, name, price) VALUES (2, 'Cheap Widget', 9.99); -- ERROR: new row violates WITH CHECK OPTION -- price=9.99 would not be visible in the view -- Without CHECK OPTION, the cheap widget would… A close relative is CREATE VIEW, which creates a virtual table based on a SELECT query. Think of it as a saved query that acts like a table.