Skip to content

Instantly share code, notes, and snippets.

@dinnouti
Last active June 10, 2020 20:19
Show Gist options
  • Save dinnouti/42fc670017ab3e75681a1fbb375b9165 to your computer and use it in GitHub Desktop.
Save dinnouti/42fc670017ab3e75681a1fbb375b9165 to your computer and use it in GitHub Desktop.
Redshift - Listing tables, views, columns from database information schema
SELECT
t.table_schema
, t.table_name
, c.column_name
, c.data_type
, CASE
WHEN c.character_maximum_length IS NOT NULL THEN c.character_maximum_length
ELSE c.numeric_precision
END AS max_length
, is_nullable
FROM information_schema.tables t
JOIN information_schema.columns c ON t.table_schema = c.table_schema AND t.table_name = c.table_name
WHERE t.table_schema NOT IN ('information_schema', 'pg_catalog')
ORDER BY 1, 2, 3
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment