zoukankan      html  css  js  c++  java
  • postgresql获取表结构,表名、表注释、字段名、字段类型及长度和字段注释

    场景描述:navicate 将postgresql表结构导出到Excel。

    1、查询表名和表注释

    select relname as tabname,
    cast(obj_description(relfilenode,'pg_class') as varchar) as comment 
    from pg_class c 
    where   relname ='t_bt_data' ;


    2、查询字段名、字段类型及字段长度和字段注释

    select a.attnum AS "序号",
    c.relname AS "表名",
    cast(obj_description(relfilenode,'pg_class') as varchar) AS "表名描述",
    a.attname AS "列名",
    concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '\(.*\)')) as "字段类型",
    d.description AS "备注"
    from pg_class c, pg_attribute a , pg_type t, pg_description d 
    where  c.relname = 't_bt_data'
    and a.attnum>0 
    and a.attrelid = c.oid 
    and a.atttypid = t.oid 
    and  d.objoid=a.attrelid
    and d.objsubid=a.attnum
    ORDER BY c.relname DESC,a.attnum ASC ;


    其他:通过查询sql,可以导出结果到EXCEL中。

    为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
    学问:纸上得来终觉浅,绝知此事要躬行
    为事:工欲善其事,必先利其器。
    态度:道阻且长,行则将至;行而不辍,未来可期
    转载请标注出处!
  • 相关阅读:
    简单工厂设计模式
    MVC备忘
    在MVC后台代码中想实现删除时弹出"确认删除"效果
    集合
    嵌套
    整理 补课内容
    百鸡百钱
    ////输入一个100以内的数,判断是不是正整数;
    课后题 5 6
    课后题3,4
  • 原文地址:https://www.cnblogs.com/ios9/p/15783527.html
Copyright © 2011-2022 走看看