> 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/19/internals/catalogs/catalog-pg-attribute.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 52.7. pg\_attribute \#

### 52.7. `pg_attribute` [#](#catalog-pg-attribute) <a href="#catalog-pg-attribute" id="catalog-pg-attribute"></a>

系統目錄 `pg_attribute` 存放資料表欄位的相關資訊。資料庫中每個資料表的 每個欄位，在 `pg_attribute` 中都恰好有一筆資料列。 （索引也會有屬性項目，事實上所有在 [`pg_class`](https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-class.md) 中有項目的物件都會有。）

「屬性」（attribute）一詞等同於欄位，是基於歷史因素而沿用的。

#### 表 52.7. `pg_attribute` 欄位 [#](#catalog-pg-attribute-columns) <a href="#catalog-pg-attribute-columns" id="catalog-pg-attribute-columns"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>attrelid</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-class.md"><code>pg\_class</code></a>.<code>oid</code>）</p><p>此欄位所屬的資料表</p>                                                                                                                                                                                                 |
| <p><code>attname</code> <code>name</code></p><p>欄位名稱</p>                                                                                                                                                                                                                                                                                                                                      |
| <p><code>atttypid</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-type.md"><code>pg\_type</code></a>.<code>oid</code>）</p><p>此欄位的資料型別（已移除的欄位為零）</p>                                                                                                                                                                                          |
| <p><code>attlen</code> <code>int2</code></p><p>此欄位型別之 <code>pg\_type.typlen</code> 的副本</p>                                                                                                                                                                                                                                                                                                    |
| <p><code>attnum</code> <code>int2</code></p><p>欄位的編號。一般欄位從 1 開始 往上編號。系統欄位（例如 <code>ctid</code>） 具有（任意的）負數編號。</p>                                                                                                                                                                                                                                                                              |
| <p><code>atttypmod</code> <code>int4</code></p><p><code>atttypmod</code> 記錄在建立資料表時提供的型別專屬資料（例如 <code>varchar</code> 欄位的最大長度）。它會被傳遞給 型別專屬的輸入函式與長度強制轉換函式。 對於不需要 <code>atttypmod</code> 的型別，其值通常為 -1。</p>                                                                                                                                                                                        |
| <p><code>attndims</code> <code>int2</code></p><p>若此欄位是陣列型別，則為維度數；否則為 0。 （目前並不強制檢查陣列的維度數， 因此任何非零值實際上都表示“這是陣列”。）</p>                                                                                                                                                                                                                                                                            |
| <p><code>attbyval</code> <code>bool</code></p><p>此欄位型別之 <code>pg\_type.typbyval</code> 的副本</p>                                                                                                                                                                                                                                                                                                |
| <p><code>attalign</code> <code>char</code></p><p>此欄位型別之 <code>pg\_type.typalign</code> 的副本</p>                                                                                                                                                                                                                                                                                                |
| <p><code>attstorage</code> <code>char</code></p><p>通常是此欄位型別之 <code>pg\_type.typstorage</code> 的副本。 對於可 TOAST 的資料型別，可以在建立欄位之後變更此值， 以控制儲存策略。</p>                                                                                                                                                                                                                                                |
| <p><code>attcompression</code> <code>char</code></p><p>此欄位目前的壓縮方法。通常為 <code>'\0'</code>，表示使用目前的預設設定 （請參閱 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-DEFAULT-TOAST-COMPRESSION">default\_toast\_compression</a>）。否則， <code>'p'</code> 選擇 pglz 壓縮，而 <code>'l'</code> 選擇 LZ4 壓縮。不過，只要 <code>attstorage</code> 不允許 壓縮，此欄位就會被忽略。</p> |
| <p><code>attnotnull</code> <code>bool</code></p><p>此欄位具有（可能無效的）非空值限制條件。</p>                                                                                                                                                                                                                                                                                                                   |
| <p><code>atthasdef</code> <code>bool</code></p><p>此欄位具有預設值運算式或產生運算式；在這種情況下， <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-attrdef.md"><code>pg\_attrdef</code></a> 系統目錄中會有一筆對應的項目， 實際定義該運算式。（請檢查 <code>attgenerated</code>， 以判斷這是預設值運算式還是產生運算式。）</p>                                                                                                                   |
| <p><code>atthasmissing</code> <code>bool</code></p><p>此欄位有一個值，用於資料列中完全缺少該欄位的情況； 在資料列建立之後，以非揮發性的 <code>DEFAULT</code> 值新增欄位時，就會發生這種情況。 實際使用的值存放在 <code>attmissingval</code> 欄位中。</p>                                                                                                                                                                                                           |
| <p><code>attidentity</code> <code>char</code></p><p>若為零位元組（<code>''</code>），則不是識別欄位。 否則，<code>a</code> = 一律產生（GENERATED ALWAYS）， <code>d</code> = 預設產生（GENERATED BY DEFAULT）。</p>                                                                                                                                                                                                             |
| <p><code>attgenerated</code> <code>char</code></p><p>若為零位元組（<code>''</code>），則不是產生欄位。 否則，<code>s</code> = 儲存式（stored），<code>v</code> = 虛擬（virtual）。儲存式產生欄位會像一般欄位一樣實體存放。 虛擬產生欄位在實體上存放為 null 值， 實際值則在執行時期計算。</p>                                                                                                                                                                                |
| <p><code>attisdropped</code> <code>bool</code></p><p>此欄位已被移除，不再有效。已移除的欄位 在實體上仍存在於資料表中，但會被剖析器忽略， 因此無法透過 SQL 存取。</p>                                                                                                                                                                                                                                                                            |
| <p><code>attislocal</code> <code>bool</code></p><p>此欄位是在該關聯中本地定義的。請注意，一個欄位可以 同時是本地定義的與繼承而來的。</p>                                                                                                                                                                                                                                                                                              |
| <p><code>attinhcount</code> <code>int2</code></p><p>此欄位擁有的直接祖先數量。祖先數量不為零的欄位 既不能被移除，也不能被重新命名。</p>                                                                                                                                                                                                                                                                                              |
| <p><code>attcollation</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-collation.md"><code>pg\_collation</code></a>.<code>oid</code>）</p><p>此欄位所定義的定序；若此欄位 不是可定序的資料型別，則為零</p>                                                                                                                                                                 |
| <p><code>attstattarget</code> <code>int2</code></p><p><code>attstattarget</code> 控制 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-analyze.md"><code>ANALYZE</code></a> 為此欄位所累積之統計資訊的詳細程度。 零值表示不應收集任何統計資訊。 null 值表示使用系統預設的統計目標。 正值的確切意義取決於資料型別。 對於純量資料型別，<code>attstattarget</code> 既是要收集的“最常見值”的目標數量，也是要建立的直方圖區間的目標數量。</p>                                                |
| <p><code>attacl</code> <code>aclitem\[]</code></p><p>欄位層級的存取權限（若有專門針對此欄位授予的權限）</p>                                                                                                                                                                                                                                                                                                            |
| <p><code>attoptions</code> <code>text\[]</code></p><p>屬性層級選項，以“keyword=value”字串表示</p>                                                                                                                                                                                                                                                                                                         |
| <p><code>attfdwoptions</code> <code>text\[]</code></p><p>屬性層級的外部資料包裝器選項，以“keyword=value”字串表示</p>                                                                                                                                                                                                                                                                                              |
| <p><code>attmissingval</code> <code>anyarray</code></p><p>此欄位含有一個單元素陣列，其中包含資料列中完全缺少該欄位時所使用的值； 在資料列建立之後，以非揮發性的 <code>DEFAULT</code> 值新增該欄位時， 就會發生這種情況。只有在 <code>atthasmissing</code> 為 true 時才會使用此值。 若沒有值，此欄位為 null。</p>                                                                                                                                                                       |

<br>

在已移除欄位的 `pg_attribute` 項目中， `atttypid` 會被重設為零，但 `attlen` 以及其他從 [`pg_type`](https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-type.md) 複製而來的欄位仍然有效。之所以需要這樣的安排， 是為了應付已移除欄位的資料型別後來也被移除、因而 `pg_type` 中已不再有對應資料列的情況。 `attlen` 與其他欄位可用來解讀資料表中資料列的內容。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/catalog-pg-attribute.html)（原文版本：18.6；核對日期：2026-10-17）


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
