postgresql獲取表結構,表名、表注釋、字段名、字段類型及長度和字段注釋


場景描述:navicate 將postgresql表結構導出到Excel。

1、查詢表名和表注釋

select relname as tabname,
cast(obj_description(relfilenode,'pg_class') as varchar) as comment 
from pg_class c 
where   relname ='t_bt_data' ;

 

 

 

 


2、查詢字段名、字段類型及字段長度和字段注釋

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 "備注"
from pg_class c, pg_attribute a , pg_type t, pg_description d 
where  c.relname = 't_bt_data'
and a.attnum>0 
and a.attrelid = c.oid 
and a.atttypid = t.oid 
and  d.objoid=a.attrelid
and d.objsubid=a.attnum
ORDER BY c.relname DESC,a.attnum ASC ;

 

 

 


其他:通過查詢sql,可以導出結果到EXCEL中。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM