Use the EXECUTE AS command to set the CURRENT USER of the session.
EXECUTE AS <target-user-name>
| Input | Description |
|---|---|
| <target-user-name> | The name of an existing user. |
| Output | Description |
|---|---|
| EXECUTE AS | The message that the system returns if the command is successful. |
| ERROR: permission denied. | You must have EXECUTE AS privilege on the target user. |
This statement allows a suitably privileged user to set the CURRENT USER of their session to a different user. On successful completion of this statement, the CURRENT USER is the target user specified in the syntax. Security checks are based on the security profile the CURRENT USER.
The current_user function returns the target user. The session_user function returns the original session user.
BEGIN;
EXECUTE AS dd;
ROLLBACK;
SELECT current_user;
CURRENT_USER
--------------
DD
(1 row)
EXECUTE AS BOB;