Query goal: | There must be at least n (four in this case) user-defined non-trigger routines in the database. |
Notes about the query: | 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. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | High (Few or no false-positive results) |
Query license: | MIT License |
Fixing suggestion: | Create additional routines. |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
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; |
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 |
---|---|
Assessment | Queries of this category could be used specifically in the learning environment to assess as to whether student projects have filled certain criteria. |
User-defined routines | Queries of this category provide information about the user-defined routines |