Goal This query identifies automatically updatable views that define a row restriction (via a WHERE clause) but lack the WITH CHECK OPTION constraint. In the absence of this constraint, it is possible to perform INSERT or UPDATE operations through the view that result in rows satisfying the base table constraints but failing the view's inclusion criteria. This leads to "phantom updates," where the modified data is committed to the database but immediately disappears from the view's scope. Enforcing WITH CHECK OPTION ensures that all modifications performed through the view respect its defining predicate.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability High (Few or no false-positive results)
License MIT License
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 view_definition~*'WHERE[[:space:]]'
AND (view_definition!~*'(JOIN|DISTINCT|GROUP|UNION|INTERSECT|EXCEPT|HAVING|WHERE.*[_[:alnum:]]+\.[_[:alnum:]]+[[:space:]]*=[[:space:]]*[_[:alnum:]]+\.[_[:alnum:]]+|LIMIT|OFFSET|FETCH[[:space:]]FIRST)'
AND view_definition!~*'(sum|count|avg|min|max|over)[[:space:]]{0,1}[(]')
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;

Collections

This query belongs to the following collections:

NameDescription
Find problems automaticallyQueries, 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 .
Find problems by overviewQueries that results point to different aspects of database that might have problems. A human reviewer has to decide based on the results as to whether there are problems or not .
Categories

This query is classified under the following categories:

NameDescription
Derived tablesQueries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer.
SecurityQueries of this category provide information about the security measures.