Updated on 2025-03-13 GMT+08:00

ALTER PACKAGE

Description

Modifies the attributes of a package or recompiles a package.

Precautions

  • Currently, only users with the ALTER PACKAGE OWNER permission can run this command. By default, system administrators have the permission. The restrictions are as follows:
    • The current user must be the owner of the package or a system administrator and a member of the new owner role.
  • The plpgsql_dependency parameter must be set for package recompilation.
  • Only the initial user can modify the owner of the package that has the definer permission.
  • When separation of duties is enabled, to change the owner of a package, users must have the user group permission, even a system administrator. The owner of a package of the DEFINER type cannot be changed.
  • Only the initial user can change the owner of a package to the initial user.
  • When separation of duties is disabled, only a system administrator or a higher-level user can change the package owner, but the owner cannot be changed to an O&M administrator.
  • System administrators are not allowed to change the owner of a package of the DEFINER type to the initial user or OPRADMIN.

Syntax

  • Change the owner of a package.
    ALTER PACKAGE package_name OWNER TO new_owner;
  • Recompile the package.
    ALTER PACKAGE package_name COMPILE [PACKAGE | BODY | SPECIFICATION];

Parameters

  • package_name

    Specifies the name of the package to be modified.

    Value range: an existing package name. Only one package can be modified at a time.

  • new_owner

    Specifies the new owner of a package. To change the owner of a package, the new owner must have the CREATE permission on the schema to which the package belongs.

    Value range: an existing user role

Examples

For details, see CREATE PACKAGE.

Recompilation examples:
-- Enable the dependency function.
gaussdb=# set behavior_compat_options ='plpgsql_dependency';

-- Create a function.
gaussdb=# create or replace package test_pkg as
    pkg_var int := 1;
    procedure test_pkg_proc(var int);
end test_pkg;
/

gaussdb=# create or replace package body test_pkg as
    procedure test_pkg_proc(var int)
is
begin
    pkg_var := 1;
end;
end test_pkg;
/

-- Recompile the package.
gaussdb=# alter package test_pkg compile;

Helpful Links

CREATE PACKAGE and DROP PACKAGE