mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-08 01:15:00 +00:00
Support drop sequence statement (#673)
* Add ObjectType Sequence * Drop sequence test cases added. * Parser and Drop statement Display updated. * Parser and Drop statement Display updated. * Fix compile errors * add new test case
This commit is contained in:
parent
b42632fa0d
commit
b32cbbd855
4 changed files with 33 additions and 2 deletions
|
@ -1184,6 +1184,9 @@ pub enum Statement {
|
|||
/// Whether `CASCADE` was specified. This will be `false` when
|
||||
/// `RESTRICT` or no drop behavior at all was specified.
|
||||
cascade: bool,
|
||||
/// Whether `RESTRICT` was specified. This will be `false` when
|
||||
/// `CASCADE` or no drop behavior at all was specified.
|
||||
restrict: bool,
|
||||
/// Hive allows you specify whether the table's stored data will be
|
||||
/// deleted along with the dropped table
|
||||
purge: bool,
|
||||
|
@ -2143,14 +2146,16 @@ impl fmt::Display for Statement {
|
|||
if_exists,
|
||||
names,
|
||||
cascade,
|
||||
restrict,
|
||||
purge,
|
||||
} => write!(
|
||||
f,
|
||||
"DROP {}{} {}{}{}",
|
||||
"DROP {}{} {}{}{}{}",
|
||||
object_type,
|
||||
if *if_exists { " IF EXISTS" } else { "" },
|
||||
display_comma_separated(names),
|
||||
if *cascade { " CASCADE" } else { "" },
|
||||
if *restrict { " RESTRICT" } else { "" },
|
||||
if *purge { " PURGE" } else { "" }
|
||||
),
|
||||
Statement::Discard { object_type } => {
|
||||
|
@ -2910,6 +2915,7 @@ pub enum ObjectType {
|
|||
Index,
|
||||
Schema,
|
||||
Role,
|
||||
Sequence,
|
||||
}
|
||||
|
||||
impl fmt::Display for ObjectType {
|
||||
|
@ -2920,6 +2926,7 @@ impl fmt::Display for ObjectType {
|
|||
ObjectType::Index => "INDEX",
|
||||
ObjectType::Schema => "SCHEMA",
|
||||
ObjectType::Role => "ROLE",
|
||||
ObjectType::Sequence => "SEQUENCE",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2441,9 +2441,11 @@ impl<'a> Parser<'a> {
|
|||
ObjectType::Role
|
||||
} else if self.parse_keyword(Keyword::SCHEMA) {
|
||||
ObjectType::Schema
|
||||
} else if self.parse_keyword(Keyword::SEQUENCE) {
|
||||
ObjectType::Sequence
|
||||
} else {
|
||||
return self.expected(
|
||||
"TABLE, VIEW, INDEX, ROLE, or SCHEMA after DROP",
|
||||
"TABLE, VIEW, INDEX, ROLE, SCHEMA, or SEQUENCE after DROP",
|
||||
self.peek_token(),
|
||||
);
|
||||
};
|
||||
|
@ -2465,6 +2467,7 @@ impl<'a> Parser<'a> {
|
|||
if_exists,
|
||||
names,
|
||||
cascade,
|
||||
restrict,
|
||||
purge,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4469,6 +4469,7 @@ fn parse_drop_table() {
|
|||
names,
|
||||
cascade,
|
||||
purge: _,
|
||||
..
|
||||
} => {
|
||||
assert!(!if_exists);
|
||||
assert_eq!(ObjectType::Table, object_type);
|
||||
|
@ -4489,6 +4490,7 @@ fn parse_drop_table() {
|
|||
names,
|
||||
cascade,
|
||||
purge: _,
|
||||
..
|
||||
} => {
|
||||
assert!(if_exists);
|
||||
assert_eq!(ObjectType::Table, object_type);
|
||||
|
|
|
@ -22,6 +22,25 @@ use sqlparser::ast::*;
|
|||
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
||||
use sqlparser::parser::ParserError;
|
||||
|
||||
#[test]
|
||||
fn parse_drop_sequence() {
|
||||
// SimpleLogger::new().init().unwrap();
|
||||
let sql1 = "DROP SEQUENCE IF EXISTS name0 CASCADE";
|
||||
pg().one_statement_parses_to(sql1, "DROP SEQUENCE IF EXISTS name0 CASCADE");
|
||||
let sql2 = "DROP SEQUENCE IF EXISTS name1 RESTRICT";
|
||||
pg().one_statement_parses_to(sql2, "DROP SEQUENCE IF EXISTS name1 RESTRICT");
|
||||
let sql3 = "DROP SEQUENCE name2 CASCADE";
|
||||
pg().one_statement_parses_to(sql3, "DROP SEQUENCE name2 CASCADE");
|
||||
let sql4 = "DROP SEQUENCE name2";
|
||||
pg().one_statement_parses_to(sql4, "DROP SEQUENCE name2");
|
||||
let sql5 = "DROP SEQUENCE name0 CASCADE";
|
||||
pg().one_statement_parses_to(sql5, "DROP SEQUENCE name0 CASCADE");
|
||||
let sql6 = "DROP SEQUENCE name1 RESTRICT";
|
||||
pg().one_statement_parses_to(sql6, "DROP SEQUENCE name1 RESTRICT");
|
||||
let sql7 = "DROP SEQUENCE name1, name2, name3";
|
||||
pg().one_statement_parses_to(sql7, "DROP SEQUENCE name1, name2, name3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_with_defaults() {
|
||||
let sql = "CREATE TABLE public.customer (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue