mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
mod, parser and test cases for CREATE [ { TEMPORARY | TEMP } ] SEQUENCE [ IF NOT EXISTS ] (#678)
This commit is contained in:
parent
b32cbbd855
commit
e3c936a6ce
3 changed files with 53 additions and 0 deletions
|
@ -1452,6 +1452,13 @@ pub enum Statement {
|
|||
table_name: ObjectName,
|
||||
if_exists: bool,
|
||||
},
|
||||
///CreateSequence -- define a new sequence
|
||||
/// CREATE [ { TEMPORARY | TEMP } ] SEQUENCE [ IF NOT EXISTS ] <sequence_name>
|
||||
CreateSequence {
|
||||
temporary: bool,
|
||||
if_not_exists: bool,
|
||||
name: ObjectName,
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Display for Statement {
|
||||
|
@ -2468,6 +2475,19 @@ impl fmt::Display for Statement {
|
|||
write!(f, "UNCACHE TABLE {table_name}", table_name = table_name)
|
||||
}
|
||||
}
|
||||
Statement::CreateSequence {
|
||||
temporary,
|
||||
if_not_exists,
|
||||
name,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"CREATE {temporary}SEQUENCE {if_not_exists}{name}",
|
||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
||||
temporary = if *temporary { "TEMPORARY " } else { "" },
|
||||
name = name
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1904,6 +1904,8 @@ impl<'a> Parser<'a> {
|
|||
self.parse_create_function(temporary)
|
||||
} else if self.parse_keyword(Keyword::ROLE) {
|
||||
self.parse_create_role()
|
||||
} else if self.parse_keyword(Keyword::SEQUENCE) {
|
||||
self.parse_create_sequence(temporary)
|
||||
} else {
|
||||
self.expected("an object type after CREATE", self.peek_token())
|
||||
}
|
||||
|
@ -5414,6 +5416,20 @@ impl<'a> Parser<'a> {
|
|||
clauses,
|
||||
})
|
||||
}
|
||||
|
||||
/// https://www.postgresql.org/docs/current/sql-createsequence.html
|
||||
/// CREATE [ { TEMPORARY | TEMP } ] SEQUENCE [ IF NOT EXISTS ] <sequence_name>
|
||||
pub fn parse_create_sequence(&mut self, temporary: bool) -> Result<Statement, ParserError> {
|
||||
//[ IF NOT EXISTS ]
|
||||
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
|
||||
//name
|
||||
let name = self.parse_object_name()?;
|
||||
Ok(Statement::CreateSequence {
|
||||
temporary,
|
||||
if_not_exists,
|
||||
name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Word {
|
||||
|
|
|
@ -22,6 +22,23 @@ use sqlparser::ast::*;
|
|||
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
||||
use sqlparser::parser::ParserError;
|
||||
|
||||
#[test]
|
||||
fn parse_create_sequence() {
|
||||
// SimpleLogger::new().init().unwrap();
|
||||
|
||||
let sql1 = "CREATE SEQUENCE name0";
|
||||
pg().one_statement_parses_to(sql1, "CREATE SEQUENCE name0");
|
||||
|
||||
let sql2 = "CREATE SEQUENCE IF NOT EXISTS name0";
|
||||
pg().one_statement_parses_to(sql2, "CREATE SEQUENCE IF NOT EXISTS name0");
|
||||
|
||||
let sql3 = "CREATE TEMPORARY SEQUENCE IF NOT EXISTS name0";
|
||||
pg().one_statement_parses_to(sql3, "CREATE TEMPORARY SEQUENCE IF NOT EXISTS name0");
|
||||
|
||||
let sql4 = "CREATE TEMPORARY SEQUENCE name0";
|
||||
pg().one_statement_parses_to(sql4, "CREATE TEMPORARY SEQUENCE name0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_drop_sequence() {
|
||||
// SimpleLogger::new().init().unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue