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

# 52.2. pg\_aggregate \#

### 52.2. `pg_aggregate` [#](#catalog-pg-aggregate) <a href="#catalog-pg-aggregate" id="catalog-pg-aggregate"></a>

目錄 `pg_aggregate` 儲存彙總函式的相關資訊。 彙總函式是一種對一組值（通常是每個符合查詢條件之資料列中的某一個欄位） 進行運算，並傳回由所有這些值計算出之單一值的函式。 典型的彙總函式有 `sum`、`count` 與 `max`。`pg_aggregate` 中的每一筆項目 都是 [`pg_proc`](https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md) 中某一筆項目的延伸。 該 `pg_proc` 項目記載彙總函式的名稱、 輸入與輸出資料型別，以及其他與一般函式相似的資訊。

#### 表 52.2. `pg_aggregate` 欄位 [#](#catalog-pg-aggregate-columns) <a href="#catalog-pg-aggregate-columns" id="catalog-pg-aggregate-columns"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                        |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>aggfnoid</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>彙總函式的 <code>pg\_proc</code> OID</p>       |
| <p><code>aggkind</code> <code>char</code></p><p>彙總函式種類： <code>n</code> 表示「一般」彙總函式， <code>o</code> 表示「有序集合」彙總函式， <code>h</code> 表示「假設集合」彙總函式</p>                                                                             |
| <p><code>aggnumdirectargs</code> <code>int2</code></p><p>有序集合或假設集合彙總函式的直接（非彙總）引數數量， 可變引數陣列計為一個引數。 若等於 <code>pronargs</code>，則該彙總函式必須是可變引數（variadic）的， 且該可變引數陣列同時描述被彙總的引數 與最後的直接引數。 一般彙總函式一律為零。</p>                          |
| <p><code>aggtransfn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>轉換函式</p>                                |
| <p><code>aggfinalfn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>最終函式（若無則為零）</p>                         |
| <p><code>aggcombinefn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>合併函式（若無則為零）</p>                       |
| <p><code>aggserialfn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>序列化函式（若無則為零）</p>                       |
| <p><code>aggdeserialfn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>反序列化函式（若無則為零）</p>                    |
| <p><code>aggmtransfn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>移動彙總模式的正向轉換函式（若無則為零）</p>               |
| <p><code>aggminvtransfn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>移動彙總模式的反向轉換函式（若無則為零）</p>            |
| <p><code>aggmfinalfn</code> <code>regproc</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-proc.md"><code>pg\_proc</code></a>.<code>oid</code>）</p><p>移動彙總模式的最終函式（若無則為零）</p>                 |
| <p><code>aggfinalextra</code> <code>bool</code></p><p>為真時，會傳遞額外的虛擬引數給 <code>aggfinalfn</code></p>                                                                                                                           |
| <p><code>aggmfinalextra</code> <code>bool</code></p><p>為真時，會傳遞額外的虛擬引數給 <code>aggmfinalfn</code></p>                                                                                                                         |
| <p><code>aggfinalmodify</code> <code>char</code></p><p><code>aggfinalfn</code> 是否會修改 轉換狀態值： <code>r</code> 表示它是唯讀的， <code>s</code> 表示 <code>aggtransfn</code> 不能在 <code>aggfinalfn</code> 之後套用， <code>w</code> 表示它會寫入該值</p> |
| <p><code>aggmfinalmodify</code> <code>char</code></p><p>與 <code>aggfinalmodify</code> 相同，但適用於 <code>aggmfinalfn</code></p>                                                                                                  |
| <p><code>aggsortop</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-operator.md"><code>pg\_operator</code></a>.<code>oid</code>）</p><p>相關聯的排序運算子（若無則為零）</p>                 |
| <p><code>aggtranstype</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>aggtransspace</code> <code>int4</code></p><p>轉換狀態資料的大約平均大小（以位元組為單位）， 或為零以使用預設估計值</p>                                                                                                                               |
| <p><code>aggmtranstype</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>aggmtransspace</code> <code>int4</code></p><p>移動彙總模式下轉換狀態資料的大約平均大小（以位元組為單位）， 或為零以使用預設估計值</p>                                                                                                                       |
| <p><code>agginitval</code> <code>text</code></p><p>轉換狀態的初始值。這是一個文字欄位， 以外部字串表示法存放初始值。 若此欄位為 null，轉換狀態值 一開始即為 null。</p>                                                                                                       |
| <p><code>aggminitval</code> <code>text</code></p><p>移動彙總模式下轉換狀態的初始值。 這是一個文字欄位，以外部字串表示法 存放初始值。若此欄位為 null，轉換狀態值 一開始即為 null。</p>                                                                                               |

<br>

新的彙總函式以 [`CREATE AGGREGATE`](https://docs.postgresql.tw/19/reference/sql-commands/sql-createaggregate.md) 命令註冊。關於撰寫彙總函式以及轉換函式等的意義， 更多資訊請參閱[第 36.12 節](https://docs.postgresql.tw/19/server-programming/extend/xaggr.md)。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/catalog-pg-aggregate.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-aggregate.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.
