Skip to content

Instantly share code, notes, and snippets.

@brambow
Created August 30, 2017 18:42
Show Gist options
  • Save brambow/b20fd5a1f3a6c3673245e9ff6618be8b to your computer and use it in GitHub Desktop.
Save brambow/b20fd5a1f3a6c3673245e9ff6618be8b to your computer and use it in GitHub Desktop.
PostgreSQL Data Dictionary
SELECT DISTINCT ON
( table_schema, table_name, ordinal_position ) table_schema,
table_name,
ordinal_position,
column_name,
data_type,
column_default,
is_nullable,
pg_description.description
FROM
information_schema.columns
JOIN pg_catalog.pg_class ON pg_class.relname = columns.table_name
LEFT OUTER JOIN pg_catalog.pg_description ON pg_description.objoid = pg_class.relfilenode
AND pg_description.objsubid = columns.ordinal_position
WHERE
table_schema IN ( 'wq', 'logging' )
ORDER BY
table_schema,
table_name,
ordinal_position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment