查找AnalyticDB表的DDL语句

select dump_talbe_ddl('tablename'::regclass);

1.获取AnalyticDB表

select * from information_schema.tables;

2.获取AnalyticDB列

select * from information_schema.columns;

3.获取ADB PG表中文名
获取表中文名:方法一

select t.schemaname  ,t.relname   --表英文名,description --表中文名
from pg_description d,pg_class c,pg_stat_all_tables t
where d.objoid = c.oidand objsubid = 0 and t.relname = c.relnameand t.schemaname = 'SCHEMANAME'and c.relname = 'tablename'
;

获取表中文名:方法二

select relname                --表英文名,obj_description(c.oid) --表中文名
from pg_class c
where obj_description(c.oid) is not null
and relname = 'tablename'
;

获取表中文名:方法三

select distinct a.relname --表英文名,b.description     --表中文名
from pg_class a
left join pg_description b
on a.oid = b.objoid
and b.objsubid = '0'
where a.relname = 'tablename'
;

4.获取表中文名、字段中文名、字段类型

select --t2.attnum,t2.relname   --表英文名,obj_description(t2.oid)  --表中文名,t2.field                 --字段英文名,t2.comment               --字段中文名,case when t2.type = 'varchar' then concat('varchar(',cast(t1.charachter_maximum_length as varchar),')')when t2.type = 'numeric' then concat('numeric(',numeric_precistion,',',numeric_scale,')')else t2.typeend  as type     --字段类型
from information_schema.columns t1
left join(
select a.attnum,c.oid,c.relname,a.attname as field,t.typname as type,a.attlen  as length,a.atttypmod as lengthvar,attnotnull  as notnull,b.description as comment
from pg_class c,pg_attribute aleft outer join pg_description b on a.attrelid = b.objoid and a.attnum =  b.objsubid,pg_type t
--where c.regclass = ('tablename')
where a.attnum >0
and a.attrelid = c.oid
and a.atttypid = t.oid
order by a.attnum
) t2
on t1.table_name = t2.relname
and t1.column_name = t2.field
where t1.table_schmea = 'SCHEMA'
and table_name = 'tablename'
order by relname,attnum
;

5.获取表中文名、字段中文名、字段类型、分布键

selectb.relname                         as 表名,obj_description(b.oid)           as 表中文名,a.attname                        as 字段英文名称,col_description(a.attrelid,a.attnum)   as 字段中文名称,replace(format_type(a.atttypid,a.atttypmod),'character varying','varchar') as 字段类型,(case when atttypmod -4 >0 then atttypmod -4 else 0 end) as 字段长度,(case when (select count(1) from gp_constraint where conrelid = a.attrelid and conkey[1] = attnum and contype = 'p') > 0then 'Y' else 'N' end) as 主键,(case when (select count(1) from gp_constraint where conrelid = a.attrelid and conkey[1] = attnum and contype = 'u') > 0then 'Y' else 'N' end) as 唯一约束,(case when (select count(1) from gp_constraint where conrelid = a.attrelid and conkey[1] = attnum and contype = 'f') > 0then 'Y' else 'N' end) as 外键约束,(case when a.attnotnull = true then 'N' else 'Y' end) as 是否允许NULL,case when c.attname is not null then 'Y' else 'N' end as 是否分布键from pg_attribute a
left join pg_class b on a.attrelid = b.pid
left join (select aaa.relname as 表名 ,ccc.attname, aaa.oidfrom ( select aa.oid,obj_description(aa.oid) as table_comment,aa.relname,bb.localoid,bb.distkey   as attrnums,,regexp_split_to_table(array_to_string(bb.distkey,','),',')  as att,dd.nspnamefrom pg_class aa -- 原数据信息,最主要的表left join gp_distribution_policy bb on bb.localoid = aa.oid  -- 分布键表left join pg_namespace dd on dd.oid = aa.relnamespace  -- 模式left join pg_inherits hh on aa.oid = hh.inhrelid  -- 继承表where dd.nspname = 'schema_name'  -- 替换需要的模式and hh.inhrelid is null) aaaleft join pg_attribute ccc on ccc.attrelid = aaa.oidand     cast(ccc.attnum as text) = aaa.attwhere ccc.attnum >0) c
on a.attrelid = c.oid
and a.attname = c.attname
left join information_schema.columns e on attname = e.column_name
and b.relname = e.table_name
where attstattarget = -1
and e.table_schmea = 'schema_name'
and b.relname = 'table_name'
order by b.rename,e.ordinal_position
;

AnalyticDB PostgreSQL获取表信息相关推荐

  1. postgresql获取表最后更新时间(通过触发器将时间写入另外一张表)

    通过触发器方式获取表最后更新时间,并将时间信息写入到另外一张表 一.创建测试表和表记录更新时间表 CREATE TABLE weather( city varchar(80), temp_lo int ...

  2. 查询用户所有信息后只需要两个字段的信息_Excel VBA+ADO+SQL入门教程023:OpenSchema获取表信息...

    点上方关注我们,每日1练,每天进步一点点  1. 我们在使用SQL语言对数据库数据进行查询之前,有时需要获取每张表的表名,甚至获取每张表每个字段的名称等:比如,当我们进行跨工作簿数据查询及汇总时,在不 ...

  3. hbase获取表信息_HBase的读写和javaAPI的使用

    一.hbase系统管理表 hbase:namespace,记录了hbase中所有namespace的信息 ,当前系统下有哪些namespace信息 scan 'hbase:namespace' hba ...

  4. Sql获取表信息(包括结构及字段说明)

    SELECT     表名       = case when a.colorder=1 then d.name else '' end,     表说明     = case when a.colo ...

  5. SQL SERVER 获取表结构信息《转载》

    获取表信息 SELECT      表名       = case when a.colorder=1 then d.name else '' end,      表说明     = case whe ...

  6. JAVA中获取字段信息的方法

    一.JDBC之DatabaseMetaData之获取表信息以及列信息  (1) DatabaseMetaData实例的获取 Connection conn = DriverManager.getCon ...

  7. Java--通过JDBC元数据获取表结构(ResultSetMetaData元数据的使用)

    最近在线上联调,由于我们没有数据库的可视化工具,和其他公司比对数据和表结构总是十分麻烦.后来我看到组长通过元数据来获取表结构和值.之后我自学了一下,感觉十分方便,分享给大家. jdbc的元数据有两类. ...

  8. MySQL SHOW TABLE STATUS 获取表的信息

    show table status 获取表的信息 show table status like 'tableName' 1.Name 表名称 2.Engine: 表的存储引擎 3.Version: 版 ...

  9. SQL Server 获取表或视图结构信息

    ------------获取表或视图的结构信息(ObjName:表名或视图名) Select o.name as Oname,c.name As name , t.name As type,c.Len ...

最新文章

  1. python使用fpdf生成数据报告pdf文件
  2. 使用 qrcodejs 生成二维码的几个问题
  3. [poj3041]Asteroids(二分图的最小顶点覆盖)
  4. ceph rbdmap遇到的一个问题
  5. 【撸啊撸 Docker】搭建 Jenkins
  6. 50行 koa-compose,面试常考的中间件原理原来这么简单?
  7. 漫步数理统计十七——条件分布与期望
  8. java编程思想 Chapter 2
  9. Xcode 输入时 搜索代码块前面标记的字母含义
  10. java微服务实战.pdf_Spring微服务实战 ([美]约翰·卡内尔) 中文完整pdf扫描版[172MB]...
  11. 8、网友问答之串口数据接收与数据强制转换---------labview宝典
  12. python股票成交明细_AkShare-股票数据-龙虎榜-机构席位成交明细
  13. 2008年金融危机的背后原因以及感悟
  14. iwork09破解方法及解决SFCompatibility错误方法
  15. 日本首次利用IPS细胞分化成免疫细胞应用于癌症治疗
  16. 《和平精英》与玛莎拉蒂跨界合作
  17. 使用RecyclerView实现瀑布流
  18. 大数据分析的技术有哪些?
  19. 【通信协议】单总线协议详解——以DHT11为例
  20. html中h3字体不加粗取消,css如何取消加粗

热门文章

  1. 网页设计大作业模板-网页设计大作业——丝绸之路网页设计(6页)
  2. python中 什么是描述符?
  3. 使用hexo搭建自己的博客系统
  4. 放屁的犀牛(farting rhino)
  5. 【区块链】以太坊 web3j for java 使用 - 部署和调用合约 3
  6. Android MarginLeft与MarginStart的差别
  7. 恒盛策略|汽车制造板块飙升近4%,概念股批量涨停!
  8. 【SAP Hana】X档案:SAP HANA SQL 进阶教程
  9. ---------------------------谨以此文献给我的2011-----------------------------------
  10. mysql 去除双引号