Updated on 2025-10-23 GMT+08:00

ALTER EXTENSION

Description

Modifies plug-in extensions. Currently, this syntax is not supported. This feature is for internal use only. You are advised not to use it.

Precautions

ALTER EXTENSION modifies the definition of an installed extension. To use this API, set support_extended_features to true. Methods are as follows:

  • UPDATE

    The extension is updated to the latest version. The extension must be applicable to an update script (or a series of scripts) so that the current installation version can be modified to a required version.

  • SET SCHEMA

    The extended object is moved to another schema. This extension must be relocatable to make the command successful.

  • ADD member_object

    An existing object is added to the extension. This is mainly useful for extension update scripts. This object is then treated as a member of the extension. Obviously, the object can only be canceled by canceling the extension.

  • DROP member_object

    A member object is removed from the extension. This method is useful in extension update scripts. The object is not canceled, but is simply separated from the extension.

    You must have an extension before using ALTER EXTENSION. You must have the permission on adding or deleting an object before using the ADD or DROP statement.

Syntax

  • Modify the version of an extension.
ALTER EXTENSION name UPDATE [ TO new_version ];
  • Modify the schema of the extension.
ALTER EXTENSION name SET SCHEMA new_schema;
  • Add or delete member objects of the extension.
ALTER EXTENSION name { ADD | DROP } member_object;

The member object member_object is written as follows:

{ COLLATION object_name |
  FOREIGN DATA WRAPPER object_name |  
  SCHEMA object_name |
  SEQUENCE object_name |
  SERVER object_name |
  TABLE object_name |
  VIEW object_name}

Parameters

  • name

    Name of an installed extension.

  • new_version

    Latest version of the extension, which can be overridden by identifiers and string literals. If the target version of the extension is not specified, ALTER EXTENSION UPDATE updates to the default version shown in the extension's control file.

  • new_schema

    New schema of the extension.

  • object_name

    agg_name

    function_name

    operator_name

    Names of objects that are added or removed from the extension, including names of tables, aggregations, domains, external linked lists, functions, operators, operator classes, operator families, sequences, text search objects, types, and views that can be schema-qualified.

  • agg_type

    Input data type of the aggregate function. To reference a zero-parameter aggregate function, use * to replace the input data type list.

  • source_type

    Name of the source data type to be forcibly converted.

  • target_type

    Name of the target data type to be forcibly converted.

  • argmode

    Model of the function parameter. The value can be IN, OUT, INOUT, or VARIADIC. The default value is IN. ALTER EXTENSION does not correlate to OUT, because you only need to enter parameters to confirm the consistency of functions. Therefore, IN, INOUT, and VARIADIC are enough.

  • argname

    Specifies the parameter name of the function. ALTER EXTENSION does not correlate to the parameter name. Only the parameter data type is required to confirm the consistency of the function.

  • argtype

    Data type (optionally schema-qualified) of a function parameter.

  • left_type

    right_type

    Data type (optionally schema-qualified) of an operator parameter. NONE is written for a missing parameter of a prefix or suffix operator.

Examples

Update the PL/pgSQL extension to version 2.0.

m_db=# ALTER EXTENSION plpgsql UPDATE TO '2.0';

Update the PL/pgSQL extension mode to utils.

m_db=# ALTER EXTENSION plpgsql SET SCHEMA utils;