Goal Find user-defined routines that have a comment registered by the COMMENT statement and a comment within the routine body. Make sure that there are no inconsistencies between the comments.
Notes Refers to the column pg_proc.prokind and thus works starting from PostgreSQL 11. The query finds routines that have a comment inside their body as well have a comment that has been associated with it with the COMMENT statement. The query does not consider the routines that are a part of an extension. 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.
Type General (Overview of some aspect of the database.)
License MIT License
Fixing Suggestion Put comments in one place.
Data Source INFORMATION_SCHEMA+system catalog
SQL Query
SELECT 
  n.nspname AS routine_schema, 
  p.proname AS routine_name,
pg_get_function_identity_arguments(p.oid) AS parameters,
  CASE WHEN p.prokind='f' THEN 'FUNCTION'
  WHEN p.prokind='p' THEN 'PROCEDURE'
  WHEN p.prokind='w' THEN 'WINDOW FUNCTION' END AS routine_type,
regexp_replace(regexp_replace(pg_get_functiondef(p.oid),'<','<','g'),'[\r\n]','
','g') AS routine_src, d.description AS comment FROM (pg_catalog.pg_proc p JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.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 p.prokind<>'a' 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 d.description IS NOT NULL AND pg_get_functiondef(p.oid)~*'(/[*]|--)' 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) ORDER BY routine_schema, routine_name, parameters;
Collections

This query belongs to the following collections:

NameDescription
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 .
Lexicon bad smells and linguistic antipatternsQueries made to find the occurrences of lexicon bad smells and linguistic antipatterns
Categories

This query is classified under the following categories:

NameDescription
Comfortability of database evolutionQueries of this category provide information about the means that influence database evolution.
CommentsQueries of this category provide information about comments to the database objects that have been registered in the system catalog.
InconsistenciesQueries of this catergory provide information about inconsistencies of solving the same problem in different places.
User-defined routinesQueries of this category provide information about the user-defined routines

Further reading and related materials:

Reference
https://blog.codinghorror.com/code-tells-you-how-comments-tell-you-why/