Skip to content

Instantly share code, notes, and snippets.

@jonmathews
Created July 11, 2020 15:42
Show Gist options
  • Save jonmathews/611b77634a4d96b5220406b6a2424880 to your computer and use it in GitHub Desktop.
Save jonmathews/611b77634a4d96b5220406b6a2424880 to your computer and use it in GitHub Desktop.
Get all column description/comments from Postgres
WITH tables
AS (SELECT oid,
relname AS table
FROM pg_class),
columns
AS (SELECT ordinal_position AS objsubid,
table_name AS table,
column_name AS column
FROM information_schema.columns)
SELECT t.table,
c.COLUMN,
d.description
FROM pg_catalog.pg_description d
LEFT JOIN tables t
ON d.objoid = t.oid
LEFT JOIN columns c
ON d.objsubid = c.objsubid
AND t.table = c.table
WHERE d.objsubid > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment