跳转到主要内容
← 目录图谱 / pg_attribute

SYSTEM CATALOG · 系统目录

pg_attribute

The catalog pg_attribute stores information about table columns. There will be exactly one pg_attribute row for every column in every table in the database. (There will also be attribute entries for indexes, and indeed all objects that have pg_class entries.) The term attribute is equivalent to column and is used for historical reasons.

首次收录 PG 9.0最近收录 PG 19当前字段 25

已与 PostgreSQL 18.6 实例逐字段核对 · 原始实测记录 ↗

字段结构 PostgreSQL 18

pg_attribute
字段 / COLUMN类型 / TYPE说明 / DESCRIPTION
attrelid oidNOT NULL The table this column belongs to引用:pg_class.oid
attname nameNOT NULL The column name
atttypid oidNOT NULL The data type of this column (zero for a dropped column)引用:pg_type.oid
attlen smallintNOT NULL文档原写法:int2 A copy of pg_type.typlen of this column's type
attnum smallintNOT NULL文档原写法:int2 The number of the column. Ordinary columns are numbered from 1 up. System columns, such as ctid, have (arbitrary) negative numbers.
atttypmod integerNOT NULL文档原写法:int4 atttypmod records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). It is passed to type-specific input functions and length coercion functions. The value will generally be -1 for types that do not need atttypmod.
attndims smallintNOT NULL文档原写法:int2 Number of dimensions, if the column is an array type; otherwise 0. (Presently, the number of dimensions of an array is not enforced, so any nonzero value effectively means “it's an array”.)
attbyval booleanNOT NULL文档原写法:bool A copy of pg_type.typbyval of this column's type
attalign "char"NOT NULL文档原写法:char A copy of pg_type.typalign of this column's type
attstorage "char"NOT NULL文档原写法:char Normally a copy of pg_type.typstorage of this column's type. For TOAST-able data types, this can be altered after column creation to control storage policy.
attcompression "char"NOT NULL文档原写法:char The current compression method of the column. Typically this is '\0' to specify use of the current default setting (see default_toast_compression). Otherwise, 'p' selects pglz compression, while 'l' selects LZ4 compression. However, this field is ignored whenever attstorage does not allow compression.
attnotnull booleanNOT NULL文档原写法:bool This column has a (possibly invalid) not-null constraint.
atthasdef booleanNOT NULL文档原写法:bool This column has a default expression or generation expression, in which case there will be a corresponding entry in the pg_attrdef catalog that actually defines the expression. (Check attgenerated to determine whether this is a default or a generation expression.)
atthasmissing booleanNOT NULL文档原写法:bool This column has a value which is used where the column is entirely missing from the row, as happens when a column is added with a non-volatile DEFAULT value after the row is created. The actual value used is stored in the attmissingval column.
attidentity "char"NOT NULL文档原写法:char If a zero byte (''), then not an identity column. Otherwise, a = generated always, d = generated by default.
attgenerated "char"NOT NULL文档原写法:char If a zero byte (''), then not a generated column. Otherwise, s = stored, v = virtual. A stored generated column is physically stored like a normal column. A virtual generated column is physically stored as a null value, with the actual value being computed at run time.
attisdropped booleanNOT NULL文档原写法:bool This column has been dropped and is no longer valid. A dropped column is still physically present in the table, but is ignored by the parser and so cannot be accessed via SQL.
attislocal booleanNOT NULL文档原写法:bool This column is defined locally in the relation. Note that a column can be locally defined and inherited simultaneously.
attinhcount smallintNOT NULL文档原写法:int2 The number of direct ancestors this column has. A column with a nonzero number of ancestors cannot be dropped nor renamed.
attcollation oidNOT NULL The defined collation of the column, or zero if the column is not of a collatable data type引用:pg_collation.oid
attstattarget smallint文档原写法:int2 attstattarget controls the level of detail of statistics accumulated for this column by ANALYZE. A zero value indicates that no statistics should be collected. A null value says to use the system default statistics target. The exact meaning of positive values is data type-dependent. For scalar data types, attstattarget is both the target number of “most common values” to collect, and the target number of histogram bins to create.
attacl aclitem[] Column-level access privileges, if any have been granted specifically on this column
attoptions text[] Attribute-level options, as “keyword=value” strings
attfdwoptions text[] Attribute-level foreign data wrapper options, as “keyword=value” strings
attmissingval anyarray This column has a one element array containing the value used when the column is entirely missing from the row, as happens when the column is added with a non-volatile DEFAULT value after the row is created. The value is only used when atthasmissing is true. If there is no value the column is null.

标记“隐式列”的字段不包含在 SELECT * 中;部分早期统计视图由同版本源码补全,额外来源会显示在字段说明中。

通用系统列 6

PostgreSQL 提供的系统属性,通常不在 SELECT * 中展开。单独保留,不与普通字段混算。

字段类型attnum
tableoidoid-6
cmaxcid-5
xmaxxid-4
cmincid-3
xminxid-2
ctidtid-1

字段演化矩阵

悬停查看字段类型
存在新增 / 类型或属性变化移除
字段 / COLUMN9.09.19.29.39.49.59.610111213141516171819
attrelid
attname
atttypid
attstattarget
attlen
attnum
attndims
attcacheoff
atttypmod
attbyval
attstorage
attalign
attnotnull
atthasdef
attisdropped
attislocal
attinhcount
attacl
attoptions
attcollation
attfdwoptions
attidentity
atthasmissing
attmissingval
attgenerated
attcompression

9.0 是收录基线;基线中已存在的字段不标记为新增。矩阵按字段名称对齐,重命名显示为旧字段移除与新字段新增。

演化时间线

相邻大版本的变化

PostgreSQL 18 ← 17

− attcacheoff2 处字段说明更新

PostgreSQL 17 ← 16

~ attstattarget: not_null: true → false↕ 字段顺序变化1 处字段说明更新

PostgreSQL 16 ← 15

~ attinhcount: integer → smallint~ attndims: integer → smallint~ attstattarget: integer → smallint↕ 字段顺序变化

PostgreSQL 14 ← 13

+ attcompression↕ 字段顺序变化2 处字段说明更新

PostgreSQL 12 ← 11

+ attgenerated2 处字段说明更新

PostgreSQL 11 ← 10

+ atthasmissing+ attmissingval

PostgreSQL 10 ← 9.6

+ attidentity4 处字段说明更新

PostgreSQL 9.5 ← 9.4

1 处字段说明更新

PostgreSQL 9.2 ← 9.1

+ attfdwoptions

PostgreSQL 9.1 ← 9.0

+ attcollation

比较任意两个版本

选择两个版本,查看字段的新增、移除与类型变化。交互比较需要 JavaScript;演化时间线可直接阅读。