The list of all the queries

Insufficient number of user-defined triggers+rules

Query goal: There must be user-defined triggers and/or rules for at least n (three in this case) tasks in the database. It also means that one should create at least three triggers and/or rules 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 triggers+rules (three in this case) serves here as an example. It could be replaced with some other threshold. Rules are specific to PostgreSQL and thus it is not possible to get information about these from the INFORMATION_SCHEMA views.
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 triggers or rules.
Data source: INFORMATION_SCHEMA+system catalog
SQL query: Click on query to copy it

WITH activedb AS (SELECT trigger_schema, trigger_name, 'TRIGGER' AS type
FROM information_schema.triggers
WHERE trigger_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)
UNION SELECT r.schemaname,  r.rulename, 'RULE' AS type
FROM 
  pg_catalog.pg_rules r, 
  pg_catalog.pg_namespace n, 
  pg_catalog.pg_authid u
WHERE 
  r.schemaname = n.nspname AND
  n.nspowner = u.oid AND (n.nspname = 'public' OR u.rolname <> 'postgres'))
SELECT 'Too few triggers and/or rules, must be at least three' As comment, (SELECT Count(*) AS cnt FROM activedb) AS the_number_of_triggers_rules
WHERE (SELECT Count(*) AS cnt FROM activedb)<3;

Collections where the query belongs to

Collection nameCollection description
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 where the query belongs to

Category nameCategory description
AssessmentQueries of this category could be used specifically in the learning environment to assess as to whether student projects have filled certain criteria.
Triggers and rulesQueries of this category provide information about triggers and rules in a database.

The list of all the queries