Skip to content

Add Snowflake COPY/REVOKE CURRENT GRANTS option #1926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3996,6 +3996,7 @@ pub enum Statement {
with_grant_option: bool,
as_grantor: Option<Ident>,
granted_by: Option<Ident>,
current_grants: Option<CurrentGrantsKind>,
},
/// ```sql
/// DENY privileges ON object TO grantees
Expand Down Expand Up @@ -4312,6 +4313,28 @@ pub enum Statement {
Return(ReturnStatement),
}

/// ```sql
/// {COPY | REVOKE} CURRENT GRANTS
/// ```
///
/// - [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/grant-ownership#optional-parameters)
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum CurrentGrantsKind {
CopyCurrentGrants,
RevokeCurrentGrants,
}

impl fmt::Display for CurrentGrantsKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CurrentGrantsKind::CopyCurrentGrants => write!(f, "COPY CURRENT GRANTS"),
CurrentGrantsKind::RevokeCurrentGrants => write!(f, "REVOKE CURRENT GRANTS"),
}
}
}

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
Expand Down Expand Up @@ -5715,6 +5738,7 @@ impl fmt::Display for Statement {
with_grant_option,
as_grantor,
granted_by,
current_grants,
} => {
write!(f, "GRANT {privileges} ")?;
if let Some(objects) = objects {
Expand All @@ -5724,6 +5748,9 @@ impl fmt::Display for Statement {
if *with_grant_option {
write!(f, " WITH GRANT OPTION")?;
}
if let Some(current_grants) = current_grants {
write!(f, " {current_grants}")?;
}
if let Some(grantor) = as_grantor {
write!(f, " AS {grantor}")?;
}
Expand Down
10 changes: 10 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13794,6 +13794,15 @@ impl<'a> Parser<'a> {
let with_grant_option =
self.parse_keywords(&[Keyword::WITH, Keyword::GRANT, Keyword::OPTION]);

let current_grants =
if self.parse_keywords(&[Keyword::COPY, Keyword::CURRENT, Keyword::GRANTS]) {
Some(CurrentGrantsKind::CopyCurrentGrants)
} else if self.parse_keywords(&[Keyword::REVOKE, Keyword::CURRENT, Keyword::GRANTS]) {
Some(CurrentGrantsKind::RevokeCurrentGrants)
} else {
None
};

let as_grantor = if self.parse_keywords(&[Keyword::AS]) {
Some(self.parse_identifier()?)
} else {
Expand All @@ -13813,6 +13822,7 @@ impl<'a> Parser<'a> {
with_grant_option,
as_grantor,
granted_by,
current_grants,
})
}

Expand Down
2 changes: 2 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9437,6 +9437,8 @@ fn parse_grant() {
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO a:b");
verified_stmt("GRANT USAGE ON SCHEMA sc1 TO GROUP group1");
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST COPY CURRENT GRANTS");
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST REVOKE CURRENT GRANTS");
verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1");
verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1");
verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");
Expand Down
1 change: 1 addition & 0 deletions tests/sqlparser_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3616,6 +3616,7 @@ fn parse_grant() {
with_grant_option,
as_grantor: _,
granted_by,
current_grants: _,
} = stmt
{
assert_eq!(
Expand Down