SELECT c.relname 表名稱, A.attname AS 字段名稱, col_description(A.attrelid,A.attnum) AS 注釋, format_type ( A.atttypid, A.atttypmod ) AS 類型, CASE WHEN A.attnotnull='f' THEN '否' ELSE '是' END AS 是否必填, a.attnum 序號 FROM pg_class AS c, pg_attribute AS a WHERE A.attrelid = C.oid AND A.attnum > 0 ORDER BY c.relname,a.attnum;
SELECT c.relname 表名稱, A.attname AS 字段名稱, split_part(col_description ( A.attrelid, A.attnum ),':',1) AS 注釋, format_type ( A.atttypid, A.atttypmod ) AS 類型, CASE WHEN A.attnotnull='f' THEN '否' ELSE '是' END AS 是否必填, a.attnum 序號 FROM pg_class AS c, pg_attribute AS a WHERE c.relnamespace=16389 AND c.relname not like 'v_%' AND c.relname not like 'pk_%' AND c.relname not like 'unidx%' AND c.relname not like '%_index' AND c.relname not like '%_seq' AND c.relname not like '%_pkey' AND A.attrelid = C.oid AND A.attnum > 0 ORDER BY c.relname,a.attnum;
補充:postgresql 查詢某一個表中的所有字段
postgresql 查詢某一個表中的所有字段,也就是查詢所有的列名
select * from information_schema.columns where table_schema='public' and table_name='表名稱 ';
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
標(biāo)簽:濮陽 海西 寶雞 昭通 溫州 杭州 榆林 辛集
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PostgreSQL 實現(xiàn)查詢表字段信息SQL腳本》,本文關(guān)鍵詞 PostgreSQL,實現(xiàn),查詢表,字段,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。