码迷,mamicode.com
首页 > 数据库 > 详细

【PostgreSql】生成数据字典

时间:2020-05-06 20:01:13      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:esc   sql   pid   cas   pos   desc   des   color   ons   

pg查询元数据,生成表数据字典:

 

效果:

技术图片

 

  

代码:

SELECT
    A .attname 字段,   
    concat_ws (
        ‘‘,
        T .typname,
        SUBSTRING (
            format_type (A .atttypid, A .atttypmod)
            FROM
                \(.*\)
        )
    ) AS 类型,
        case when s.pk is not null then 
                               else 
    end as 主键,
    case A.attnotnull when f then 
                      when t then 
    end as 空,
    d.description 注释
FROM pg_attribute A
INNER JOIN pg_class C on A .attrelid = C .oid
INNER JOIN pg_type T on A .atttypid = T .oid
LEFT JOIN (SELECT conrelid, unnest(conkey) as pk
                        FROM pg_constraint
                        WHERE contype = p) S ON S.conrelid = C .oid
                                   AND A.attnum = S.pk
LEFT JOIN pg_description d on d.objoid = A .attrelid
                                                    AND d.objsubid = A .attnum
WHERE A .attnum > 0
AND C.relname = t_gfecp_bigdata_blacklist
ORDER BY
    C .relname,
    A .attnum

 

【PostgreSql】生成数据字典

标签:esc   sql   pid   cas   pos   desc   des   color   ons   

原文地址:https://www.cnblogs.com/TurboWay/p/12838214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!