DROP_AGGREGATE(7pg16)
π DROP_AGGREGATE(7) β PostgreSQL 16.15 Documentation π
Hii bestie, welcome to the DROP AGGREGATE(7) page from the PostgreSQL 16.15 docs π This is the one where we remove an aggregate function, and yes, the vibes are immaculate cleanup energy β¨
πΈ NAME πΈ
DROP_AGGREGATE β remove an aggregate function π«Ά
π SYNOPSIS π
DROP AGGREGATE [ IF EXISTS ] name ( aggregate_signature ) [, ...] [ CASCADE | RESTRICT ]
where aggregate_signature is:
* |
[ argmode ] [ argname ] argtype [ , ... ] |
[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
π¦ DESCRIPTION π¦
Okay so DROP AGGREGATE removes an existing aggregate function. To execute this command, the current user must be the owner of the aggregate function. That's the rule, bestie β no cap π
β¨ PARAMETERS β¨
IF EXISTSβ do not throw an error if the aggregate does not exist. A notice is issued in this case. Very βno drama, just a little heads-upβ of it πnameβ the name (optionally schema-qualified) of an existing aggregate function. Slay, but make sure it's the right one πargmodeβ the mode of an argument:INorVARIADIC. If omitted, the default isIN. Lowkey important, highkey iconic β¨argnameβ the name of an argument. Note thatDROP AGGREGATEdoes not actually pay any attention to argument names, since only the argument data types are needed to determine the aggregate function's identity. So yeah, the names are giving decoration, not main character energy πargtypeβ an input data type on which the aggregate function operates. To reference a zero-argument aggregate function, write*in place of the list of argument specifications. To reference an ordered-set aggregate function, writeORDER BYbetween the direct and aggregated argument specifications. This is the part where the syntax gets a little fancy, but you got this πCASCADEβ automatically drop objects that depend on the aggregate function (such as views using it), and in turn all objects that depend on those objects (see Section 5.14). It's giving domino effect, so use it with intention πRESTRICTβ refuse to drop the aggregate function if any objects depend on it. This is the default. The safe little guardrail keeping your schema from chaos π«Ά
π§ NOTES π§
Alternative syntaxes for referencing ordered-set aggregates are described under ALTER AGGREGATE (ALTER_AGGREGATE(7)). Go check that page if you want the extra lore πβ¨
π EXAMPLES π
To remove the aggregate function myavg for type integer:
DROP AGGREGATE myavg(integer);
To remove 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");
To remove multiple aggregate functions in one command:
DROP AGGREGATE myavg(integer), myavg(bigint);
β COMPATIBILITY β
There is no DROP AGGREGATE statement in the SQL standard. So this one is PostgreSQL-specific, bestie β no standard-SQL twin to match with π
π SEE ALSO π
ALTER AGGREGATE (ALTER_AGGREGATE(7)), CREATE AGGREGATE (CREATE_AGGREGATE(7)) π
xoxo, from the PostgreSQL 16.15 docs, dated 2026, page DROP AGGREGATE(7) β bye bestie, go drop those aggregates responsibly πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-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