> 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-aggregate.md).

# 52.2. pg\_aggregate \#

The catalog `pg_aggregate` stores information about aggregate functions. An aggregate function is a function that operates on a set of values (typically one column from each row that matches a query condition) and returns a single value computed from all these values. Typical aggregate functions are `sum`, `count`, and `max`. Each entry in `pg_aggregate` is an extension of an entry in [`pg_proc`](/internals/catalogs/catalog-pg-proc.md). The `pg_proc` entry carries the aggregate's name, input and output data types, and other information that is similar to ordinary functions.

**Table 52.2. `pg_aggregate` Columns**

| <p>Column Type</p><p>Description</p>                                                                                                                                                                                                                                                                                                                                                                       |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>aggfnoid</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p><code>pg\_proc</code> OID of the aggregate function</p>                                                                                                                                                                                                  |
| <p><code>aggkind</code> <code>char</code></p><p>Aggregate kind: <code>n</code> for “normal” aggregates, <code>o</code> for “ordered-set” aggregates, or <code>h</code> for “hypothetical-set” aggregates</p>                                                                                                                                                                                               |
| <p><code>aggnumdirectargs</code> <code>int2</code></p><p>Number of direct (non-aggregated) arguments of an ordered-set or hypothetical-set aggregate, counting a variadic array as one argument. If equal to <code>pronargs</code>, the aggregate must be variadic and the variadic array describes the aggregated arguments as well as the final direct arguments. Always zero for normal aggregates.</p> |
| <p><code>aggtransfn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Transition function</p>                                                                                                                                                                                                                                |
| <p><code>aggfinalfn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Final function (zero if none)</p>                                                                                                                                                                                                                      |
| <p><code>aggcombinefn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Combine function (zero if none)</p>                                                                                                                                                                                                                  |
| <p><code>aggserialfn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Serialization function (zero if none)</p>                                                                                                                                                                                                             |
| <p><code>aggdeserialfn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Deserialization function (zero if none)</p>                                                                                                                                                                                                         |
| <p><code>aggmtransfn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Forward transition function for moving-aggregate mode (zero if none)</p>                                                                                                                                                                              |
| <p><code>aggminvtransfn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Inverse transition function for moving-aggregate mode (zero if none)</p>                                                                                                                                                                           |
| <p><code>aggmfinalfn</code> <code>regproc</code> (references <a href="/pages/8TiLY9QeJalZY0OBAANF"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Final function for moving-aggregate mode (zero if none)</p>                                                                                                                                                                                           |
| <p><code>aggfinalextra</code> <code>bool</code></p><p>True to pass extra dummy arguments to <code>aggfinalfn</code></p>                                                                                                                                                                                                                                                                                    |
| <p><code>aggmfinalextra</code> <code>bool</code></p><p>True to pass extra dummy arguments to <code>aggmfinalfn</code></p>                                                                                                                                                                                                                                                                                  |
| <p><code>aggfinalmodify</code> <code>char</code></p><p>Whether <code>aggfinalfn</code> modifies the transition state value: <code>r</code> if it is read-only, <code>s</code> if the <code>aggtransfn</code> cannot be applied after the <code>aggfinalfn</code>, or <code>w</code> if it writes on the value</p>                                                                                          |
| <p><code>aggmfinalmodify</code> <code>char</code></p><p>Like <code>aggfinalmodify</code>, but for the <code>aggmfinalfn</code></p>                                                                                                                                                                                                                                                                         |
| <p><code>aggsortop</code> <code>oid</code> (references <a href="/pages/gJEllT61m6FTxxJgK6D0"><code>pg\_operator</code></a>.<code>oid</code>)</p><p>Associated sort operator (zero if none)</p>                                                                                                                                                                                                             |
| <p><code>aggtranstype</code> <code>oid</code> (references <a href="/pages/Rnbzy6x669U98OjJh3D7"><code>pg\_type</code></a>.<code>oid</code>)</p><p>Data type of the aggregate function's internal transition (state) data</p>                                                                                                                                                                               |
| <p><code>aggtransspace</code> <code>int4</code></p><p>Approximate average size (in bytes) of the transition state data, or zero to use a default estimate</p>                                                                                                                                                                                                                                              |
| <p><code>aggmtranstype</code> <code>oid</code> (references <a href="/pages/Rnbzy6x669U98OjJh3D7"><code>pg\_type</code></a>.<code>oid</code>)</p><p>Data type of the aggregate function's internal transition (state) data for moving-aggregate mode (zero if none)</p>                                                                                                                                     |
| <p><code>aggmtransspace</code> <code>int4</code></p><p>Approximate average size (in bytes) of the transition state data for moving-aggregate mode, or zero to use a default estimate</p>                                                                                                                                                                                                                   |
| <p><code>agginitval</code> <code>text</code></p><p>The initial value of the transition state. This is a text field containing the initial value in its external string representation. If this field is null, the transition state value starts out null.</p>                                                                                                                                              |
| <p><code>aggminitval</code> <code>text</code></p><p>The initial value of the transition state for moving-aggregate mode. This is a text field containing the initial value in its external string representation. If this field is null, the transition state value starts out null.</p>                                                                                                                   |

<br>

New aggregate functions are registered with the [`CREATE AGGREGATE`](/reference/sql-commands/sql-createaggregate.md) command. See [Section 36.12](/server-programming/extend/xaggr.md) for more information about writing aggregate functions and the meaning of the transition functions, etc.

***

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