The list of all the queries

Base tables with multiple comment columns

Query goal: Find base tables with more than one comment columns
Query type: General (Overview of some aspect of the database.)
Query license: MIT License
Data source: INFORMATION_SCHEMA only
SQL query: Click on query to copy it

WITH name_cols AS (SELECT table_schema, table_name, column_name, 
CASE WHEN character_maximum_length IS NOT NULL 
THEN data_type || '(' || character_maximum_length || ')'
ELSE data_type END AS data_type, CASE WHEN is_nullable='NO' THEN 'NOT NULL' ELSE 'NULL' END AS not_null,
ordinal_position
FROM INFORMATION_SCHEMA.columns
WHERE column_name ~* '(comment|description|explanation|komment|selgitus|kirjeldus)'
AND (table_schema, table_name) IN (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))
SELECT table_schema, table_name, Count(*) AS nr_of_columns, string_agg(column_name || ' ' || data_type || ' ' || not_null,';<br>' ORDER BY ordinal_position) AS columns
FROM name_cols
GROUP BY table_schema, table_name
HAVING Count(*)>1
ORDER BY Count(*) DESC, table_schema, table_name;

Collections where the query belongs to

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

Category nameCategory description
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

The list of all the queries