zoukankan      html  css  js  c++  java
  • pg 生成数据字典

    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;
    

      

  • 相关阅读:
    bzoj1084
    bzoj1088 [SCOI2005]扫雷
    [LUOGU] 1892 团伙
    [普及组] 2017 成绩
    [LUOGU] P2661 信息传递
    [LUOGU] P1339 [USACO09OCT]热浪Heat Wave
    [LUOGU] P1828 香甜的黄油 Sweet Butter
    [模板] 单源最短路径
    [LUOGU] 1717 钓鱼
    [UVA] 704 Colour Hash
  • 原文地址:https://www.cnblogs.com/Guroer/p/10748725.html
Copyright © 2011-2022 走看看