杜燕明

杜燕明

Anno框架交流:478399354 欢迎大家加群相互交流!

PostgreSQL查询表名称及表结构

1. 查询表名称

在psql状态下查询表名称

\dt  



SQL方式查看表名称

 SELECT tablename FROM pg_tables;  

 

SELECT   viewname   FROM   pg_views  
WHERE     schemaname ='public'  

PostgreSQL获取数据库中所有view名 视图

SELECT   viewname   FROM   pg_views  
WHERE     schemaname ='public'

2. 查询表结构

在psql状态下查询表结构

 \d tablename  


SQL方式查看表结构

SELECT a.attnum,
a.attname AS field,
t.typname AS type,
a.attlen AS length,
a.atttypmod AS lengthvar,
a.attnotnull AS notnull,
b.description AS comment
FROM pg_class c,
pg_attribute a
LEFT OUTER JOIN pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid,
pg_type t
WHERE c.relname = 'udoc_saldiscount'
and a.attnum > 0
and a.attrelid = c.oid
and a.atttypid = t.oid
ORDER BY a.attnum;

posted @ 2017-10-10 15:45  杜燕明  阅读(102345)  评论(0编辑  收藏  举报