The list of all the queries

Perhaps a CHECK constraint about required personal name components is missing

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'
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;

Collections where the query belongs to

Collection nameCollection description
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 where the query belongs to

Category nameCategory description
CHECK constraintsQueries of this category provide information about CHECK constraints.
Result quality depends on namesQueries 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 completenessQueries 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).

The list of all the queries