1. 程式人生 > >PostGreSQL用命令列方式查詢表結構

PostGreSQL用命令列方式查詢表結構

需要用Python來查詢PostGreSQL資料庫的表結構,以前都是隨便select一條資訊來看錶都有哪些colnum的。但是如果表是空的話,就不好使了。網上查了一下,找到一種方法。

如果我的表是desaru。

SELECT a.attname from pg_class c,pg_attribute a,pg_type t where c.relname='desaru' and a.attnum>0 and a.attrelid=c.oid and a.atttypid=t.oid