The list of all the queries

Names of constraints (directly connected to a base table) that do not contain the table name

Query goal: Find constraints that are perhaps badly named. Table names help us to ensure the uniqueness of the names within a schema and make the names more expressive and user-friendly.
Notes about the query: The query considers only locally-defined constraints, i.e., constraints that are not inherited. The query considers a possibility that underscores (_) in the table name have been removed from the constraint/index name.
Query type: Problem detection (Each row in the result could represent a flaw in the design)
Query reliability: Medium (Medium number of false-positive results)
Query license: MIT License
Fixing suggestion: Use the table name in the constraint names and index names. A problem is that by default a PostgreSQL identifier may be at most 63 bytes long. Thus, in case of long table names one may have to shorten the name in the constraint or index names. It is important to do this consistently. Do not shorten the table name.
Data source: system catalog only
SQL query: Click on query to copy it

WITH constraint_names AS (
select 
case when o.contype='p' then 'PRIMARY KEY'
when o.contype='u' then 'UNIQUE'
when o.contype='f' then 'FOREIGN KEY'
when o.contype='c' then 'TABLE CHECK'
when o.contype='x' then 'EXCLUDE'
when o.contype='t' then 'CONSTRAINT TRIGGER' END AS constraint_type,
(select nspname from pg_namespace where oid=o.connamespace) as table_schema,
c.relname AS table_name,
o.conname AS constraint_name
from pg_constraint o inner join pg_class c on c.oid = o.conrelid
where o.contype in ('p','u','c','f','x')
and conislocal=true)

SELECT constraint_type, table_schema, table_name, constraint_name
FROM constraint_names
WHERE constraint_name NOT ILIKE  '%' || table_name || '%'
AND translate(constraint_name,'_','') NOT ILIKE  '%' || translate(table_name,'_','') || '%'
ORDER BY constraint_type, table_schema, table_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.

Reference materials for further reading

Reference
https://dba.stackexchange.com/questions/152510/enforce-constraint-name-uniqueness
https://www.postgresql.org/message-id/3724.1094436837%40sss.pgh.pa.us

The list of all the queries