The list of all the queries

Frequency of column name lengths based on the table type

Query goal: Find in case of base tables, materialized views, and views the number of columns based on the length of the column name.
Query type: Sofware measure (Numeric values (software measures) about the database)
Query license: MIT License
Data source: INFORMATION_SCHEMA+system catalog
SQL query: Click on query to copy it

WITH columns AS (SELECT nspname AS table_schema, relname AS table_name, 
CASE WHEN relkind='r' THEN 'BASE TABLE' 
WHEN relkind='m' THEN 'MATERIALIZED VIEW' 
ELSE 'VIEW' END AS table_type, attname AS column_name
FROM pg_class INNER JOIN pg_namespace ON pg_class.relnamespace=pg_namespace.oid
INNER JOIN pg_attribute ON pg_class.oid=pg_attribute.attrelid
WHERE relkind IN ('r', 'm','v') AND attnum>=1 AND 
nspname 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_type, length(column_name) AS length, Count(*) AS nr_of_occurrences, Round(Count(*)::decimal*100/(SELECT Count(*) FROM columns AS c2 WHERE c2.table_type=columns.table_type),1) AS percentage_of_all_columns
FROM columns
GROUP BY table_type, length(column_name)
ORDER BY table_type, length;

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
NamingQueries of this category provide information about the style of naming.

The list of all the queries