Find updatable views that do not have WITH CHECK OPTION constraint. WITH CHECK OPTION constraint prevents updates through the view that violate the predicate of the view. Such updates must be prevented.
Type
Problem detection (Each row in the result could represent a flaw in the design)
Recreate the view with the WITH CHECK OPTION constraint.
Data Source
INFORMATION_SCHEMA only
SQL Query
SELECT table_schema AS view_schema, table_name AS view_name, is_updatable, is_insertable_into
FROM Information_schema.views
WHERE (is_insertable_into='YES' OR is_updatable='YES') AND check_option='NONE'
AND table_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)
ORDER BY table_schema, table_name;
SQL statements that help generate fixes for the identified problem.
SQL Query to Generate Fix
Description
SELECT format('CREATE OR REPLACE VIEW %1$I.%2$I WITH(security_barrier) AS %3$s WITH CHECK OPTION;', table_schema, table_name, rtrim(view_definition, ';')) AS statements
FROM Information_schema.views
WHERE (is_insertable_into='YES' OR is_updatable='YES') AND check_option='NONE'
AND table_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)
ORDER BY table_schema, table_name;
Recreate the view with the WITH CHECK OPTION constraint.
Collections
This query belongs to the following collections:
Name
Description
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
Categories
This query is classified under the following categories:
Name
Description
Derived tables
Queries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer.
Security
Queries of this category provide information about the security measures.