1. 程式人生 > >PostgreSQL查詢表名稱及表結構

PostgreSQL查詢表名稱及表結構

1. 查詢表名稱

在psql狀態下查詢表名稱

\dt  



SQL方式查看錶名稱

 SELECT tablename FROM pg_tables;  

 

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;

 

轉自:https://www.cnblogs.com/duyanming/p/7646022.html