CURRENT_ROLE
CURRENT_ROLE in SQL is a system function that identifies the current role being used during a SQL session's execution. It is used to obtain the active role's name, which may be necessary for the dynamic management of data access permissions. It returns the name of the current role as a VARCHAR type. The current role is set by the SET ROLE statement.
Example
Output
Explanation
The CURRENT_ROLE
function in PostgreSQL returns the name of the current role for the active session. In the output, myusername
represents the current role name that the function returned.
Example
Output
Explanation
In this example, the CURRENT_USER function in SQL Server is used to return the name of the user who is currently connected to the database. The output will be the ‘username’ of the currently logged-in user.
Note: SQL Server does not have a CURRENT_ROLE function, but CURRENT_USER or USER can be used to determine the user context in which SQL Server code is running.
Example
Output
Explanation
The CURRENT_ROLE
is a built-in function in Oracle that returns the name of the active role for the current user session. In the example, it is used to pull the current active role from the dual
table, a special one-row, one-column table present by default in all Oracle databases. The output CONNECT
is the active role for the current database session.