获取表名及注释:

select relname as tabname,cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c 
where relkind = 'r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname

过滤掉分表:

加条件 and relchecks=0 即可

获取字段名、类型、注释、是否为空:

SELECT col_description(a.attrelid,a.attnum) as comment,format_type(a.atttypid,a.atttypmod) as type,a.attname as name, a.attnotnull as notnull 
FROM pg_class as c,pg_attribute as a where c.relname = '表名' and a.attrelid = c.oid and a.attnum>0

补充:PostgreSQL查询表主键及注释内容

网上关于pgSql获取表主键的内容都是千篇一律,并且对于存在多主键的场景不支持。

附上测试后可获取多个主键字段值的SQL

SELECT
 string_agg(DISTINCT t3.attname,',') AS primaryKeyColumn
 ,t4.tablename AS tableName
 , string_agg(cast(obj_description(relfilenode,'pg_class') as varchar),'') as comment
FROM
 pg_constraint t1
 INNER JOIN pg_class t2 ON t1.conrelid = t2.oid
 INNER JOIN pg_attribute t3 ON t3.attrelid = t2.oid AND array_position(t1.conkey,t3.attnum) is not null
 INNER JOIN pg_tables t4 on t4.tablename = t2.relname
 INNER JOIN pg_index t5 ON t5.indrelid = t2.oid AND t3.attnum = ANY (t5.indkey)
 LEFT JOIN pg_description t6 on t6.objoid=t3.attrelid and t6.objsubid=t3.attnum
WHERE t1.contype = 'p'
  AND length(t3.attname) > 0
  AND t2.oid = '表名' :: regclass
 group by t4.tablename

postgresql 实现获取所有表名,字段名,字段类型,注释

目前只找到了获取指定表的主键信息,对于批量获取没有找到。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。