Syntax
CREATE AGGREGATE features:
- Schema-qualified names: Aggregates can be defined in specific schemas, and overloaded aggregates (same name, different argument types) are tracked independently.
- Transition and final functions:
SFUNC/STYPE(required),FINALFUNC,FINALFUNC_EXTRA, andFINALFUNC_MODIFY. - Initial condition:
INITCOND. - Parallel aggregation:
COMBINEFUNC,SERIALFUNC,DESERIALFUNC, andPARALLEL = SAFE | RESTRICTED. - Moving-aggregate support (for window frames):
MSFUNC,MINVFUNC,MSTYPE,MSSPACE,MFINALFUNC,MFINALFUNC_EXTRA,MFINALFUNC_MODIFY, andMINITCOND. - State space hints:
SSPACEandMSSPACE. - Sort operator:
SORTOP(for normal aggregates, e.g.MIN/MAX-style aggregates). - Ordered-set and hypothetical-set aggregates: the
... ORDER BY ...signature is preserved, andHYPOTHETICALis emitted for hypothetical-set aggregates. - Comments:
COMMENT ON AGGREGATE.
SFUNC, FINALFUNC, COMBINEFUNC, …) are schema-qualified only when they live in a different schema than the aggregate itself.
Canonical Format
When generating migration SQL, pgschema produces aggregates in the following canonical format:SFUNCandSTYPEare always emitted; every other option is emitted only when it differs from its PostgreSQL default, in the same order pg_dump uses.- A zero-argument aggregate renders its signature as
(*). - PostgreSQL has no
ALTER AGGREGATEfor the defining properties, so any change to an aggregate’s definition is expressed asDROP AGGREGATE+CREATE AGGREGATE. A comment-only change emits justCOMMENT ON AGGREGATE. - For DROP operations:
DROP AGGREGATE IF EXISTS aggregate_name(argument_types);— the signature contains only the argument types (the identity signature). - Aggregates are created after their support functions and all tables, and before views that reference them; they are dropped before their support functions.

