Retrieving Comments from a PostgreSQL DB

后端 未结 13 2197
别那么骄傲
别那么骄傲 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 14:02

    I accessed table comments like this:

    select c.relname table_name, pg_catalog.obj_description(c.oid) as comment from pg_catalog.pg_class c where c.relname = 'table_name';
    

    and column comments thusly:

    SELECT c.column_name, pgd.description FROM pg_catalog.pg_statio_all_tables as st inner join pg_catalog.pg_description pgd on (pgd.objoid=st.relid) inner join information_schema.columns c on (pgd.objsubid=c.ordinal_position and c.table_schema=st.schemaname and c.table_name=st.relname and c.table_name = 'table_name' and c.table_schema = 'public');
    

提交回复
热议问题