> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/internals/catalogs/catalog-pg-attribute.md).

# 52.7. 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`](/internals/catalogs/catalog-pg-class.md) entries.)

The term attribute is equivalent to column and is used for historical reasons.

**Table 52.7. `pg_attribute` Columns**

| <p>Column Type</p><p>Description</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>attrelid</code> <code>oid</code> (references <a href="/pages/b1fii6hWVNacZFXaxWON"><code>pg\_class</code></a>.<code>oid</code>)</p><p>The table this column belongs to</p>                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>attname</code> <code>name</code></p><p>The column name</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>atttypid</code> <code>oid</code> (references <a href="/pages/Rnbzy6x669U98OjJh3D7"><code>pg\_type</code></a>.<code>oid</code>)</p><p>The data type of this column (zero for a dropped column)</p>                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><code>attlen</code> <code>int2</code></p><p>A copy of <code>pg\_type.typlen</code> of this column's type</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| <p><code>attnum</code> <code>int2</code></p><p>The number of the column. Ordinary columns are numbered from 1 up. System columns, such as <code>ctid</code>, have (arbitrary) negative numbers.</p>                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>atttypmod</code> <code>int4</code></p><p><code>atttypmod</code> records type-specific data supplied at table creation time (for example, the maximum length of a <code>varchar</code> 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 <code>atttypmod</code>.</p>                                                                                                                                                                                                                   |
| <p><code>attndims</code> <code>int2</code></p><p>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”.)</p>                                                                                                                                                                                                                                                                                                                                           |
| <p><code>attbyval</code> <code>bool</code></p><p>A copy of <code>pg\_type.typbyval</code> of this column's type</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>attalign</code> <code>char</code></p><p>A copy of <code>pg\_type.typalign</code> of this column's type</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>attstorage</code> <code>char</code></p><p>Normally a copy of <code>pg\_type.typstorage</code> of this column's type. For TOAST-able data types, this can be altered after column creation to control storage policy.</p>                                                                                                                                                                                                                                                                                                                                                            |
| <p><code>attcompression</code> <code>char</code></p><p>The current compression method of the column. Typically this is <code>'\0'</code> to specify use of the current default setting (see <a href="/pages/kv4bHT02CeSrSMpfX0AZ#GUC-DEFAULT-TOAST-COMPRESSION">default\_toast\_compression</a>). Otherwise, <code>'p'</code> selects pglz compression, while <code>'l'</code> selects LZ4 compression. However, this field is ignored whenever <code>attstorage</code> does not allow compression.</p>                                                                                      |
| <p><code>attnotnull</code> <code>bool</code></p><p>This column has a (possibly invalid) not-null constraint.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><code>atthasdef</code> <code>bool</code></p><p>This column has a default expression or generation expression, in which case there will be a corresponding entry in the <a href="/pages/lHDyExdNZNcCzFF74aes"><code>pg\_attrdef</code></a> catalog that actually defines the expression. (Check <code>attgenerated</code> to determine whether this is a default or a generation expression.)</p>                                                                                                                                                                                          |
| <p><code>atthasmissing</code> <code>bool</code></p><p>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 <code>DEFAULT</code> value after the row is created. The actual value used is stored in the <code>attmissingval</code> column.</p>                                                                                                                                                                                                                                                      |
| <p><code>attidentity</code> <code>char</code></p><p>If a zero byte (<code>''</code>), then not an identity column. Otherwise, <code>a</code> = generated always, <code>d</code> = generated by default.</p>                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>attgenerated</code> <code>char</code></p><p>If a zero byte (<code>''</code>), then not a generated column. Otherwise, <code>s</code> = stored, <code>v</code> = 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.</p>                                                                                                                                                                                                                |
| <p><code>attisdropped</code> <code>bool</code></p><p>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.</p>                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>attislocal</code> <code>bool</code></p><p>This column is defined locally in the relation. Note that a column can be locally defined and inherited simultaneously.</p>                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>attinhcount</code> <code>int2</code></p><p>The number of direct ancestors this column has. A column with a nonzero number of ancestors cannot be dropped nor renamed.</p>                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>attcollation</code> <code>oid</code> (references <a href="/pages/NXiMpFyxCVHCoDPqdrtW"><code>pg\_collation</code></a>.<code>oid</code>)</p><p>The defined collation of the column, or zero if the column is not of a collatable data type</p>                                                                                                                                                                                                                                                                                                                                       |
| <p><code>attstattarget</code> <code>int2</code></p><p><code>attstattarget</code> controls the level of detail of statistics accumulated for this column by <a href="/pages/-LBxTh9Zm5_YS7bTGgfk"><code>ANALYZE</code></a>. 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, <code>attstattarget</code> is both the target number of “most common values” to collect, and the target number of histogram bins to create.</p> |
| <p><code>attacl</code> <code>aclitem\[]</code></p><p>Column-level access privileges, if any have been granted specifically on this column</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>attoptions</code> <code>text\[]</code></p><p>Attribute-level options, as “keyword=value” strings</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>attfdwoptions</code> <code>text\[]</code></p><p>Attribute-level foreign data wrapper options, as “keyword=value” strings</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>attmissingval</code> <code>anyarray</code></p><p>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 <code>DEFAULT</code> value after the row is created. The value is only used when <code>atthasmissing</code> is true. If there is no value the column is null.</p>                                                                                                                                                                                          |

<br>

In a dropped column's `pg_attribute` entry, `atttypid` is reset to zero, but `attlen` and the other fields copied from [`pg_type`](/internals/catalogs/catalog-pg-type.md) 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.

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/catalog-pg-attribute.html)（英文原文，待翻譯）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.postgresql.tw/internals/catalogs/catalog-pg-attribute.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
