查詢格式:
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)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- postgresql 補齊空值、自定義查詢字段并賦值操作
- postgresql 13.1 insert into select并行查詢的實現(xiàn)
- postgresql insert into select無法使用并行查詢的解決
- 關(guān)于PostgreSQL錯誤日志與慢查詢?nèi)罩臼占?/li>
- 查詢PostgreSQL占多大內(nèi)存的操作
- postgresql 實現(xiàn)查詢出的數(shù)據(jù)為空,則設(shè)為0的操作