加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

pg 生成数据字典

发布时间:2020-12-14 04:33:01 所属栏目:大数据 来源:网络整理
导读:select(select relname||‘--‘||(select description from pg_description where objoid=oid and objsubid=0) as comment from pg_class where oid=a.attrelid) as table_name,a.attname as column_name,format_type(a.atttypid,a.atttypmod) as data_type,
select

(select relname||‘--‘||(select description from pg_description where objoid=oid and objsubid=0) as comment from pg_class where oid=a.attrelid) as table_name,a.attname as column_name,format_type(a.atttypid,a.atttypmod) as data_type,(case when atttypmod-4>0 then atttypmod-4 else 0 end)data_length,(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype=‘p‘)>0 then ‘Y‘ else ‘N‘ end) as 主键约束,(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype=‘u‘)>0 then ‘Y‘ else ‘N‘ end) as 唯一约束,(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype=‘f‘)>0 then ‘Y‘ else ‘N‘ end) as 外键约束,(case when a.attnotnull=true then ‘Y‘ else ‘N‘ end) as nullable,col_description(a.attrelid,a.attnum) as comment

from pg_attribute a

where attstattarget=-1 and attrelid in (select oid from pg_class where relname in(select relname from pg_class where relkind =‘r‘ and relname like ‘tbl_%‘))

order by table_name,a.attnum;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读