Skip to content

Commit 243b05b

Browse files
committed
Support SET ROLE
1 parent 9c21155 commit 243b05b

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/cst/Role.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { NullLiteral, NumberLiteral, StringLiteral } from "./Literal";
55

66
export type AllRoleNodes = AllRoleStatements | RoleOption | InDatabaseClause;
77

8-
export type AllRoleStatements = CreateRoleStmt | AlterRoleStmt | DropRoleStmt;
8+
export type AllRoleStatements =
9+
| CreateRoleStmt
10+
| AlterRoleStmt
11+
| DropRoleStmt
12+
| SetRoleStmt;
913

1014
export type RoleSpecification = Identifier | FuncCall;
1115

@@ -113,3 +117,12 @@ export interface DropRoleStmt extends BaseNode {
113117
ifExistsKw?: [Keyword<"IF">, Keyword<"EXISTS">];
114118
names: ListExpr<RoleSpecification>;
115119
}
120+
121+
// SET ROLE
122+
export interface SetRoleStmt extends BaseNode {
123+
type: "set_role_stmt";
124+
setKw: Keyword<"SET">;
125+
scopeKw?: Keyword<"SESSION" | "LOCAL">;
126+
roleKw: Keyword<"ROLE">;
127+
name: Identifier | StringLiteral | Keyword<"NONE">;
128+
}

src/parser.pegjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ ddl_statement_postgres
161161
/ create_role_stmt
162162
/ alter_role_stmt
163163
/ drop_role_stmt
164+
/ set_role_stmt
164165

165166
dml_statement
166167
= compound_select_stmt
@@ -4556,6 +4557,17 @@ drop_role_stmt
45564557
});
45574558
}
45584559

4560+
set_role_stmt
4561+
= kw:(SET __) scopeKw:((SESSION / LOCAL) __)? roleKw:(ROLE __) name:(NONE / ident / string_literal) {
4562+
return loc({
4563+
type: "set_role_stmt",
4564+
setKw: read(kw),
4565+
scopeKw: read(scopeKw),
4566+
roleKw: read(roleKw),
4567+
name,
4568+
});
4569+
}
4570+
45594571
/**
45604572
* ------------------------------------------------------------------------------------ *
45614573
* *

src/showNode/role.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ export const roleMap: FullTransformMap<string, AllRoleNodes> = {
2525
// DROP ROLE
2626
drop_role_stmt: (node) =>
2727
show([node.dropRoleKw, node.ifExistsKw, node.names]),
28+
29+
// SET ROLE
30+
set_role_stmt: (node) =>
31+
show([node.setKw, node.scopeKw, node.roleKw, node.name]),
2832
};

test/ddl/role.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ describe("role", () => {
176176
testWc("DROP GROUP IF EXISTS mary, john");
177177
});
178178
});
179+
180+
describe("SET ROLE", () => {
181+
it("supports SET ROLE name", () => {
182+
testWc("SET ROLE paul");
183+
testWc("SET SESSION ROLE paul");
184+
testWc("SET LOCAL ROLE paul");
185+
});
186+
187+
it("supports SET ROLE 'name'", () => {
188+
testWc("SET ROLE 'paul'");
189+
testWc("SET SESSION ROLE 'paul'");
190+
testWc("SET LOCAL ROLE 'paul'");
191+
});
192+
193+
it("supports SET ROLE NONE", () => {
194+
testWc("SET ROLE NONE");
195+
testWc("SET SESSION ROLE NONE");
196+
testWc("SET LOCAL ROLE NONE");
197+
});
198+
});
179199
});
180200

181201
notDialect("postgresql", () => {

0 commit comments

Comments
 (0)