zoukankan      html  css  js  c++  java
  • 根据PostgreSQL 系统表查出字段描述

    SELECT a.attname AS fields_name,
           pg_catalog.format_type(a.atttypid, a.atttypmod),
           CASE WHEN a.attnotnull  THEN 'N' ELSE ''
           END AS fields_not_null,
           pg_attrdef.adsrc AS fields_default,
           b.contype,
           pg_description.description AS fields_comment
     FROM
           pg_catalog.pg_attribute a
           INNER JOIN pg_class  ON a.attrelid = pg_class.oid AND pg_class.relname='tablename'
           INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid AND pg_namespace.nspname = 'public'
           INNER JOIN pg_type   ON a.atttypid = pg_type.oid
           LEFT OUTER JOIN pg_attrdef ON pg_attrdef.adrelid = pg_class.oid AND pg_attrdef.adnum = a.attnum
           LEFT OUTER JOIN pg_description ON pg_description.objoid = pg_class.oid AND pg_description.objsubid = a.attnum
           LEFT OUTER JOIN (SELECT a.attnum, pg_constraint.contype
                            FROM pg_catalog.pg_attribute a
    			     INNER JOIN pg_class  ON a.attrelid = pg_class.oid AND pg_class.relname='tablename'
                                 INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid AND pg_namespace.nspname = 'public'
                                 INNER JOIN pg_constraint ON pg_constraint.conrelid = pg_class.oid 
                                                 AND pg_constraint.connamespace = pg_namespace.oid 
                                                 AND a.attnum = ANY(pg_constraint.conkey)
                            GROUP BY a.attnum, pg_constraint.contype) b
                            ON a.attnum = b.attnum
     WHERE
           a.attnum > 0
           AND attisdropped <> 't' 
           AND a.attname <> 'oid'
     ORDER BY a.attnum;
    

      

  • 相关阅读:
    django学习笔记
    django配置setting文件
    django用mysql数据库出现的问题解决
    hadoop本地集群搭建
    生成器
    Java自动装箱的陷阱
    LeetCode 89. Gray Code
    LeetCode 476. Number Complement
    Javac编译与JIT编译
    LeetCode 462. Minimum Moves to Equal Array Elements II
  • 原文地址:https://www.cnblogs.com/shuaixf/p/2171748.html
Copyright © 2011-2022 走看看