Goal Find columns of base and foreign tables that based on the column names and types are used to register start time and duration rather than start time and end time.
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)
Reliability Medium (Medium number of false-positive results)
License MIT License
Fixing Suggestion Instead of registering duration, register start and end times. One can always calculate the duration based on these values.
Data Source INFORMATION_SCHEMA only
SQL Query
SELECT table_type, table_schema, table_name, column_name,  data_type, character_maximum_length
FROM INFORMATION_SCHEMA.columns AS c INNER JOIN INFORMATION_SCHEMA.tables USING (table_schema, table_name)
WHERE data_type~*'(char|text|integer|smallint|bigint|numeric|decimal|real|float|double precision)'
AND column_name~*'(^|_)(kestus|kestvus|duration)$'
AND table_type IN( 'BASE TABLE','FOREIGN') 
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 EXISTS (SELECT * 
FROM INFORMATION_SCHEMA.columns AS c2
WHERE c.table_schema=c2.table_schema
AND c.table_name=c2.table_name
AND c2.column_name~*'(algus|beginning|start)$'
AND c2.data_type~*'(date|timestamp)')
ORDER BY table_type, table_schema, table_name, ordinal_position;

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 .
Find problems by overviewQueries that results point to different aspects of database that might have problems. A human reviewer has to decide based on the results as to whether there are problems or not .
Categories

This query is classified under the following categories:

NameDescription
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.
Structure of base tablesQueries of this category provide information about the structuring of base tables at the database conceptual level

Further reading and related materials:

Reference
Factor, P.: SQL Code Smells. Redgate, http://assets.red-gate.com/community/books/sql-code-smells.pdf, last accessed 2019/12/29 (Storing a duration rather than a point in time)