Skip to main content

SET ROLE

Description

This statement is used to activate roles granted to the current login user in the current session.

info

Roles activated by the SET ROLE statement only affect the current session and do not affect subsequent sessions.

Syntax

SET ROLE {
DEFAULT
| NONE
| ALL
| ALL EXCEPT role_name [, role_name ...]
| role_name [, role_name ...]
};

Parameters

ParameterDescription
DEFAULTSpecifies to keep the default role setting. The system will activate roles based on the value of the variable activate_all_roles_on_login and the default activated roles set by the SET DEFAULT ROLE statement or the ALTER USER statement:
  • If the value of the variable activate_all_roles_on_login is on, all roles granted to the user are activated in the session.
  • If the value of the variable activate_all_roles_on_login is off, the default activated roles specified by the SET DEFAULT ROLE statement or the ALTER USER statement are activated in the session.
NONESpecifies to disable all roles granted to the user.
ALLSpecifies to activate all roles granted to the user.
ALL EXCEPTSpecifies to not activate any roles granted to the user.
role_nameSpecifies the name of the role. When activating multiple roles, separate the role names with commas (,).

Examples

  • Specify to activate all roles granted to the user except for the role001 role in the current session.

    SET ROLE ALL EXCEPT role001;
  • Specify to activate the role001 and role002 roles of the user in the current session.

    SET ROLE role001, role002;

References