Goal Find pairs of names of domains that are very similar or even equal.
Notes The query finds the pairs of domain names where the Levenshtein distance between the names is less than three. The query uses a function from the fuzzystrmatch extension.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability Medium (Medium number of false-positive results)
License MIT License
Fixing Suggestion Make sure that the names are correct and there are no duplication or unused domains.
Data Source INFORMATION_SCHEMA only
SQL Query
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
WITH domains 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))
SELECT d1.domain_schema AS domain1_schema, d1.domain_name AS domain1_name,
d2.domain_schema AS domain2_schema, d2.domain_name AS domain2_name
FROM domains AS d1, domains AS d2
WHERE NOT (d1.domain_schema=d2.domain_schema AND d1.domain_name=d2.domain_name)
AND levenshtein(d1.domain_name,d2.domain_name)<=2
ORDER BY domain1_name, domain2_name;

DROP EXTENSION IF EXISTS fuzzystrmatch;
Collections

This query belongs to the following collections:

NameDescription
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
DomainsQueries of this category provide information about reusable specifications of column properties.
Duplication of implementation elementsQueries of this catergory provide information about the duplication of the database objects.
NamingQueries of this category provide information about the style of naming.
Unused implementation elementsQueries of this catergory provide information about the database objects that are not used.