Goal Find table names that are the same as some routine name. Use different names to avoid confusion.
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 Rename the table or the routine.
Data Source INFORMATION_SCHEMA+system catalog
SQL Query
WITH routine_names AS (SELECT specific_schema AS routine_schema, routine_name
FROM information_schema.routines
WHERE specific_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)),
table_names AS (SELECT A.table_schema, A.table_name, A.table_type 
FROM INFORMATION_SCHEMA.tables A
INNER JOIN INFORMATION_SCHEMA.schemata B
ON A.table_schema=B.schema_name
WHERE (A.table_schema = 'public'
OR B.schema_owner<>'postgres')
UNION SELECT schemaname, matviewname, 'MATERIALIZED VIEW' AS table_type
FROM pg_catalog.pg_matviews)
SELECT table_schema, table_name, table_type, routine_schema, routine_name
FROM table_names, routine_names
WHERE lower(routine_name)=lower(table_name)
ORDER BY table_schema, table_name;

Collections

This query belongs to the following collections:

NameDescription
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

This query is classified under the following categories:

NameDescription
Derived tablesQueries of this category provide information about the derived tables (views, materialized views), which are used to implement virtual data layer.
NamingQueries of this category provide information about the style of naming.
User-defined routinesQueries of this category provide information about the user-defined routines