In MariaDB, CURRENT_ROLE()
is a built-in function that returns the current role name. The current role determines your access privileges.
The output of SELECT CURRENT_ROLE
is equivalent to the contents of the information_schema.ENABLED_ROLES
table.
Syntax
The function can be called with or without the parentheses:
CURRENT_ROLE
CURRENT_ROLE()
No arguments are required or accepted.
Example
Here’s an example to demonstrate:
SELECT CURRENT_ROLE();
Result:
+----------------+ | CURRENT_ROLE() | +----------------+ | NULL | +----------------+
In my case, there’s no current role and so NULL
is returned.
Let’s add a current role:
SET ROLE analyst;
And run it again:
SELECT CURRENT_ROLE();
Result:
+----------------+ | CURRENT_ROLE() | +----------------+ | analyst | +----------------+
Now, the role we added is the current role.
This example assumes that the role has previously been created.
Without Parentheses
As mentioned, the CURRENT_ROLE()
function can be called with or without parentheses.
Here’s an example without parentheses:
SELECT CURRENT_ROLE;
Result:
+--------------+ | CURRENT_ROLE | +--------------+ | analyst | +--------------+
No Arguments are Accepted
Passing any arguments to CURRENT_ROLE()
results in an error:
SELECT CURRENT_ROLE(1);
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1)' at line 1