zoukankan      html  css  js  c++  java
  • postgresql导出数据库文档

    select t.name as "表名",k."属性",k."数据类型",k."长度",k."主键约束",k."唯一约束",
    k."外键约束", k.nullable "是否非空",k.comment as "注释" from(select a.attrelid,


    a.attname as "属性",

    format_type(a.atttypid,a.atttypmod) as "数据类型",

    (case when atttypmod-4>0 then atttypmod-4 else 0 end) as "长度",

    (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

    )k
    left join (
    SELECT a.oid,
    a.relname AS name,
    b.description AS comment
    FROM pg_class a
    LEFT OUTER JOIN pg_description b ON b.objsubid=0 AND a.oid = b.objoid
    WHERE a.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname='public') --用户表一般存储在public模式下
    AND a.relkind='r'
    ORDER BY a.relname
    )t on t.oid=k.attrelid where t.name is not null

    参考:https://www.cnblogs.com/nami/p/4112339.html

    http://www.cnblogs.com/jxycn/p/5215822.html?locationNum=6&fps=1

  • 相关阅读:
    算法笔记--贪心
    算法笔记--递归
    算法笔记--哈希
    算法笔记--散列
    算法笔记--排序算法
    算法笔记--简单编程训练
    算法笔记--简单模拟
    算法笔记--注意事项
    3.4 空间滤波
    【解题报告】【概率DP入门】 P1850 换教室
  • 原文地址:https://www.cnblogs.com/longsanshi/p/10002350.html
Copyright © 2011-2022 走看看