匿名用户openGauss查所有列名和列注释的SQL?
求一个SQL,某张表里的openGauss查所有列名和列注释?
我来答
添加附件
收藏
复制链接
微信扫码分享
在小程序上查看
分享
添加附件
问题补充
2条回答
默认
最新
采纳答案后不可修改和取消
可以参考compat-tools中DBA_COL_COMMENTS视图的实现方式
https://gitee.com/enmotech/compat-tools
SELECT case when n.nspname::text = lower(n.nspname::text) then UPPER(n.nspname::text) else n.nspname::text end AS OWNER
, case when c.relname::text = lower(c.relname::text) then UPPER(c.relname::text) else c.relname::text end AS TABLE_NAME
, case when a.attname::text = lower(a.attname::text) then UPPER(a.attname::text) else a.attname::text end AS COLUMN_NAME
, d.description as COMMENTS
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c on a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n on c.relnamespace = n.oid
LEFT JOIN pg_catalog.pg_description d on a.attrelid = d.objoid and a.attnum = d.objsubid and d.classoid = 'pg_class'::regclass::oid
WHERE n.nspname not like 'pg_toast%';
评论
有用 0使用类似pg方法
select c.relname,a.attnum, a.attname, concat_ws('', t.typname, SUBSTRING(format_type(a.atttypid, a.atttypmod) from '\(.*\)')) as type, d.description
from pg_class c, pg_attribute a, pg_type t, pg_description d,pg_tables tb
where 1=1
--c.relname = 'sys_user'
-- and a.attnum > 0
-- and
-- and tb.tablename
and t.typname='bpchar'
and a.attrelid = c.oid
and a.atttypid = t.oid
and d.objoid = a.attrelid
and d.objsubid = a.attnum;
使用类似mysql方法
information_schema.columns
都满足你的需求。
评论
有用 0回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
墨值悬赏

