1. 程式人生 > 其它 >postgresql獲取表結構,表名、表註釋、欄位名、欄位型別及長度和欄位註釋

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中。

為人:謙遜、激情、博學、審問、慎思、明辨、 篤行
學問:紙上得來終覺淺,絕知此事要躬行
為事:工欲善其事,必先利其器。
態度:道阻且長,行則將至;行而不輟,未來可期
轉載請標註出處!