The list of all the queries

Domain name and type name are the same

Query goal: Use different names to avoid confusion.
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: Rename the domain so that its name is not the same as the type name.
Data source: INFORMATION_SCHEMA+system catalog
SQL query: Click on query to copy it

WITH domain_names AS (SELECT domain_schema, domain_name
FROM information_schema.domains
WHERE domain_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)),
type_names AS (SELECT nspname AS type_schema, typname AS type_name
FROM pg_catalog.pg_type t INNER JOIN pg_catalog.pg_namespace n ON t.typnamespace=n.oid
WHERE typtype<>'d')
SELECT domain_schema, domain_name, type_schema, type_name
FROM domain_names, type_names
WHERE lower(domain_name)=lower(type_name)
ORDER BY domain_schema, domain_name;

SQL statements for generating SQL statements that help us to fix the problem

SQL queryDescription
WITH domain_names AS (SELECT domain_schema, domain_name
FROM information_schema.domains
WHERE domain_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)),
type_names AS (SELECT nspname AS type_schema, typname AS type_name
FROM pg_catalog.pg_type t INNER JOIN pg_catalog.pg_namespace n ON t.typnamespace=n.oid
WHERE typtype<>'d')
SELECT format('ALTER DOMAIN %1$I.%2$I RENAME TO d_%2$I;', domain_schema, domain_name) AS statements
FROM domain_names, type_names
WHERE lower(domain_name)=lower(type_name)
ORDER BY domain_schema, domain_name;
Rename the domain so that the new name has prefix "d_".

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
Data typesQueries of this category provide information about the data types and their usage.
DomainsQueries of this category provide information about reusable specifications of column properties.
NamingQueries of this category provide information about the style of naming.

The list of all the queries