Query goal: | Find views, materialized views, and user-defined routines that do not have a comment at all or the comment is shorter than twice the length of the object name, or the comment states that it is missing (TODO). You should give information to future developers and maintainers of the system (including the future version of yourself). Do not just repeat the name in the comment (with perhaps some rewording). |
Notes about the query: | Refers to the column pg_proc.prokind and thus works starting from PostgreSQL 11. There could be multiple routines with the same name but with different parameters in the same schema (overloading). Thus, for the unique identification of the routine it is necessary to present also its parameters in addition to the schema name and routine name. The query does not find comments of routines that are added to a database as a part of an extension. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | Medium (Medium number of false-positive results) |
Query license: | MIT License |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
SELECT CASE WHEN relkind='m' THEN 'MATERIALIZED VIEW' ELSE 'VIEW' END AS object_type, n.nspname AS schema_name, c.relname AS object_name, d.description AS comment FROM pg_catalog.pg_class c JOIN pg_catalog.pg_authid u ON u.oid = c.relowner JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_catalog.pg_description d ON c.oid=d.objoid WHERE c.relkind IN ('v', 'm') AND (n.nspname = 'public' OR u.rolname <> 'postgres') AND (d.description IS NULL OR char_length(c.relname)*2>=char_length(d.description) OR d.description~*'todo') UNION SELECT CASE WHEN p.prokind='f' THEN 'FUNCTION' WHEN p.prokind='p' THEN 'PROCEDURE' WHEN p.prokind='a' THEN 'AGGREGATE FUNCTION' WHEN p.prokind='w' THEN 'WINDOW FUNCTION' END AS object_type, n.nspname AS routine_schema, p.proname || '(' || pg_get_function_identity_arguments(p.oid) || ')' AS object_name, d.description AS comment FROM (pg_catalog.pg_proc p JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid) JOIN pg_catalog.pg_language l ON p.prolang=l.oid LEFT JOIN pg_catalog.pg_description d ON p.oid=d.objoid WHERE p.proname NOT IN ('f_assume_you_must_use_files', 'f_check_format_comma_separated_list', 'f_check_password', 'f_default_value_with_no_match') AND n.nspname NOT IN (SELECT schema_name FROM INFORMATION_SCHEMA.schemata WHERE schema_name<>'public' AND schema_owner='postgres' AND schema_name IS NOT NULL) AND l.lanname IN ('sql','plpgsql') AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d WHERE EXISTS (SELECT 1 FROM pg_catalog.pg_extension e WHERE d.refobjid=e.oid) AND d.objid=p.oid) AND (d.description IS NULL OR char_length(p.proname)*2>=char_length(d.description) OR d.description~*'todo') ORDER BY object_type, schema_name, object_name; |
Collection name | Collection 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 . |
Category name | Category description |
---|---|
Comfortability of database evolution | Queries of this category provide information about the means that influence database evolution. |
Comments | Queries of this category provide information about comments to the database objects that have been registered in the system catalog. |
Derived tables | Queries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer. |
User-defined routines | Queries of this category provide information about the user-defined routines |