我是靠谱客的博主 稳重丝袜,最近开发中收集的这篇文章主要介绍PostgreSql 查询表结构和说明,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

select 
(select relname from  pg_class where oid=a.attrelid) relname ,
(select relname||'--'||(select description  from pg_description where objoid=oid and objsubid=0) as comment from pg_class where oid=a.attrelid) as table_name,

a.attname as column_name,

format_type(a.atttypid,a.atttypmod) as data_type,

(case when atttypmod-4>0 then atttypmod-4 else 0 end)data_length,

(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype='p')>0 then 'Y' else 'N' end) as 主键约束,

(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype='u')>0 then 'Y' else 'N' end) as 唯一约束,

(case when (select count(*) from pg_constraint where conrelid = a.attrelid and conkey[1]=attnum and contype='f')>0 then 'Y' else 'N' end) as 外键约束,

(case when a.attnotnull=true then 'Y' else 'N' end) as nullable,

col_description(a.attrelid,a.attnum) as comment

from pg_attribute a

where attstattarget=-1 and attrelid in (select oid from pg_class where relname in(select relname from pg_class where relkind ='r' and relname not like 'pg_%' ))

order by relname,a.attnum;

 

转载于:https://www.cnblogs.com/hzy168/p/10293408.html

最后

以上就是稳重丝袜为你收集整理的PostgreSql 查询表结构和说明的全部内容,希望文章能够帮你解决PostgreSql 查询表结构和说明所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部