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
13 changes: 13 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3725,6 +3725,14 @@ pub enum Statement {
/// `<schema name> | AUTHORIZATION <schema authorization identifier> | <schema name> AUTHORIZATION <schema authorization identifier>`
schema_name: SchemaName,
if_not_exists: bool,
/// Schema properties.
///
/// ```sql
/// CREATE SCHEMA myschema WITH (key1='value1');
/// ```
///
/// [Trino](https://trino.io/docs/current/sql/create-schema.html)
with: Option<Vec<SqlOption>>,
/// Schema options.
///
/// ```sql
Expand Down Expand Up @@ -5585,6 +5593,7 @@ impl fmt::Display for Statement {
Statement::CreateSchema {
schema_name,
if_not_exists,
with,
options,
default_collate_spec,
} => {
Expand All @@ -5599,6 +5608,10 @@ impl fmt::Display for Statement {
write!(f, " DEFAULT COLLATE {collate}")?;
}

if let Some(with) = with {
write!(f, " WITH ({})", display_comma_separated(with))?;
}

if let Some(options) = options {
write!(f, " OPTIONS({})", display_comma_separated(options))?;
}
Expand Down
7 changes: 7 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4862,6 +4862,12 @@ impl<'a> Parser<'a> {
None
};

let with = if self.peek_keyword(Keyword::WITH) {
Some(self.parse_options(Keyword::WITH)?)
} else {
None
};

let options = if self.peek_keyword(Keyword::OPTIONS) {
Some(self.parse_options(Keyword::OPTIONS)?)
} else {
Expand All @@ -4871,6 +4877,7 @@ impl<'a> Parser<'a> {
Ok(Statement::CreateSchema {
schema_name,
if_not_exists,
with,
options,
default_collate_spec,
})
Expand Down
3 changes: 3 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4268,6 +4268,9 @@ fn parse_create_schema() {
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a OPTIONS(key1 = 'value1')"#);
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a OPTIONS()"#);
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a DEFAULT COLLATE 'und:ci' OPTIONS()"#);
verified_stmt(r#"CREATE SCHEMA a.b.c WITH (key1 = 'value1', key2 = 'value2')"#);
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a WITH (key1 = 'value1')"#);
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a WITH ()"#);
}

#[test]
Expand Down