Skip to content

Commit e467279

Browse files
committed
Add support for GRANT .. AS role syntax
1 parent 681cfe1 commit e467279

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
@@ -3791,6 +3791,7 @@ pub enum Statement {
37913791
objects: Option<GrantObjects>,
37923792
grantees: Vec<Grantee>,
37933793
with_grant_option: bool,
3794+
as_grantor: Option<Ident>,
37943795
granted_by: Option<Ident>,
37953796
},
37963797
/// ```sql
@@ -5413,6 +5414,7 @@ impl fmt::Display for Statement {
54135414
objects,
54145415
grantees,
54155416
with_grant_option,
5417+
as_grantor,
54165418
granted_by,
54175419
} => {
54185420
write!(f, "GRANT {privileges} ")?;
@@ -5423,6 +5425,9 @@ impl fmt::Display for Statement {
54235425
if *with_grant_option {
54245426
write!(f, " WITH GRANT OPTION")?;
54255427
}
5428+
if let Some(grantor) = as_grantor {
5429+
write!(f, " AS {grantor}")?;
5430+
}
54265431
if let Some(grantor) = granted_by {
54275432
write!(f, " GRANTED BY {grantor}")?;
54285433
}

src/parser/mod.rs

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

13002-
let granted_by = self
13003-
.parse_keywords(&[Keyword::GRANTED, Keyword::BY])
13004-
.then(|| self.parse_identifier().unwrap());
13002+
let as_grantor = if self.peek_keyword(Keyword::AS) {
13003+
self.parse_keywords(&[Keyword::AS])
13004+
.then(|| self.parse_identifier().unwrap())
13005+
} else {
13006+
None
13007+
};
13008+
13009+
let granted_by = if self.peek_keywords(&[Keyword::GRANTED, Keyword::BY]) {
13010+
self.parse_keywords(&[Keyword::GRANTED, Keyword::BY])
13011+
.then(|| self.parse_identifier().unwrap())
13012+
} else {
13013+
None
13014+
};
1300513015

1300613016
Ok(Statement::Grant {
1300713017
privileges,
1300813018
objects,
1300913019
grantees,
1301013020
with_grant_option,
13021+
as_grantor,
1301113022
granted_by,
1301213023
})
1301313024
}

tests/sqlparser_common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9324,6 +9324,7 @@ fn parse_grant() {
93249324
verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");
93259325
verified_stmt("GRANT SELECT ON VIEW view1 TO ROLE role1");
93269326
verified_stmt("GRANT EXEC ON my_sp TO runner");
9327+
verified_stmt("GRANT UPDATE ON my_table TO updater_role AS dbo");
93279328

93289329
all_dialects_where(|d| d.identifier_quote_style("none") == Some('['))
93299330
.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
@@ -3283,6 +3283,7 @@ fn parse_grant() {
32833283
objects,
32843284
grantees,
32853285
with_grant_option,
3286+
as_grantor: _,
32863287
granted_by,
32873288
} = stmt
32883289
{

0 commit comments

Comments
 (0)