Rename the domain so that its name is not the same as the type name.
Data Source
INFORMATION_SCHEMA+system catalog
SQL Query
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 that help generate fixes for the identified problem.
SQL Query to Generate Fix
Description
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
This query belongs to the following collections:
Name
Description
Find problems automatically
Queries, 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:
Name
Description
Data types
Queries of this category provide information about the data types and their usage.
Domains
Queries of this category provide information about reusable specifications of column properties.
Naming
Queries of this category provide information about the style of naming.