Retrieving Comments from a PostgreSQL DB

后端 未结 13 2196
别那么骄傲
别那么骄傲 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:45

    It all works by oid,

    mat=> SELECT c.oid FROM pg_catalog.pg_class c WHERE c.relname = 'customers';
      oid  
    -------
     23208
    (1 row)
    

    Now, I have the oid for that table, so I can ask :

    mat=> select pg_catalog.obj_description(23208);
      obj_description  
    -------------------
     Customers
    (1 row)
    

    Then, I can ask for the description of the fourth column :

    mat=> select pg_catalog.col_description(23208,4);
                 col_description             
    -----------------------------------------
     Customer codes, CHS, FACTPOST, POWER...
    (1 row)
    

    If you want to know which queries does psql run when you do \dt+ or \d+ customers, just run it with -E.

提交回复
热议问题