Skip to content

Instantly share code, notes, and snippets.

@ycku
Created February 2, 2021 09:41
Show Gist options
  • Save ycku/659bbf366dc1e516f167a4abbce16c06 to your computer and use it in GitHub Desktop.
Save ycku/659bbf366dc1e516f167a4abbce16c06 to your computer and use it in GitHub Desktop.
PostgreSQL show comments of all column in the specified table by query
-- https://www.postgresql.org/docs/current/infoschema-columns.html
SELECT
cols.column_name,
(
SELECT
pg_catalog.col_description(c.oid, cols.ordinal_position::int)
FROM pg_catalog.pg_class c
WHERE
c.oid = ((cols.table_schema||'.'||cols.table_name)::regclass::oid) AND
c.relname = cols.table_name
) as column_comment
FROM information_schema.columns cols
WHERE
cols.table_schema = 'YOUR_SCHEMA' AND
cols.table_name = 'YOUR_TABLE';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment