Skip to content

Commit

Permalink
ebnf set role (#17045) (#17191)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot committed Apr 15, 2024
1 parent 9f7ce2b commit 364d2c2
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions sql-statements/sql-statement-set-role.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@ The `SET ROLE` statement is used to enable roles in the current session. After e

## Synopsis

**SetRoleStmt:**

![SetRoleStmt](/media/sqlgram/SetRoleStmt.png)

**SetRoleOpt:**

![SetRoleOpt](/media/sqlgram/SetRoleOpt.png)

**SetDefaultRoleOpt:**

![SetDefaultRoleOpt](/media/sqlgram/SetDefaultRoleOpt.png)
```ebnf+diagram
SetRoleStmt ::=
"SET" "ROLE" ( "DEFAULT" | "ALL" ( "EXCEPT" Rolename ("," Rolename)* )? | "NONE" | Rolename ("," Rolename)* )?
```

## Examples

Create a user `'u1'@'%'` and three roles: `'r1'@'%'`, `'r2'@'%'` and `'r3'@'%'`. Grant these roles to `'u1'@'%'` and set `'r1'@'%'` as the default role of `'u1'@'%'`.

{{< copyable "sql" >}}

```sql
CREATE USER 'u1'@'%';
CREATE ROLE 'r1', 'r2', 'r3';
Expand All @@ -36,8 +27,6 @@ SET DEFAULT ROLE 'r1' TO 'u1'@'%';

Log in as `'u1'@'%'` and execute the following `SET ROLE` statement to enable all roles.

{{< copyable "sql" >}}

```sql
SET ROLE ALL;
SELECT CURRENT_ROLE();
Expand All @@ -54,8 +43,6 @@ SELECT CURRENT_ROLE();

Execute the following `SET ROLE` statement to enable `'r2'` and `'r3'`.

{{< copyable "sql" >}}

```sql
SET ROLE 'r2', 'r3';
SELECT CURRENT_ROLE();
Expand All @@ -72,8 +59,6 @@ SELECT CURRENT_ROLE();

Execute the following `SET ROLE` statement to enable the default role(s).

{{< copyable "sql" >}}

```sql
SET ROLE DEFAULT;
SELECT CURRENT_ROLE();
Expand All @@ -90,8 +75,6 @@ SELECT CURRENT_ROLE();

Execute the following `SET ROLE` statement to cancel all enabled role(s).

{{< copyable "sql" >}}

```sql
SET ROLE NONE;
SELECT CURRENT_ROLE();
Expand Down

0 comments on commit 364d2c2

Please sign in to comment.