PostgreSQL 查询表名、表注释、字段名、字段类型、字段默认值、字段备注 发表于 2021-02-23 | 阅读次数: 查询表名和注释 123456789select relname as "表名", cast(obj_description(relname::regclass, 'pg_class') as varchar) as "表注释"from pg_classwhere relname in ( select tablename from pg_tables where 1 = 1 and tablename like ('%' || 'XX 表' || '%'))order by relname asc; 查询表的字段信息 123456789101112131415161718192021222324select c.column_name as "字段名", c.column_default as "默认值", c.is_nullable as "是否可为空", c.data_type as "类型", c.character_maximum_length as "长度", ad.attnum as "序号", ad.description as "备注"from( select * from information_schema.columns where table_name = 'XX 表') cjoin( select a.attnum, a.attname, d.description from pg_attribute a, pg_description d where a.attnum > 0 and d.objoid = a.attrelid and d.objsubid = a.attnum and a.attrelid = (SELECT oid FROM pg_class WHERE relname = 'XX 表')) adon c.column_name = ad.attname; 相关文章 PostgreSQL 数据库的 jsonb 数组操作 PostgreSQL 字符串分隔函数(regexp_split_to_table、regexp_split_to_array) PostgreSQL 查看被锁的表 PostgreSQL 常用字符操作函数 PostgreSQL 使用 CREATE TABLE AS SELECT 语句方便的备份数据到备份表 本文链接: https://zhangzw.com/posts/20210223.html 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-ND 许可协议。转载请注明出处!