ALTER AGGREGATE
ALTER AGGREGATE — change the definition of an aggregate function
Synopsis
ALTER AGGREGATEname
(aggregate_signature
) RENAME TOnew_name
ALTER AGGREGATEname
(aggregate_signature
) OWNER TO {new_owner
| CURRENT_ROLE | CURRENT_USER | SESSION_USER }ALTER AGGREGATEname
(aggregate_signature
) SET SCHEMAnew_schema
whereaggregate_signature
is:* |[argmode
] [argname
]argtype
[ , ... ] |[ [argmode
] [argname
]argtype
[ , ... ] ] ORDER BY [argmode
] [argname
]argtype
[ , ... ]
Description
ALTER AGGREGATE
changes the definition of an aggregate function.
You must own the aggregate function to useALTER AGGREGATE
. To change the schema of an aggregate function, you must also haveCREATE
privilege on the new schema. To alter the owner, you must be able toSET ROLE
to the new owning role, and that role must haveCREATE
privilege on the aggregate function's schema. (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.)
Parameters
name
The name (optionally schema-qualified) of an existing aggregate function.
argmode
The mode of an argument:
IN
orVARIADIC
. If omitted, the default isIN
.argname
The name of an argument. Note that
ALTER AGGREGATE
does 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 BY
between 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 writeORDER BY
between the direct and aggregated argument specifications, in the same style as inCREATE AGGREGATE
. However, it will also work to omitORDER BY
and just run the direct and aggregated argument specifications into a single list. In this abbreviated form, ifVARIADIC "any"
was used in both the direct and aggregated argument lists, writeVARIADIC "any"
only once.
Examples
To rename the aggregate functionmyavg
for typeinteger
tomy_average
:
ALTER AGGREGATE myavg(integer) RENAME TO my_average;
To change the owner of the aggregate functionmyavg
for typeinteger
tojoe
:
ALTER AGGREGATE myavg(integer) OWNER TO joe;
To move the ordered-set aggregatemypercentile
with direct argument of typefloat8
and aggregated argument of typeinteger
into schemamyschema
:
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 noALTER AGGREGATE
statement in the SQL standard.