声明:本PostgreSQl实用指南系列为刘兴(http://deepfuture.iteye.com/)原创,未经笔者授权,任何人和机构不能转载
SQL方式查看表结构(表名是student)
mydb=# SELECT a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a
.atttypmod AS lengthvar,a.attnotnull AS notnull
mydb-# FROM pg_class c,pg_attribute a,pg_type t
mydb-# WHERE c.relname = 'student' and a.attnum > 0 and a.attrelid = c.oid and a
.atttypid = t.oid
mydb-# ORDER BY a.attnum;
attnum | field | type | length | lengthvar | notnull
--------+-------+---------+--------+-----------+---------
1 | name | varchar | -1 | 24 | f
2 | age | int4 | 4 | -1 | f
3 | city | int4 | 4 | -1 | f
(3 rows)
命令方式
mydb=# \d student
Table "public.student"
Column | Type | Modifie