ALTER_AGGREGATE(7pg15)
π ALTER_AGGREGATE π
okay bestie, so this is the PostgreSQL 15.19 docs page for ALTER_AGGREGATE(7) β it's the glow-up command for aggregate functions, and honestly it's giving "small but mighty." Let's get into it π«Ά
β¨ NAME β¨
ALTER_AGGREGATE β change the definition of an aggregate function. that's it, that's the whole vibe π
πΈ SYNOPSIS πΈ
ALTER AGGREGATE name ( aggregate_signature ) RENAME TO new_name
ALTER AGGREGATE name ( aggregate_signature )
OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER AGGREGATE name ( aggregate_signature ) SET SCHEMA new_schema
where aggregate_signature is:
* |
[ argmode ] [ argname ] argtype [ , ... ] |
[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
like, yes, that signature grammar is a whole mood board, but it's literally just "how do I point at exactly one aggregate function." π¦
π DESCRIPTION π
ALTER AGGREGATE changes the definition of an aggregate function. no cap, that's the entire job description β¨
now the rules, and yes there are rules, because PostgreSQL is a main character who wants you to earn it:
You must own the aggregate function to use ALTER AGGREGATE. To change the schema of an aggregate function, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the aggregate function's schema. π
(and the reason for all that: these restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the aggregate function. however β a superuser can alter ownership of any aggregate function anyway. iconic loophole, lowkey π )
π¦ PARAMETERS π¦
nameβ the name (optionally schema-qualified) of an existing aggregate function. i.e. tell me which one, bestie.argmodeβ the mode of an argument:INorVARIADIC. If omitted, the default isIN. πargnameβ the name of an argument. and here's the tea:ALTER 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 yes, you can write them, and the server will simply not care. π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. βnew_nameβ the new name of the aggregate function. the rebrand β¨new_ownerβ the new owner of the aggregate function. handing over the crown πnew_schemaβ the new schema for the aggregate function. moving day π
π NOTES π
The recommended syntax for referencing an ordered-set aggregate is to write ORDER BY between the direct and aggregated argument specifications, in the same style as in CREATE AGGREGATE. π―
however!! it will also work to omit ORDER BY and just run the direct and aggregated argument specifications into a single list. In this abbreviated form, if VARIADIC "any" was used in both the direct and aggregated argument lists, write VARIADIC "any" only once. (yes, only once β the server is not about to let you say it twice, fr fr) π
π₯ EXAMPLES π₯
To rename the aggregate function myavg for type integer to my_average:
ALTER AGGREGATE myavg(integer) RENAME TO my_average;
To change the owner of the aggregate function myavg for type integer to joe:
ALTER AGGREGATE myavg(integer) OWNER TO joe;
To move the ordered-set aggregate mypercentile with direct argument of type float8 and aggregated argument of type integer into schema myschema:
ALTER AGGREGATE mypercentile(float8 ORDER BY integer) SET SCHEMA myschema;
This will work too:
ALTER AGGREGATE mypercentile(float8, integer) SET SCHEMA myschema;
see? two ways, same slay. you pick the one that vibes with you π§
π COMPATIBILITY π
There is no ALTER AGGREGATE statement in the SQL standard. so it's a PostgreSQL original, iykyk π
π SEE ALSO π
CREATE AGGREGATE(CREATE_AGGREGATE(7))DROP AGGREGATE(DROP_AGGREGATE(7))
ok warning-ish aside from your girl: the privilege rules above are real, so ifALTER AGGREGATEis acting like it doesn't know you, it's a permissions thing, not a you thing. check ownership andCREATEprivileges first π«Ά
and that's the page!! brought to you by PostgreSQL 15.19, dated 2026, filed under ALTER AGGREGATE(7) β go forth and rename ur aggregates, bestie. periodt. ππβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-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