List columns by name length in Redshift

This query returns columns in a database sorted by their name length.

Query

select c.column_name,
    length(c.column_name) as column_name_length,
    c.table_schema,
    c.table_name
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'
order by column_name_length desc,
         column_name;

Columns

  • column_name - column name
  • column_name_length - column name length
  • table_schema - column table schema name
  • table_name - column table name

Rows

  • One row represents one column of each table in a database
  • Scope of rows: each column that exists in a database
  • Ordered by length descrending - from longest to shortest

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.