postgresql_16:7.1.174.1 Description
PostgreSQL 16 > Reference > SQL Commands > SET ROLE > Description
This command sets the current user identifier of the current SQL session to be *role_name*. The role name can be written as either an identifier or a string literal. After SET ROLE, permissions checking for SQL commands is carried out as though the named role were the one that had logged in originally.
The current session user must have the SET option for the specified *role_name*, either directly or indirectly via a chain of memberships with the SET option. (If the session user is a superuser, any role can be selected.)
The SESSION and LOCAL modifiers act the same as for the regular SET (see postgresql_16:7.1.172) command.
SET ROLE NONE sets the current user identifier to the current session user identifier, as returned by session_user. RESET ROLE sets the current user identifier to the connection-time setting specified by the command-line options (see libpq-connect-options), ALTER ROLE (see postgresql_16:7.1.24), or ALTER DATABASE (see postgresql_16:7.1.5), if any such settings exist. Otherwise, RESET ROLE sets the current user identifier to the current session user identifier. These forms can be executed by any user.