{"id":18052,"date":"2021-07-01T09:33:22","date_gmt":"2021-06-30T23:33:22","guid":{"rendered":"https:\/\/database.guide\/?p=18052"},"modified":"2021-07-01T09:33:22","modified_gmt":"2021-06-30T23:33:22","slug":"mariadb-current_role-explained","status":"publish","type":"post","link":"https:\/\/database.guide\/mariadb-current_role-explained\/","title":{"rendered":"MariaDB CURRENT_ROLE() Explained"},"content":{"rendered":"\n<p>In MariaDB, <code>CURRENT_ROLE()<\/code> is a built-in function that returns the current role name. The current role determines your access privileges.<\/p>\n\n\n\n<p>The output of <code>SELECT CURRENT_ROLE<\/code> is equivalent to the contents of the <code>information_schema.ENABLED_ROLES<\/code> table.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p>The function can be called with or without the parentheses:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CURRENT_ROLE\nCURRENT_ROLE()<\/code><\/pre>\n\n\n\n<p>No arguments are required or accepted.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p>Here&#8217;s an example to demonstrate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT CURRENT_ROLE();<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+----------------+\n| CURRENT_ROLE() |\n+----------------+\n| NULL           |\n+----------------+<\/pre>\n\n\n\n<p>In my case, there&#8217;s no current role and so <code>NULL<\/code> is returned.<\/p>\n\n\n\n<p>Let&#8217;s add a current role:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SET ROLE analyst;<\/code><\/pre>\n\n\n\n<p>And run it again:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT CURRENT_ROLE();<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+----------------+\n| CURRENT_ROLE() |\n+----------------+\n| analyst        |\n+----------------+<\/pre>\n\n\n\n<p>Now, the role we added is the current role. <\/p>\n\n\n\n<p>This example assumes that the role has previously been created.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Without Parentheses<\/h2>\n\n\n\n<p>As mentioned, the <code>CURRENT_ROLE()<\/code> function can be called with or without parentheses. <\/p>\n\n\n\n<p>Here&#8217;s an example without parentheses:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT CURRENT_ROLE;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+--------------+\n| CURRENT_ROLE |\n+--------------+\n| analyst      |\n+--------------+<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">No Arguments are Accepted<\/h2>\n\n\n\n<p>Passing any arguments to <code>CURRENT_ROLE()<\/code> results in an error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT CURRENT_ROLE(1);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">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<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[93,20],"class_list":["post-18052","post","type-post","status-publish","format-standard","hentry","category-mariadb","tag-functions","tag-what-is"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=18052"}],"version-history":[{"count":5,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18052\/revisions"}],"predecessor-version":[{"id":18058,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18052\/revisions\/18058"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=18052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=18052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=18052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}