ALTER_AGGREGATE(7pg13)
β¨ ALTER_AGGREGATE β¨
okay so bestie, this is the ALTER_AGGREGATE page from the PostgreSQL 13.23 documentation, and it's literally the glow-up station for your aggregate functions π
like we're not creating anything new here, we're just doing a lil makeover on one that already exists.
πΈ SYNOPSIS πΈ
ALTER AGGREGATE name ( aggregate_signature ) RENAME TO new_name
ALTER AGGREGATE name ( aggregate_signature )
OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
ALTER AGGREGATE name ( aggregate_signature ) SET SCHEMA new_schema
and aggregate_signature is, and I cannot stress this enough, one of these three:
* |
[ argmode ] [ argname ] argtype [ , ... ] |
[ [ argmode ] [ argname ] argtype [ , ... ] ] ORDER BY [ argmode ] [ argname ] argtype [ , ... ]
no cap, that's the whole menu π«Ά
π DESCRIPTION π
ALTER AGGREGATE changes the definition of an aggregate function. that's the assignment. that's the vibe. β¨
but bestie, there are rules, and the rules are not optional:
- you must own the aggregate function to use
ALTER AGGREGATE, periodt. - if you're changing the schema of an aggregate function, you also need
CREATEprivilege on the new schema. - if you're changing the owner, you must also be a direct or indirect member of the new owning role, and that role must have
CREATEprivilege on the aggregate function's schema. (these restrictions are giving "enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the aggregate function" energy. however, a superuser can alter ownership of any aggregate function anyway, so π«Ά main character exemption.)
π PARAMETERS π
nameβ the name (optionally schema-qualified) of an existing aggregate function. yes it has to exist already, we're altering, not manifesting π¦argmodeβ the mode of an argument:INorVARIADIC. if you omit it, the default isIN.argnameβ the name of an argument. okay so funny thing:ALTER AGGREGATEdoes not actually pay any attention to argument names, because only the argument data types are needed to determine the aggregate function's identity. it's lowkey ignoring them and honestly? relatable π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.new_ownerβ the new owner of the aggregate function.new_schemaβ the new schema for the aggregate function.
π¦ 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 (CREATE_AGGREGATE(7)). that's the iconic way, that's the way it's giving π
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. one time. singular. not twice. β¨
π 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;
both slay, pick your fave π
π COMPATIBILITY π
there is no ALTER AGGREGATE statement in the SQL standard. we're built different, we're off-book, we're that girl π₯
π SEE ALSO π
CREATE AGGREGATE(CREATE_AGGREGATE(7))DROP AGGREGATE(DROP_AGGREGATE(7))
πΈ and that's the page!! this was PostgreSQL 13.23, dated 2025, signing off with so much love, go forth and rename your aggregates responsibly bestie ππ
π¦ 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