> 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/15/internals/system-catalogs/pg_aggregate.md).

# 53.2. pg\_aggregate

## 53.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`](/15/internals/system-catalogs/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 53.2. `pg_aggregate` Columns**

| <p>Column Type</p><p>Description</p>                                                                                                                                                                                                                                                                                                                                                                       |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>aggfnoid</code> <code>regproc</code> (references <a href="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_proc.md"><code>pg\_proc</code></a>.<code>oid</code>)</p><p>Transition function</p>                                                                                                                                                                                                                   |
| <p><code>aggfinalfn</code> <code>regproc</code> (references <a href="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_proc.md"><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="/15/internals/system-catalogs/pg_operator.md"><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="/15/internals/system-catalogs/pg_type.md"><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="/15/internals/system-catalogs/pg_type.md"><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>                                                                                                                   |

New aggregate functions are registered with the [`CREATE AGGREGATE`](/15/reference/sql-commands/create-aggregate.md) command. See [Section 38.12](/15/server-programming/extending-sql/user-defined-aggregates.md) for more information about writing aggregate functions and the meaning of the transition functions, etc.

***

原文：[PostgreSQL 15.19 Documentation](/15/internals/system-catalogs/pg_aggregate.md)（英文原文，待翻譯）


---

# 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/15/internals/system-catalogs/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.
