Goal This query identifies potential redundancy or ambiguity in the schema by detecting pairs of user-defined domain names with high textual similarity. It utilizes the Levenshtein distance algorithm to find name pairs that differ by fewer than two characters. Crucially, the query implements a filter to exclude pairs where the divergence is attributable solely to numerical digits. This heuristic prevents false positives for valid domain variations based on size or version (e.g., d_name_20 vs. d_name_50), focusing the analysis strictly on likely typographical errors or semantic duplicates.
Notes 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 translate(d1.domain_name,'0123456789','')<>translate(d2.domain_name,'0123456789','')
AND levenshtein(d1.domain_name,d2.domain_name)<=1
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.