ALTER_AGGREGATE(7pg14)
π NAME π
okay so bestie, this is the ALTER_AGGREGATE page from the PostgreSQL 14.24 Documentation β and itβs literally giving βchange the definition of an aggregate functionβ π
β¨. Also known as ALTER AGGREGATE(7), if youβre keeping track.
π¦ 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 πΈ
ALTER AGGREGATE changes the definition of an aggregate function. Thatβs the whole main-character job, no cap π«Ά.
First things first: 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.
Basically, these restrictions make sure that changing the owner canβt do anything you couldnβt already do by dropping and recreating the aggregate function. Plot twist, though: a superuser can alter ownership of any aggregate function anyway π
π PARAMETERS π
nameβ the name (optionally schema-qualified) of an existing aggregate function.argmodeβ the mode of an argument:INorVARIADIC. If omitted, the default isIN.argnameβ the name of an argument. Note thatALTER AGGREGATEdoes not actually pay any attention to argument names, since only the argument data types are needed to determine the aggregate functionβs identity.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. In the syntax you can also useCURRENT_ROLE,CURRENT_USER, orSESSION_USERas the owner value π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.
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. iykyk π§
π₯ 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;
π COMPATIBILITY π
There is no ALTER AGGREGATE statement in the SQL standard. no cap, thatβs the whole vibe check π
π SEE ALSO π
CREATE AGGREGATE(CREATE_AGGREGATE(7))DROP AGGREGATE(DROP_AGGREGATE(7))
bestie, thatβs the whole page. This one comes from PostgreSQL 14.24, dated 2026, and itβs the ALTER AGGREGATE(7) manual page. mwah π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-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