Query goal: | Find base tables that have optional columns for recording both given name and surname and do not have a CHECK constraint that requires that at least one of the name components must be registered in case of each person. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | Medium (Medium number of false-positive results) |
Query license: | MIT License |
Data source: | INFORMATION_SCHEMA+system catalog |
SQL query: | Click on query to copy it
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.tables WHERE table_type='BASE TABLE' AND table_schema NOT IN (SELECT schema_name FROM INFORMATION_SCHEMA.schemata WHERE schema_name<>'public' AND schema_owner='postgres' AND schema_name IS NOT NULL) AND (table_schema, table_name) IN (SELECT table_schema, table_name FROM information_schema.columns WHERE column_name~*'^[_]*(eesnimi|firstname|first_name|given_name|givenname)[_]*$' AND is_nullable='YES') AND (table_schema, table_name) IN (SELECT table_schema, table_name FROM information_schema.columns WHERE column_name~*'^[_]*(perenimi|perekonnanimi|given_name|givenname|surname|family_name|last_name|lastname)[_]*$' AND is_nullable='YES') AND (table_schema, table_name) NOT IN (select (select nspname from pg_namespace where oid=c.relnamespace) as target_schema, c.relname as target_table from pg_constraint o inner join pg_class c on c.oid = o.conrelid where o.contype = 'c' and cardinality(o.conkey)>1 and (substring(pg_get_constraintdef(o.oid),7)~*'is[[:space:]]+not[[:space:]]+null' or substring(pg_get_constraintdef(o.oid),7)~*'(?<=not.*)is[[:space:]]+null') and substring(pg_get_constraintdef(o.oid),7)~*'(eesnimi|firstname|first_name|given_name|givenname)' and substring(pg_get_constraintdef(o.oid),7)~*'(perenimi|perekonnanimi|given_name|givenname|surname|family_name|last_name|lastname)') ORDER BY table_schema, table_name; |
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 |
---|---|
CHECK constraints | Queries of this category provide information about CHECK constraints. |
Result quality depends on names | Queries of this category use names (for instance, column names) to try to guess the meaning of a database object. Thus, the goodness of names determines the number of false positive and false negative results. |
Validity and completeness | Queries of this category provide information about whether database design represents the world (domain) correctly (validity) and whether database design captures all the information about the world (domain) that is correct and relevant (completeness). |