DROP_AGGREGATE(7pg13)
๐ DROP_AGGREGATE โ bestie's guide to yeeting an aggregate function
okay so this is the DROP AGGREGATE page from the PostgreSQL 13.23 docs, and it's honestly so much simpler than it looks. you're literally just deleting an aggregate function. that's it. that's the whole vibe. but there's lore and we're gonna get into it ๐ซถ
โจ SYNOPSIS โจ
like all the good ones, this starts with a lil signature moment:
DROP AGGREGATE [ IF EXISTS ] name ( aggregate_signature ) [, ...] [ CASCADE | RESTRICT ]
and aggregate_signature is giving... choices. here's what it can be:
* |
[ argmode ] [ argname ] argtype [ , ... ] |
[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
yes bestie, those | bars mean "any of these" โ not all at once. breathe. ๐ฎโ๐จ
๐ธ DESCRIPTION ๐ธ
DROP AGGREGATE removes an existing aggregate function. periodt. ๐๏ธ
โ ๏ธ but here's the gatekeeping: to run this command, the current user has to be the owner of the aggregate function. no owner, no drop. that's the rule, iykyk.
๐ PARAMETERS ๐
the whole menu, no skips, we're eating everything ๐
IF EXISTSโ don't throw an error if the aggregate doesn't exist. instead it just issues a notice and moves on. very "no thoughts head empty" of it, honestly ๐nameโ the name of an existing aggregate function (optionally schema-qualified). yes you can use the full government name with the schema in front ๐argmodeโ the mode of an argument:INorVARIADIC. if you omit it, the default isIN. defaults are so main character energy โจargnameโ the name of an argument. but plot twist:DROP AGGREGATEdoes not actually pay any attention to argument names, because only the argument data types are needed to determine the aggregate function's identity. so you can write it, but it's lowkey just decoration ๐argtypeโ an input data type on which the aggregate function operates. and then there's the special syntax lore:- to reference a zero-argument aggregate function, write
*in place of the list of argument specifications - to reference an ordered-set aggregate function, write
ORDER BYbetween the direct and aggregated argument specifications
- to reference a zero-argument aggregate function, write
CASCADEโ automatically drop objects that depend on the aggregate function (like views using it), and in turn all objects that depend on those objects (see Section 5.14). it's giving domino effect ๐ one drop takes the whole friend groupRESTRICTโ refuse to drop the aggregate function if any objects depend on it. and this one is the default, so it's the safe bestie who checks in before the chaos ๐
๐ฆ NOTES ๐ฆ
there are alternative syntaxes for referencing ordered-set aggregates, and they're described over under ALTER AGGREGATE (ALTER_AGGREGATE(7)). go peek if you're curious, we love a cross-reference moment ๐
๐ง EXAMPLES ๐ง
removing the aggregate function myavg for type integer:
DROP AGGREGATE myavg(integer);
removing the hypothetical-set aggregate function myrank, which takes an arbitrary list of ordering columns and a matching list of direct arguments:
DROP AGGREGATE myrank(VARIADIC "any" ORDER BY VARIADIC "any");
look at that VARIADIC "any" twice with an ORDER BY in the middle. iconic. no notes. ๐ฅ
removing multiple aggregate functions in one command (efficiency queen ๐):
DROP AGGREGATE myavg(integer), myavg(bigint);
โญ COMPATIBILITY โญ
there is no DROP AGGREGATE statement in the SQL standard. so if you were about to cite a standard at someone: don't. this is a PostgreSQL thing, not a committee thing ๐
๐ซ SEE ALSO ๐ซ
ALTER AGGREGATE(ALTER_AGGREGATE(7))CREATE AGGREGATE(CREATE_AGGREGATE(7))
the holy trinity fr fr ๐
okay bestie that's the whole page, go forth and drop responsibly ๐ this lil slice of documentation is straight out of PostgreSQL 13.23, dated 2025, and the footer energy is very much DROP AGGREGATE(7) โ slay, bye! ๐ฆโจ
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms