## Get column name length distribution in Redshift

Article for:

Query below returns distribution of column name lengths (number of characters).

## Query

``````select length(c.column_name) as column_name_length,
count(*) as columns,
count(distinct c.table_schema || '.' || c.table_name) as tables
from information_schema.columns c
join information_schema.tables t
on t.table_schema = c.table_schema
and t.table_name = c.table_name
where t.table_schema not in ('information_schema', 'pg_catalog')
and t.table_type = 'BASE TABLE'
group by length(c.column_name)
order by length(c.column_name);
``````

## Columns

• column_name_length - lenght in characters of column name
• columns - number of columns with this length
• tables - number of tables that have columns with this name length

## Rows

• One row represents one name lenght (number of characters)
• Scope of rows: each column length that exists in a database
• Ordered by length ascending (from 1 to max)

## Sample results
{"ft_lang_label":"__label__en","ft_lang_prob":0.7526274,"math_prob":0.83189213,"size":871,"snap":"2023-40-2023-50","text_gpt3_token_len":192,"char_repetition_ratio":0.19723183,"word_repetition_ratio":0.0,"special_character_ratio":0.23421355,"punctuation_ratio":0.1369863,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97431624,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-30T15:35:40Z\",\"WARC-Record-ID\":\"<urn:uuid:43cd212b-f358-4b0f-8d89-b4fc2ca1f7a6>\",\"Content-Length\":\"95109\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6d104062-d5a4-4550-85ba-5ffe1cf4d70e>\",\"WARC-Concurrent-To\":\"<urn:uuid:8770a394-b3a4-4634-bbe1-84407d42ba75>\",\"WARC-IP-Address\":\"3.210.151.149\",\"WARC-Target-URI\":\"https://dataedo.com/kb/query/amazon-redshift/column-name-length-distribution\",\"WARC-Payload-Digest\":\"sha1:KO4XPU5XDK5UMAVKHKMUILIJSSAHYJEK\",\"WARC-Block-Digest\":\"sha1:A3IPFUOKHKHHV6YF4AXFQZDHPAU7ZWPL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510697.51_warc_CC-MAIN-20230930145921-20230930175921-00146.warc.gz\"}"}