Postgresql 中文操作指南
53.7. pg_attribute #
目录 pg_attribute 存储有关表列的信息。数据库中每个表中的每列都将精确地对应一行 pg_attribute 。索引也会有属性条目,实际上,所有有 pg_class 条目的对象也都会有属性条目。
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.
Table 53.7. pg_attribute Columns
Table 53.7. pg_attribute Columns
Column Type Description |
attrelid oid (references pg_class.oid) The table this column belongs to |
attname name The column name |
atttypid oid (references pg_type.oid) The data type of this column (zero for a dropped column) |
attlen int2 A copy of pg_type.typlen of this column’s type |
attnum int2 The number of the column. Ordinary columns are numbered from 1 up. System columns, such as ctid, have (arbitrary) negative numbers. |
attcacheoff int4 Always -1 in storage, but when loaded into a row descriptor in memory this might be updated to cache the offset of the attribute within the row |
atttypmod 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 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 bool A copy of pg_type.typbyval of this column’s type |
attalign char A copy of pg_type.typalign of this column’s type |
attstorage 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 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 bool This represents a not-null constraint. |
atthasdef 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 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 If a zero byte (''), then not an identity column. Otherwise, a = generated always, d = generated by default. |
attgenerated char If a zero byte (''), then not a generated column. Otherwise, s = stored. (Other values might be added in the future.) |
attisdropped 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 bool This column is defined locally in the relation. Note that a column can be locally defined and inherited simultaneously. |
attinhcount int2 The number of direct ancestors this column has. A column with a nonzero number of ancestors cannot be dropped nor renamed. |
attstattarget 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 negative 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. |
attcollation oid (references pg_collation.oid) The defined collation of the column, or zero if the column is not of a collatable data type |
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. |
在已删除列的 pg_attribute 条目中, atttypid 重置为 0,但 attlen 和从 pg_type 复制的其他字段仍然有效。需要此种区分,才能应对已删除列的数据类型后来已删除(因此不再存在 pg_type 行)的情况。 attlen 和其他字段可用于解释表的行的内容。
In a dropped column’s pg_attribute entry, atttypid is reset to zero, but attlen and the other fields copied from pg_type are still valid. This arrangement is needed to cope with the situation where the dropped column’s data type was later dropped, and so there is no pg_type row anymore. attlen and the other fields can be used to interpret the contents of a row of the table.