Skip to content

Commit 43a84f7

Browse files
committed
Add support for GRANT .. AS role syntax
1 parent 9b0e193 commit 43a84f7

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/ast/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,6 +3903,7 @@ pub enum Statement {
39033903
objects: Option<GrantObjects>,
39043904
grantees: Vec<Grantee>,
39053905
with_grant_option: bool,
3906+
as_grantor: Option<Ident>,
39063907
granted_by: Option<Ident>,
39073908
},
39083909
/// ```sql
@@ -5584,6 +5585,7 @@ impl fmt::Display for Statement {
55845585
objects,
55855586
grantees,
55865587
with_grant_option,
5588+
as_grantor,
55875589
granted_by,
55885590
} => {
55895591
write!(f, "GRANT {privileges} ")?;
@@ -5594,6 +5596,9 @@ impl fmt::Display for Statement {
55945596
if *with_grant_option {
55955597
write!(f, " WITH GRANT OPTION")?;
55965598
}
5599+
if let Some(grantor) = as_grantor {
5600+
write!(f, " AS {grantor}")?;
5601+
}
55975602
if let Some(grantor) = granted_by {
55985603
write!(f, " GRANTED BY {grantor}")?;
55995604
}

src/parser/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13393,15 +13393,26 @@ impl<'a> Parser<'a> {
1339313393
let with_grant_option =
1339413394
self.parse_keywords(&[Keyword::WITH, Keyword::GRANT, Keyword::OPTION]);
1339513395

13396-
let granted_by = self
13397-
.parse_keywords(&[Keyword::GRANTED, Keyword::BY])
13398-
.then(|| self.parse_identifier().unwrap());
13396+
let as_grantor = if self.peek_keyword(Keyword::AS) {
13397+
self.parse_keywords(&[Keyword::AS])
13398+
.then(|| self.parse_identifier().unwrap())
13399+
} else {
13400+
None
13401+
};
13402+
13403+
let granted_by = if self.peek_keywords(&[Keyword::GRANTED, Keyword::BY]) {
13404+
self.parse_keywords(&[Keyword::GRANTED, Keyword::BY])
13405+
.then(|| self.parse_identifier().unwrap())
13406+
} else {
13407+
None
13408+
};
1339913409

1340013410
Ok(Statement::Grant {
1340113411
privileges,
1340213412
objects,
1340313413
grantees,
1340413414
with_grant_option,
13415+
as_grantor,
1340513416
granted_by,
1340613417
})
1340713418
}

tests/sqlparser_common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9332,6 +9332,7 @@ fn parse_grant() {
93329332
verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");
93339333
verified_stmt("GRANT SELECT ON VIEW view1 TO ROLE role1");
93349334
verified_stmt("GRANT EXEC ON my_sp TO runner");
9335+
verified_stmt("GRANT UPDATE ON my_table TO updater_role AS dbo");
93359336

93369337
all_dialects_where(|d| d.identifier_quote_style("none") == Some('['))
93379338
.verified_stmt("GRANT SELECT ON [my_table] TO [public]");

tests/sqlparser_mysql.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,6 +3538,7 @@ fn parse_grant() {
35383538
objects,
35393539
grantees,
35403540
with_grant_option,
3541+
as_grantor: _,
35413542
granted_by,
35423543
} = stmt
35433544
{

0 commit comments

Comments
 (0)