The list of all the queries

Triggers with the same name within the same schema

Query goal: Find names of triggers that are used within the same schema more than once. Give different triggers different names.
Notes about the query: In case of the string_agg function, the line break (br) tag is used as a part of the separator for the better readability in case the query result is displayed in a web browser.
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: Give to triggers unique names within a schema. Use table name in the trigger name. Follow a naming convention.
Data source: INFORMATION_SCHEMA+system catalog
SQL query: Click on query to copy it

WITH triggers AS (SELECT tgname AS trigger_name,
nspname AS trigger_schema, 
c.relname as table_name
FROM pg_trigger t INNER JOIN pg_class c ON t.tgrelid=c.oid
INNER JOIN pg_namespace n ON c.relnamespace=n.oid
WHERE 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 tgisinternal='f')
SELECT trigger_name, trigger_schema, Count(*) AS number_of_occurrences, string_agg(table_name, ';<br>' ORDER BY table_name) AS tables
FROM triggers
GROUP BY trigger_name, trigger_schema
HAVING Count(*)>1
ORDER BY Count(*) DESC, trigger_schema, trigger_name;

Collections where the query belongs to

Collection nameCollection description
Find problems about namesA selection of queries that return information about the names of database objects. Contains all the types of queries - problem detection, software measure, and general overview.
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
Comfortability of database evolutionQueries of this category provide information about the means that influence database evolution.
NamingQueries of this category provide information about the style of naming.
Triggers and rulesQueries of this category provide information about triggers and rules in a database.

The list of all the queries