Find base table columns with VARCHAR type that name refers to the possibility that these are used to register national identification numbers (personal codes). Find the columns where the field size is shorter than 20.
Notes
The query considers both column names in English and Estonian.
Type
Problem detection (Each row in the result could represent a flaw in the design)
Change the field size of the column so that the field size is least 50.
Data Source
INFORMATION_SCHEMA only
SQL Query
SELECT c.table_schema, c.table_name, c.column_name, c.data_type, c.character_maximum_length
FROM information_schema.columns AS c
WHERE (c.table_schema, c.table_name) IN (SELECT table_schema, table_name
FROM INFORMATION_SCHEMA.tables WHERE table_type='BASE TABLE') AND
c.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 c.column_name~*'^(isik[u_ ]*kood|person[_ ]*code|personal[_ ]*code|(national|nat)[_ ]*identification[_ ]*(number|nr)|(national|nat)[_ ]*identity[_ ]*(number|nr)|(national|nat)[_ ]*insurance[_ ]*(number|nr))$'
AND (c.data_type='character varying') AND (c.character_maximum_length<20)
ORDER BY c.table_schema, c.table_name, c.column_name;
Collections
This query belongs to the following collections:
Name
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 .
Categories
This query is classified under the following categories:
Name
Description
Data types
Queries of this category provide information about the data types and their usage.
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).