Skip to content
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
9 changes: 9 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4417,6 +4417,11 @@ pub enum Statement {
///
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-clone#databases-schemas)
clone: Option<ObjectName>,
/// Space-separated Snowflake `COMMENT` and `DATA_RETENTION_TIME_IN_DAYS` assignments.
/// Stored as [`SqlOption::KeyValue`] entries in source order, retaining duplicates
/// and literal values for the execution consumer to validate.
#[cfg_attr(feature = "serde", serde(default))]
schema_options: Vec<SqlOption>,
},
/// ```sql
/// CREATE DATABASE
Expand Down Expand Up @@ -6217,6 +6222,7 @@ impl fmt::Display for Statement {
options,
default_collate_spec,
clone,
schema_options,
} => {
write!(
f,
Expand All @@ -6240,6 +6246,9 @@ impl fmt::Display for Statement {
if let Some(clone) = clone {
write!(f, " CLONE {clone}")?;
}
for option in schema_options {
write!(f, " {option}")?;
}
Ok(())
}
Statement::Assert { condition, message } => {
Expand Down
8 changes: 8 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,14 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if `CREATE SCHEMA` supports space-separated `COMMENT = <literal>`
/// and `DATA_RETENTION_TIME_IN_DAYS = <literal>` suffix options.
///
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-schema)
fn supports_create_schema_options(&self) -> bool {
false
}

/// Returns true if the dialect supports the `USING` clause in an `ALTER COLUMN` statement.
/// Example:
/// ```sql
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ impl Dialect for SnowflakeDialect {
true
}

fn supports_create_schema_options(&self) -> bool {
true
}

fn supports_comma_separated_drop_column_list(&self) -> bool {
true
}
Expand Down
29 changes: 29 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5208,6 +5208,18 @@ impl<'a> Parser<'a> {
self.parse_create_index(true).map(Into::into)
} else if self.parse_keyword(Keyword::VIRTUAL) {
self.parse_create_virtual_table()
} else if self.peek_keyword(Keyword::SCHEMA)
&& (or_alter
|| global.is_some()
|| transient
|| temporary
|| persistent
|| create_view_params.is_some())
{
self.expected_ref(
"an object type supporting the CREATE modifiers",
self.peek_token_ref(),
)
} else if self.parse_keyword(Keyword::SCHEMA) {
self.parse_create_schema()
} else if self.parse_keyword(Keyword::DATABASE) {
Expand Down Expand Up @@ -5476,13 +5488,30 @@ impl<'a> Parser<'a> {
None
};

let mut schema_options = Vec::new();
if self.dialect.supports_create_schema_options() {
while self
.peek_one_of_keywords(&[Keyword::COMMENT, Keyword::DATA_RETENTION_TIME_IN_DAYS])
.is_some()
{
let key = self.parse_identifier()?;
self.expect_token(&Token::Eq)?;
let value = match self.peek_token_ref().token {
Token::Number(..) | Token::Plus | Token::Minus => self.parse_number()?,
_ => Expr::Value(self.parse_value()?),
};
schema_options.push(SqlOption::KeyValue { key, value });
}
}

Ok(Statement::CreateSchema {
schema_name,
if_not_exists,
with,
options,
default_collate_spec,
clone,
schema_options,
})
}

Expand Down
Loading
Loading