獲取數據庫中所有table名:
SELECT tablename FROM pg_tables
WHERE tablename NOT LIKE 'pg%'
AND tablename NOT LIKE 'sql_%'
ORDER BY tablename;
獲取數據庫中所有table名及table的注解信息:
SELECT tablename,obj_description(relfilenode,'pg_class') FROM pg_tables a, pg_class b
WHERE
a.tablename = b.relname
and a.tablename NOT LIKE 'pg%'
AND a.tablename NOT LIKE 'sql_%'
ORDER BY a.tablename;
獲取指定table的所有字段信息:
SELECT col_description(a.attrelid,a.attnum) as comment,format_type(a.atttypid,a.atttypmod) as type,a.attname as name, a.attnotnull as notnull
FROM pg_class as c,pg_attribute as a
where c.relname = 'tablename' and a.attrelid = c.oid and a.attnum>0
查詢字段名、字段類型及字段長度和字段注釋:
select a.attnum,a.attname,concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '\(.*\)')) as type,d.description from pg_class c, pg_attribute a , pg_type t, pg_description d
where c.relname = 'table_name' and a.attnum>0 and a.attrelid = c.oid and a.atttypid = t.oid and d.objoid=a.attrelid and d.objsubid=a.attnum
補充
select column_name from information_schema.columns where table_schema='public' and table_name<>'pg_stat_statements';
版權聲明:本文為CSDN博主「凌淵閣」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/zw3413/java/article/details/83592413