PostgreSql 查询表结构和说明
Posted hzy168
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
以上是关于PostgreSql 查询表结构和说明的主要内容,如果未能解决你的问题,请参考以下文章