pg_attribute
是一个存储数据库对象列信息的系统目录表。
pg_attribute
一直存在于 PostgreSQL 中。
按 PostgreSQL 版本定义
pg_attribute (PostgreSQL 17)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ----------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attndims | smallint | | not null | attbyval | boolean | | not null | attalign | "char" | | not null | attstorage | "char" | | not null | attcompression | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | atthasmissing | boolean | | not null | attidentity | "char" | | not null | attgenerated | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | smallint | | not null | attcollation | oid | | not null | attstattarget | smallint | | | attacl | aclitem[] | | | attoptions | text[] | C | | attfdwoptions | text[] | C | | attmissingval | anyarray | | | Indexes: "pg_attribute_relid_attnum_index" PRIMARY KEY, btree (attrelid, attnum) "pg_attribute_relid_attnam_index" UNIQUE CONSTRAINT, btree (attrelid, attname)
文档: pg_attribute
pg_attribute (PostgreSQL 16)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ----------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attndims | smallint | | not null | attbyval | boolean | | not null | attalign | "char" | | not null | attstorage | "char" | | not null | attcompression | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | atthasmissing | boolean | | not null | attidentity | "char" | | not null | attgenerated | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | smallint | | not null | attstattarget | smallint | | not null | attcollation | oid | | not null | attacl | aclitem[] | | | attoptions | text[] | C | | attfdwoptions | text[] | C | | attmissingval | anyarray | | | Indexes: "pg_attribute_relid_attnum_index" PRIMARY KEY, btree (attrelid, attnum) "pg_attribute_relid_attnam_index" UNIQUE CONSTRAINT, btree (attrelid, attname)
文档: pg_attribute
pg_attribute (PostgreSQL 15)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ----------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attstattarget | integer | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attndims | integer | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attbyval | boolean | | not null | attalign | "char" | | not null | attstorage | "char" | | not null | attcompression | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | atthasmissing | boolean | | not null | attidentity | "char" | | not null | attgenerated | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | integer | | not null | attcollation | oid | | not null | attacl | aclitem[] | | | attoptions | text[] | C | | attfdwoptions | text[] | C | | attmissingval | anyarray | | | Indexes: "pg_attribute_relid_attnum_index" PRIMARY KEY, btree (attrelid, attnum) "pg_attribute_relid_attnam_index" UNIQUE CONSTRAINT, btree (attrelid, attname)
文档: pg_attribute
pg_attribute (PostgreSQL 14)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ----------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attstattarget | integer | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attndims | integer | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attbyval | boolean | | not null | attalign | "char" | | not null | attstorage | "char" | | not null | attcompression | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | atthasmissing | boolean | | not null | attidentity | "char" | | not null | attgenerated | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | integer | | not null | attcollation | oid | | not null | attacl | aclitem[] | | | attoptions | text[] | C | | attfdwoptions | text[] | C | | attmissingval | anyarray | | | Indexes: "pg_attribute_relid_attnum_index" PRIMARY KEY, btree (attrelid, attnum) "pg_attribute_relid_attnam_index" UNIQUE CONSTRAINT, btree (attrelid, attname)
文档: pg_attribute
pg_attribute (PostgreSQL 13)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ---------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attstattarget | integer | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attndims | integer | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attbyval | boolean | | not null | attstorage | "char" | | not null | attalign | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | atthasmissing | boolean | | not null | attidentity | "char" | | not null | attgenerated | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | integer | | not null | attcollation | oid | | not null | attacl | aclitem[] | | | attoptions | text[] | C | | attfdwoptions | text[] | C | | attmissingval | anyarray | | | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 12)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ---------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attstattarget | integer | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attndims | integer | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attbyval | boolean | | not null | attstorage | "char" | | not null | attalign | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | atthasmissing | boolean | | not null | attidentity | "char" | | not null | attgenerated | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | integer | | not null | attcollation | oid | | not null | attacl | aclitem[] | | | attoptions | text[] | C | | attfdwoptions | text[] | C | | attmissingval | anyarray | | | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 11)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ---------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attstattarget | integer | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attndims | integer | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attbyval | boolean | | not null | attstorage | "char" | | not null | attalign | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | atthasmissing | boolean | | not null | attidentity | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | integer | | not null | attcollation | oid | | not null | attacl | aclitem[] | | | attoptions | text[] | | | attfdwoptions | text[] | | | attmissingval | anyarray | | | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 10)
Table "pg_catalog.pg_attribute" Column | Type | Collation | Nullable | Default ---------------+-----------+-----------+----------+--------- attrelid | oid | | not null | attname | name | | not null | atttypid | oid | | not null | attstattarget | integer | | not null | attlen | smallint | | not null | attnum | smallint | | not null | attndims | integer | | not null | attcacheoff | integer | | not null | atttypmod | integer | | not null | attbyval | boolean | | not null | attstorage | "char" | | not null | attalign | "char" | | not null | attnotnull | boolean | | not null | atthasdef | boolean | | not null | attidentity | "char" | | not null | attisdropped | boolean | | not null | attislocal | boolean | | not null | attinhcount | integer | | not null | attcollation | oid | | not null | attacl | aclitem[] | | | attoptions | text[] | | | attfdwoptions | text[] | | | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 9.6)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attcollation | oid | not null attacl | aclitem[] | attoptions | text[] | attfdwoptions | text[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 9.5)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attcollation | oid | not null attacl | aclitem[] | attoptions | text[] | attfdwoptions | text[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 9.4)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attcollation | oid | not null attacl | aclitem[] | attoptions | text[] | attfdwoptions | text[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 9.3)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attcollation | oid | not null attacl | aclitem[] | attoptions | text[] | attfdwoptions | text[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 9.2)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attcollation | oid | not null attacl | aclitem[] | attoptions | text[] | attfdwoptions | text[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 9.1)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attcollation | oid | not null attacl | aclitem[] | attoptions | text[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 9.0)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attacl | aclitem[] | attoptions | text[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 8.4)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+-----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null attacl | aclitem[] | Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 8.3)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
pg_attribute (PostgreSQL 8.2)
Table "pg_catalog.pg_attribute" Column | Type | Modifiers ---------------+----------+----------- attrelid | oid | not null attname | name | not null atttypid | oid | not null attstattarget | integer | not null attlen | smallint | not null attnum | smallint | not null attndims | integer | not null attcacheoff | integer | not null atttypmod | integer | not null attbyval | boolean | not null attstorage | "char" | not null attalign | "char" | not null attnotnull | boolean | not null atthasdef | boolean | not null attisdropped | boolean | not null attislocal | boolean | not null attinhcount | integer | not null Indexes: "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname) "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
文档: pg_attribute
更改历史记录
- PostgreSQL 17
- PostgreSQL 16
- 列
attndims
、attstattarget
和attinhcount
从INTEGER
更改为SMALLINT
(提交90189eef)
- 列
- PostgreSQL 14
- 添加列
attcompression
(提交bbe0a81d)
- 添加列
- PostgreSQL 12
- 添加列
attgenerated
(提交fc22b662)
- 添加列
- PostgreSQL 11
- PostgreSQL 10
- 添加列
attidentity
(提交32173270)
- 添加列
- PostgreSQL 9.2
- 添加列
attfdwoptions
(提交c4096c76)
- 添加列
- PostgreSQL 9.1
- 添加列
attcollation
(提交414c5a2e)
- 添加列
- PostgreSQL 9.0
- 添加列
attoptions
(提交76a47c0e)
- 添加列
- PostgreSQL 8.4
- 添加列
attacl
(提交3cb5d658)
- 添加列
- PostgreSQL 8.0
- 删除列
attisset
(提交375369ac)
- 删除列
- PostgreSQL 7.3
- PostgreSQL 7.2
示例
简单单列表的 pg_attribute
示例内容
postgres=# CREATE TABLE foo (id INT NOT NULL); CREATE TABLE postgres=# SELECT * FROM pg_attribute WHERE attrelid='foo'::regclass AND attnum > 0; -[ RECORD 1 ]--+------ attrelid | 16418 attname | id atttypid | 23 attstattarget | -1 attlen | 4 attnum | 1 attndims | 0 attcacheoff | -1 atttypmod | -1 attbyval | t attstorage | p attalign | i attnotnull | t atthasdef | f atthasmissing | f attidentity | attgenerated | attisdropped | f attislocal | t attinhcount | 0 attcollation | 0 attcompression | attacl | attoptions | attfdwoptions | attmissingval |
参考文献
- PostgreSQL 文档: pg_attribute