Skip to content

Snowflake: Support GRANT CREATE SCHEMA GRANT .. ON ALL FUNCTIONS IN SCHEMA #1964

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 1 commit into from
Jul 24, 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
11 changes: 11 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6771,6 +6771,7 @@ pub enum ActionCreateObjectType {
OrganiationListing,
ReplicationGroup,
Role,
Schema,
Share,
User,
Warehouse,
Expand All @@ -6792,6 +6793,7 @@ impl fmt::Display for ActionCreateObjectType {
ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
ActionCreateObjectType::Role => write!(f, "ROLE"),
ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
ActionCreateObjectType::Share => write!(f, "SHARE"),
ActionCreateObjectType::User => write!(f, "USER"),
ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
Expand Down Expand Up @@ -7029,6 +7031,8 @@ pub enum GrantObjects {
AllMaterializedViewsInSchema { schemas: Vec<ObjectName> },
/// Grant privileges on `ALL EXTERNAL TABLES IN SCHEMA <schema_name> [, ...]`
AllExternalTablesInSchema { schemas: Vec<ObjectName> },
/// Grant privileges on `ALL FUNCTIONS IN SCHEMA <schema_name> [, ...]`
AllFunctionsInSchema { schemas: Vec<ObjectName> },
/// Grant privileges on `FUTURE SCHEMAS IN DATABASE <database_name> [, ...]`
FutureSchemasInDatabase { databases: Vec<ObjectName> },
/// Grant privileges on `FUTURE TABLES IN SCHEMA <schema_name> [, ...]`
Expand Down Expand Up @@ -7149,6 +7153,13 @@ impl fmt::Display for GrantObjects {
display_comma_separated(schemas)
)
}
GrantObjects::AllFunctionsInSchema { schemas } => {
write!(
f,
"ALL FUNCTIONS IN SCHEMA {}",
display_comma_separated(schemas)
)
}
GrantObjects::FutureSchemasInDatabase { databases } => {
write!(
f,
Expand Down
11 changes: 11 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14108,6 +14108,15 @@ impl<'a> Parser<'a> {
Some(GrantObjects::AllMaterializedViewsInSchema {
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
})
} else if self.parse_keywords(&[
Keyword::ALL,
Keyword::FUNCTIONS,
Keyword::IN,
Keyword::SCHEMA,
]) {
Some(GrantObjects::AllFunctionsInSchema {
schemas: self.parse_comma_separated(|p| p.parse_object_name(false))?,
})
} else if self.parse_keywords(&[
Keyword::FUTURE,
Keyword::SCHEMAS,
Expand Down Expand Up @@ -14414,6 +14423,8 @@ impl<'a> Parser<'a> {
Some(ActionCreateObjectType::Integration)
} else if self.parse_keyword(Keyword::ROLE) {
Some(ActionCreateObjectType::Role)
} else if self.parse_keyword(Keyword::SCHEMA) {
Some(ActionCreateObjectType::Schema)
} else if self.parse_keyword(Keyword::SHARE) {
Some(ActionCreateObjectType::Share)
} else if self.parse_keyword(Keyword::USER) {
Expand Down
2 changes: 2 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9528,6 +9528,7 @@ fn parse_grant() {
verified_stmt("GRANT SELECT ON ALL VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
verified_stmt("GRANT SELECT ON ALL MATERIALIZED VIEWS IN SCHEMA db1.sc1 TO ROLE role1");
verified_stmt("GRANT SELECT ON ALL EXTERNAL TABLES IN SCHEMA db1.sc1 TO ROLE role1");
verified_stmt("GRANT USAGE ON ALL FUNCTIONS IN SCHEMA db1.sc1 TO ROLE role1");
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");
Expand All @@ -9551,6 +9552,7 @@ fn parse_grant() {
verified_stmt("GRANT USAGE ON FUNCTION db1.sc1.foo(INT) TO ROLE role1");
verified_stmt("GRANT ROLE role1 TO ROLE role2");
verified_stmt("GRANT ROLE role1 TO USER user");
verified_stmt("GRANT CREATE SCHEMA ON DATABASE db1 TO ROLE role1");
}

#[test]
Expand Down
Loading