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;

    原文作者:PostgreSQL
    原文地址: https://www.cnblogs.com/duyanming/p/7646022.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞