zoukankan      html  css  js  c++  java
  • 关于pgsql输出表结构的问题

    今天公司中,因为要提供给其他开发人员,可以根据自己的需求查询数据库表的需求,所以经过一番测试,总结出了下面的一种方法

    sql如下:

    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,

    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))

    order by table_name,"a".attnum;

    下面做一下说明:

    pg_description 是保存注释信息的系统表,但是比较尴尬的是,只保存了他所在属性列的id

    pg_class  表记载表和几乎所有有 字段或者是那些类似表的东西。包括索引(不过还要参阅 pg_index),序列,视图,复合类型和一些特殊关系类型

    pg_attribute 这个表存储了所有属性列

    最终结果大致就显示成这样,然后可以把这样的结果放在一个视图 或者重新新建一个形式表,然后再分类进行查询

  • 相关阅读:
    怎么接音响
    怎样区分音箱与音响
    什么是卡盟
    小白晋级达人必备 电视接口使用介绍(4)
    液晶电视插有线电视信号线的是哪个接口 HDMI是什么接口
    Google 镜像站搜集
    屏幕检测
    网站引流
    夜神安卓模拟器
    html5模拟平抛运动
  • 原文地址:https://www.cnblogs.com/dtiove/p/5730444.html
Copyright © 2011-2022 走看看