Goal There must be at least n (four in this case) user-defined non-trigger routines in the database.
Notes This query implements a requirement that might occur in a learning situation. The condition in the query ensures that if the requirement is not fulfilled, then the query returns one row, otherwise it does not return a row. The result is achieved by using a PostgreSQL feature that permits SELECT statements without the FROM clause. The number of routines (four in this case) serves here as an example. It could be replaced with some other threshold. The query does not consider the routines that are a part of an extension.
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
Fixing Suggestion Create additional routines.
Data Source INFORMATION_SCHEMA+system catalog
SQL Query
WITH routines AS (SELECT 
  routines.routine_schema, 
  routines.routine_name
FROM 
  information_schema.routines
WHERE routine_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL) AND (data_type<>'trigger' OR data_type IS NULL)
AND NOT EXISTS (SELECT 1
FROM pg_catalog.pg_depend d inner join pg_catalog.pg_proc pc ON d.objid=pc.oid
WHERE EXISTS (SELECT 1 FROM pg_catalog.pg_extension e WHERE d.refobjid=e.oid) AND
pc.proname || '_' || pc.oid = routines.specific_name) 
 AND routine_name NOT IN ('f_assume_you_must_use_files', 'f_check_format_comma_separated_list', 'f_check_password', 'f_default_value_with_no_match'))
SELECT 'Too few user-defined routines, must be at least four' As comment, (SELECT Count(*) AS cnt FROM Routines) AS number_of_routines
WHERE (SELECT Count(*) AS cnt FROM routines)<4;

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 .
Categories

This query is classified under the following categories:

NameDescription
AssessmentQueries of this category could be used specifically in the learning environment to assess as to whether student projects have filled certain criteria.
User-defined routinesQueries of this category provide information about the user-defined routines