ALTER_AGGREGATE(7)
โจ ALTER AGGREGATE(7) โจ
okay so bestie, we're in the PostgreSQL 18.6 Documentation and today's main character is ALTER_AGGREGATE โ the glow-up page for your aggregate functions ๐
๐ธ NAME ๐ธ
ALTER_AGGREGATE โ change the definition of an aggregate function
๐ 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 [ , ... ]
๐ฆ DESCRIPTION ๐ฆ
So like, ALTER AGGREGATE changes the definition of an aggregate function. That's the whole vibe. Rename it, re-own it, move it to a new schema โ she contains multitudes ๐
Now the rules, and listen, because these matter:
- You must own the aggregate function to use
ALTER AGGREGATE. no cap. - Wanna change the schema of an aggregate function? You also need
CREATEprivilege on the new schema. both things, bestie. - Wanna alter the owner? You have to be able to
SET ROLEto the new owning role, and that role must haveCREATEprivilege on the aggregate function's schema. yes, both.
Why all the gatekeeping? These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the aggregate function. It's giving "no sneaky shortcuts" ๐
But also โ plot twist โ a superuser can alter ownership of any aggregate function anyway. main character energy, honestly ๐
โจ PARAMETERS โจ
nameโ the name (optionally schema-qualified) of an existing aggregate function. yeah, she has to already exist, we're not manifesting here ๐ซargmodeโ the mode of an argument:INorVARIADIC. If you justโฆ don't say anything? The default isIN. she's chill like that.argnameโ the name of an argument. lowkey important 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 like, don't stress about it ๐ซถargtypeโ an input data type on which the aggregate function operates. And here's the spicy part:- 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. iconic separator behavior ๐
- To reference a zero-argument aggregate function, write
new_nameโ the new name of the aggregate function. rebranding era ๐new_ownerโ the new owner of the aggregate function. passing the crown ๐new_schemaโ the new schema for the aggregate function. she's moving out ๐งณ
๐ NOTES ๐
The recommended syntax for referencing an ordered-set aggregate is to write ORDER BY between the direct and aggregated argument specifications โ same style as in CREATE AGGREGATE. consistency queen โจ
However! It will also work to omit ORDER BY and just run the direct and aggregated argument specifications into a single list. the abbreviated form, if you will.
โ ๏ธ heads up for the abbreviated form: ifVARIADIC "any"was used in both the direct and aggregated argument lists, writeVARIADIC "any"only once. not twice. once. fr fr.
๐ฅ EXAMPLES ๐ฅ
Rename the aggregate function myavg for type integer to my_average:
ALTER AGGREGATE myavg(integer) RENAME TO my_average;
Change the owner of the aggregate function myavg for type integer to joe:
ALTER AGGREGATE myavg(integer) OWNER TO joe;
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;
And bestie, this will work too:
ALTER AGGREGATE mypercentile(float8, integer) SET SCHEMA myschema;
see? both slay ๐
๐ COMPATIBILITY ๐
There is no ALTER AGGREGATE statement in the SQL standard. we're built different, it's fine ๐ซถ
๐ SEE ALSO ๐
CREATE AGGREGATE(CREATE_AGGREGATE(7))DROP AGGREGATE(DROP_AGGREGATE(7))
and that's the whole page, bestie ๐ go forth and alter those aggregates responsibly.
signing off from <strong>PostgreSQL 18.6</strong>, dated <strong>2026</strong>, in the one and only <strong>ALTER AGGREGATE(7)</strong> โ mwah ๐โจ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms