mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-02 12:17:21 +00:00
Support IF NOT EXISTS for CREATE SCHEMA (#276)
This is a Postgres-specific clause: https://www.postgresql.org/docs/12/sql-createschema.html Also add a test for `DROP SCHEMA IF EXISTS schema_name`, which is already supported in the parser.
This commit is contained in:
parent
926b03a31d
commit
1ac208307c
4 changed files with 46 additions and 4 deletions
|
@ -558,7 +558,10 @@ pub enum Statement {
|
|||
/// `ROLLBACK [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ]`
|
||||
Rollback { chain: bool },
|
||||
/// CREATE SCHEMA
|
||||
CreateSchema { schema_name: ObjectName },
|
||||
CreateSchema {
|
||||
schema_name: ObjectName,
|
||||
if_not_exists: bool,
|
||||
},
|
||||
/// `ASSERT <condition> [AS <message>]`
|
||||
Assert {
|
||||
condition: Expr,
|
||||
|
@ -829,7 +832,15 @@ impl fmt::Display for Statement {
|
|||
Statement::Rollback { chain } => {
|
||||
write!(f, "ROLLBACK{}", if *chain { " AND CHAIN" } else { "" },)
|
||||
}
|
||||
Statement::CreateSchema { schema_name } => write!(f, "CREATE SCHEMA {}", schema_name),
|
||||
Statement::CreateSchema {
|
||||
schema_name,
|
||||
if_not_exists,
|
||||
} => write!(
|
||||
f,
|
||||
"CREATE SCHEMA {if_not_exists}{name}",
|
||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
||||
name = schema_name
|
||||
),
|
||||
Statement::Assert { condition, message } => {
|
||||
write!(f, "ASSERT {}", condition)?;
|
||||
if let Some(m) = message {
|
||||
|
|
|
@ -1078,8 +1078,12 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
pub fn parse_create_schema(&mut self) -> Result<Statement, ParserError> {
|
||||
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
|
||||
let schema_name = self.parse_object_name()?;
|
||||
Ok(Statement::CreateSchema { schema_name })
|
||||
Ok(Statement::CreateSchema {
|
||||
schema_name,
|
||||
if_not_exists,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_create_external_table(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue