Retrieving Comments from a PostgreSQL DB

后端 未结 13 2198
别那么骄傲
别那么骄傲 2020-12-05 13:13

I\'m running a project on a Postgres database and need to retrieve the comments on columns within the DB to be used as table headings and such. I have seen that there are a

13条回答
  •  感动是毒
    2020-12-05 13:44

    A slight change to one of the other answers which only gives you columns that have comments on them, this gives you all columns whether they have a comment or not.

    select c.table_schema, st.relname as TableName, c.column_name, 
    pgd.description
    from pg_catalog.pg_statio_all_tables as st
    inner join information_schema.columns c
    on c.table_schema = st.schemaname
    and c.table_name = st.relname
    left join pg_catalog.pg_description pgd
    on pgd.objoid=st.relid
    and pgd.objsubid=c.ordinal_position
    where st.relname = 'YourTableName';
    

提交回复
热议问题