1. 程式人生 > >postgres資料庫獲取表的資訊與欄位的資訊

postgres資料庫獲取表的資訊與欄位的資訊

1、獲取postgres中定義表的名稱與註釋

select relname as TABLE_NAME ,col_description(c.oid, 0) as COMMENTS from pg_class c where  relkind = 'r' and relname not like 'pg_%' and relname not like 'sql_%'

2、獲取postgres中某個表中欄位的定義資訊

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