<<<<<<< HEAD current_role | H2 | SQLDoc
Skip to main content

current_role

1. CURRENT_ROLE Function

======= current_role | H2 Function | SQLDoc

current_role

1. CURRENT_ROLE Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The CURRENT_ROLE function in H2 database is used to retrieve the current role of the current user.

2. Syntax

The syntax for the CURRENT_ROLE function in H2 database is as follows:

CURRENT_ROLE()

Arguments

  • This function does not take any arguments.

Return

  • The CURRENT_ROLE function returns the name of the current role as a string.

3. Notes

  • The CURRENT_ROLE function in H2 database returns the name of the current role associated with the current user.
  • If the user does not have any role assigned, the function will return null.
  • This function is only applicable if role-based access control (RBAC) is enabled in the H2 database.

4. Examples

Here are a few examples demonstrating the usage of the CURRENT_ROLE function in H2 database:

Example 1 - Retrieving the current role:

SET ROLE 'admin';

SELECT CURRENT_ROLE() AS current_role;

Output:

current_role
------------
admin

Example 2 - Checking the current role within a query:

SET ROLE 'user';

SELECT id, name
FROM users
WHERE role = CURRENT_ROLE();

Output:

id | name
---+--------
1 | John
3 | Alice

There are no related functions specific to the CURRENT_ROLE function in H2 database.