前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PostgreSQL查询数据库表以及每一个表里面的字段的类型,字段名称,字段意思

PostgreSQL查询数据库表以及每一个表里面的字段的类型,字段名称,字段意思

作者头像
一写代码就开心
发布2022-10-04 08:15:28
2.6K0
发布2022-10-04 08:15:28
举报
文章被收录于专栏:java和pythonjava和python

目录

1 查看特定表名备注

代码语言:javascript
复制
select relname as tabname,
cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c 

where relname ='user';

2 查看全部表名和备注

就是查看public 下的全部都表名称

代码语言:javascript
复制
select relname as tabname,cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c
where relname in (select tablename from pg_tables where schemaname='public' and position('_2' in tablename)=0);

3 查询全部都表名

代码语言:javascript
复制
select tablename from pg_tables where
 schemaname='public' and position('_2' in tablename)=0;

4 查看特定表名字段,字段类型,描述

代码语言:javascript
复制
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='zr_wx_db_sobu_ele' and a.attnum>0 and a.attrelid=c.oid and a.atttypid=t.oid and d.objoid=a.attrelid and d.objsubid=a.attnum;

5 查询所有表名称以及字段含义

代码语言:javascript
复制
select c.relname 表名,cast(obj_description(relfilenode,'pg_class') as varchar) 名称,a.attname 字段,d.description 字段备注,concat_ws('',t.typname,SUBSTRING(format_type(a.atttypid,a.atttypmod) from '\(.*\)')) as 列类型 from pg_class c,pg_attribute a,pg_type t,pg_description d
where a.attnum>0 and a.attrelid=c.oid and a.atttypid=t.oid and d.objoid=a.attrelid and d.objsubid=a.attnum
and c.relname in (select tablename from pg_tables where schemaname='public' and position('_2' in tablename)=0) order by c.relname,a.attnum
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-10-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 目录
  • 1 查看特定表名备注
  • 2 查看全部表名和备注
  • 3 查询全部都表名
  • 4 查看特定表名字段,字段类型,描述
  • 5 查询所有表名称以及字段含义
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档