Add support for CREATE SCHEMA WITH ( <properties> ) (#1877)
Some checks are pending
Rust / test (stable) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run

This commit is contained in:
Yannick Utard 2025-06-10 06:50:10 +02:00 committed by GitHub
parent 84c3a1b325
commit 40d12b98bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 0 deletions

View file

@ -3725,6 +3725,14 @@ pub enum Statement {
/// `<schema name> | AUTHORIZATION <schema authorization identifier> | <schema name> AUTHORIZATION <schema authorization identifier>` /// `<schema name> | AUTHORIZATION <schema authorization identifier> | <schema name> AUTHORIZATION <schema authorization identifier>`
schema_name: SchemaName, schema_name: SchemaName,
if_not_exists: bool, 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. /// Schema options.
/// ///
/// ```sql /// ```sql
@ -5585,6 +5593,7 @@ impl fmt::Display for Statement {
Statement::CreateSchema { Statement::CreateSchema {
schema_name, schema_name,
if_not_exists, if_not_exists,
with,
options, options,
default_collate_spec, default_collate_spec,
} => { } => {
@ -5599,6 +5608,10 @@ impl fmt::Display for Statement {
write!(f, " DEFAULT COLLATE {collate}")?; write!(f, " DEFAULT COLLATE {collate}")?;
} }
if let Some(with) = with {
write!(f, " WITH ({})", display_comma_separated(with))?;
}
if let Some(options) = options { if let Some(options) = options {
write!(f, " OPTIONS({})", display_comma_separated(options))?; write!(f, " OPTIONS({})", display_comma_separated(options))?;
} }

View file

@ -4862,6 +4862,12 @@ impl<'a> Parser<'a> {
None 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) { let options = if self.peek_keyword(Keyword::OPTIONS) {
Some(self.parse_options(Keyword::OPTIONS)?) Some(self.parse_options(Keyword::OPTIONS)?)
} else { } else {
@ -4871,6 +4877,7 @@ impl<'a> Parser<'a> {
Ok(Statement::CreateSchema { Ok(Statement::CreateSchema {
schema_name, schema_name,
if_not_exists, if_not_exists,
with,
options, options,
default_collate_spec, default_collate_spec,
}) })

View file

@ -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(key1 = 'value1')"#);
verified_stmt(r#"CREATE SCHEMA IF NOT EXISTS a OPTIONS()"#); 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 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] #[test]