pg_attribute 是一个 系统目录 表,用于存储数据库对象的列信息。
pg_attribute 始终存在于 PostgreSQL 中。
按 PostgreSQL 版本定义
pg_attribute (PostgreSQL 19)
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 |
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 18)
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 |
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 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 18
- 已删除列
attcacheoff(提交 02a8d0c4)
- 已删除列
- 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
