Postgresql、Hologres表结构查询语句

编程入门 行业动态 更新时间:2024-10-05 21:18:37

Postgresql、Hologres表结构查询<a href=https://www.elefans.com/category/jswz/34/1770772.html style=语句"/>

Postgresql、Hologres表结构查询语句

Postgresql、Hologres表结构相关查询语句

  • 1、SQL语句展示
  • 2、相关字段说明
  • 3、其他结构查询语句展示
    • 3.1、
    • 3.2、统计每张表的分区数量
    • 3.3、

1、SQL语句展示

SELECT DISTINCT a.attnum as num,a.attndims as dimension_array,a.attname as name,t.typname as data_type,concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '\(.*\)')) as type_complete,a.attnotnull as notnull,a.attlen AS length,a.atttypmod AS lengthvar,com.description as comment,coalesce(i.indisprimary,false) as primary_key,def.adsrc as default_valueFROM pg_attribute aJOIN pg_class pgc ON pgc.oid = a.attrelidLEFT JOIN pg_index i ON(pgc.oid = i.indrelid AND i.indkey[0] = a.attnum)LEFT JOIN pg_description com on(pgc.oid = com.objoid AND a.attnum = com.objsubid)LEFT JOIN pg_attrdef def ON(a.attrelid = def.adrelid AND a.attnum = def.adnum)Left join pg_type t on( a.atttypid = t.oid)WHERE a.attnum > 0 AND pgc.oid = a.attrelidAND pg_table_is_visible(pgc.oid)AND NOT a.attisdroppedAND pgc.relname = 【这儿写入你的表名,需要在表名两侧加上单引号】ORDER BY a.attnum

2、相关字段说明

字段名释义
num字段序号
dimension_array数组维度数量,0表示不存在数组维度,如果值为1则有一个数组维度[],如果值为2,则有两个数组维度[ ][ ],以此类推
name字段名称
data_type字段类型(不带字段精度)
type_complete字段类型(带字段精度)
notnull是否允许不为空 t-不允许为空值,f-允许为空值
length(该字段含义不明)
lengthvar字段长度,由该列显示出的长度往往都比预设值长4,该长度只能作为参考,不可实际使用
comment字段注释
primary_key是否是一个主键,t-主键,f-非主键
default_value默认值

3、其他结构查询语句展示

3.1、

SELECTnmsp_parent.nspname AS parent_schema ,parent.relname AS parent ,nmsp_child.nspname AS child ,child.relname AS child_schemaFROMpg_inherits JOIN pg_class parentON pg_inherits.inhparent = parent.oid JOIN pg_class childON pg_inherits.inhrelid = child.oid JOIN pg_namespace nmsp_parentON nmsp_parent.oid = parent.relnamespace JOIN pg_namespace nmsp_childON nmsp_child.oid = child.relnamespace
WHEREparent.relname = 【这儿写入你的表名,需要在表名两侧加上单引号】;

3.2、统计每张表的分区数量

SELECTnspname ,relname ,COUNT(*) AS partition_num
FROMpg_class c ,pg_namespace n ,pg_inherits i
WHEREc.oid = i.inhparentAND c.relnamespace = n.oidAND c.relhassubclassAND c.relkind = 'r'
GROUP BY 1,2 ORDER BY partition_num DESC;

3.3、

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 "备注",
a.attnotnull as "是否允许为空",
def.adsrc as "默认值"
from pg_class c, pg_attribute a , pg_type t, pg_description d,pg_attrdef def
where  c.relname = 【这儿写入你的表名,需要在表名两侧加上单引号】
and a.attnum>0 
and a.attrelid = c.oid 
and a.atttypid = t.oid 
and  d.objoid=a.attrelid
and d.objsubid=a.attnum
and a.attrelid = def.adrelid 
--and a.attnum = def.adnum
ORDER BY c.relname DESC,a.attnum ASC

更多推荐

Postgresql、Hologres表结构查询语句

本文发布于:2024-02-28 13:05:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1769922.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   结构   Postgresql   Hologres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!