Skip to content

Instantly share code, notes, and snippets.

@a88zach
Created July 30, 2019 15:05
Show Gist options
  • Save a88zach/580cf94713801bec16b790dd0b3f8298 to your computer and use it in GitHub Desktop.
Save a88zach/580cf94713801bec16b790dd0b3f8298 to your computer and use it in GitHub Desktop.
select table_schema,
table_name,
column_name,
data_type,
character_maximum_length,
(xpath('/row/max/text()',query_to_xml(format('select max(length(%I)) from %I.%I', column_name, table_schema, table_name), true, true, '')))[1]::text::int as max_length
from information_schema.columns
where table_schema = 'ccxp'
and data_type = 'character varying'
order by table_schema, table_name, column_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment