DROP_AGGREGATE(7pg13)

๐Ÿ“ฆ version 13.23, in opensuse-leap 16.0

๐Ÿ’… 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: IN or VARIADIC. if you omit it, the default is IN. defaults are so main character energy โœจ
  • argname โ€” the name of an argument. but plot twist: DROP AGGREGATE does 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 BY between the direct and aggregated argument specifications
  • 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 group
  • RESTRICT โ€” 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 ๐Ÿ’ซ

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