pg_attribute
表中存储了每个表的属性信息,此表的 pg_attribute.attrelid
字段是每个表在对应的 pg_class.oid
的值。
例如获取pg_attribute
表自己的字段定义信息的命令如下:
select
attrelid,
attnum,
attname,
attnotnull
from
pg_attribute
where
attrelid = (select oid from pg_class where relname = 'pg_attribute') order by attnum;
查询结果
attrelid | attnum | attname | attnotnull
----------+--------+---------------+------------
1249 | -7 | tableoid | t
1249 | -6 | cmax | t
1249 | -5 | xmax | t
1249 | -4 | cmin | t
1249 | -3 | xmin | t
1249 | -1 | ctid | t
1249 | 1 | attrelid | t
1249 | 2 | attname | t
1249 | 3 | atttypid | t
1249 | 4 | attstattarget | t
1249 | 5 | attlen | t
1249 | 6 | attnum | t
1249 | 7 | attndims | t
1249 | 8 | attcacheoff | t
1249 | 9 | atttypmod | t
1249 | 10 | attbyval | t
1249 | 11 | attstorage | t
1249 | 12 | attalign | t
1249 | 13 | attnotnull | t
1249 | 14 | atthasdef | t
1249 | 15 | attidentity | t
1249 | 16 | attisdropped | t
1249 | 17 | attislocal | t
1249 | 18 | attinhcount | t
1249 | 19 | attcollation | t
1249 | 20 | attacl | f
1249 | 21 | attoptions | f
1249 | 22 | attfdwoptions | f
(28 rows)