Skip to content

Instantly share code, notes, and snippets.

@afranzi
Created February 24, 2020 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afranzi/8ac17873b1ede37a99c907cdd5178d6f to your computer and use it in GitHub Desktop.
Save afranzi/8ac17873b1ede37a99c907cdd5178d6f to your computer and use it in GitHub Desktop.
Redshift - Retrieve table descriptions
SELECT
t.table_catalog as cluster,
t.table_schema as schema_name,
t.table_name as table_name,
t.table_type as table_type,
pt.tableowner as table_owner,
pgtd.description as description
FROM
information_schema.tables as t
INNER JOIN pg_catalog.pg_statio_all_tables as st on
t.table_schema = st.schemaname
and t.table_name = st.relname
LEFT JOIN pg_catalog.pg_description pgtd on
pgtd.objoid = st.relid
and pgtd.objsubid = 0
LEFT JOIN pg_tables pt ON t.table_schema = pt.schemaname AND t.table_name = pt.tablename
WHERE table_schema IN ('{{ params.schemas | join("','") }}')
ORDER by
cluster,
schema_name,
table_name
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment