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 query | 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_". |
Collection name | Collection 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 . |
Category name | Category 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. |