Updated on 2024-05-07 GMT+08:00

ALTER PACKAGE

Description

ALTER PACKAGE modifies the attributes of a package or recompiles a package.

Precautions

  • Currently, only users with the ALTER PACKAGE OWNER permission can run this command. The system administrator has this permission by default. The restrictions are as follows:
    • The current user must be the owner of the package or the 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 modify the owner of a package, users must have the user group permission, even a system administrator.
  • Only the initial user can change the owner of a package to the initial user.
  • In separation-of-duties mode, the owner of a package of the DEFINER type cannot be changed. In non-separation-of-duties mode., only the system administrator or user with a higher permission can change the owner of a package.
  • The system administrator is not allowed to change the owner of a package of the DEFINER type to the initial user or O&M administrator.

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.

Example

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