有的时候需要在Greenplum数据库里面查看某张表的描述信息,就是Comment on table 。
废话不多说,直接上代码,亲测可用。
with tmp_tab as (
select pc.oid as ooid,pn.nspname,pc.*
from pg_class pc
left outer join pg_namespace pn
on pc.relnamespace = pn.oid
where 1=1
and pc.relkind in ('r')
and pn.nspname not in ('pg_catalog','information_schema') -- select pn.oid, pn.* from pg_namespace pn where 1=1
and pn.nspname not like 'pg_toast%'
and pc.oid not in (
select inhrelid
from pg_inherits
)
and pc.relname not like '%peiyb%'
order by pc.relname
),tmp_desc as (
select pd.*
from pg_description pd
where 1=1
and pd.objsubid = 0 --objsubid 对于一个表列上的一个注释,这里是列号(objoid和classoid指表本身)。对所有其他对象类型,此列为0。
--and pd.objoid=168605
)
select t0.*
from (
select tab.relname as table_name,
de.description
from tmp_tab tab
left outer join tmp_desc de
on tab.ooid = de.objoid
where 1=1 and tab.relname='your table name'
) t0
where 1=1;
上面的代码里面,结尾的地方,把your table name直接替换成你想要查看注释的那张表名。
然后全部复制粘贴,直接运行就ok。