博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GP 查询表字段信息(分布键等)
阅读量:6881 次
发布时间:2019-06-27

本文共 1901 字,大约阅读时间需要 6 分钟。

hot3.png

--1.查询对象字段、注释和字段类型select  t.schemaname     ,c.relname object_name    ,d.description object_comment    --,c.reltuples count    --,c.relkind object_type --r = 普通表,i = 索引,S = 序列,v = 视图, c = 复合类型,s = 特殊,t = TOAST表    --,c.relhaspkey primary_key --f:假,t-:真    ,a.attname column_name    ,db.description column_comment    ,s.attrnums distributed_column    --,case when s.attrnums is not null then 'is distributed key' end distributed_column    --,a.attnum column_seq    ,case p.typname         when 'int8' then 'bigint'        when 'int4' then 'integer'        when 'int2' then 'smallint'        when 'timestamp' then 'timestamp without time zone'        when 'date' then 'date'        when 'varchar' then 'character varying('||a.atttypmod - 4||')'        when 'numeric' then  'numeric('||(a.atttypmod - 4) / 65536||','||(atttypmod - 4) % 65536||')'    end column_type    ,at.adsrc AS column_default        ,CASE         WHEN a.attnotnull THEN          'not null'         ELSE          ''       END AS column_not_null    --,p.typname    --,p.typlen    --,a.atttypmod - 4 as column_length from pg_tables tinner join pg_class c on t.tablename=c.relnameleft join pg_description d on c.oid=d.objoid and d.objsubid=0left join pg_description db on c.oid=db.objoid and db.objsubid>0left join pg_attribute a on c.oid=a.attrelid and db.objsubid=a.attnumleft join ( select a.attrnums[i.i] attrnums,b.attname,a.localoid     from gp_distribution_policy a,          (select generate_series(1,10)) i(i),  --预计表分布键的个数为10个        pg_attribute b     where a.attrnums[i.i] is not null       and a.localoid=b.attrelid       and a.attrnums[i.i]=b.attnum ) s on c.oid=s.localoid and a.attnum=s.attrnumsleft join pg_type p on a.atttypid=p.oidleft join pg_attrdef at on c.oid=at.adrelid and a.attnum=at.adnum  --where upper(c.relname) = upper('bas_add_sub_rep') --表名order by a.attnum;

 

 

 

转载于:https://my.oschina.net/goopand/blog/370788

你可能感兴趣的文章
在mac上安装 docker
查看>>
JVM运行机制
查看>>
JVM GC 机制与性能优化 2 实例测试
查看>>
oracl 数据库中查询当前时间前几天的数据
查看>>
linux环境查看tar压缩包内容,部分解压的命令
查看>>
1.1 LAMP架构介绍
查看>>
php模式设计之 单例模式
查看>>
线性时间排序总结
查看>>
jenkins安装
查看>>
Python爬虫入门:URLError异常处理
查看>>
STS导项目的顺序及注意事项
查看>>
CentOS 7 安装 Git 与 Gitlab-runner 实例
查看>>
nginx配置用户认证
查看>>
一文带你认识Spring事务
查看>>
玩转大数据系列之三:数据报表与展示
查看>>
阿里云BaaS:降低区块链应用门槛,用技术构建商业互信
查看>>
《富爸爸巴比伦最富有的人》读书笔记3000字
查看>>
分享几个国外学习网站
查看>>
一文分析java基础面试题中易出错考点
查看>>
6月21日云栖精选夜读丨CCTV5手机客户端新媒体:让赛事集锦堪比电影大片
查看>>