Skip to content

Commit

Permalink
Support DROP DATABASE (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
linhr authored Sep 29, 2024
1 parent 2af981e commit 73dc8a3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5691,6 +5691,7 @@ pub enum ObjectType {
View,
Index,
Schema,
Database,
Role,
Sequence,
Stage,
Expand All @@ -5703,6 +5704,7 @@ impl fmt::Display for ObjectType {
ObjectType::View => "VIEW",
ObjectType::Index => "INDEX",
ObjectType::Schema => "SCHEMA",
ObjectType::Database => "DATABASE",
ObjectType::Role => "ROLE",
ObjectType::Sequence => "SEQUENCE",
ObjectType::Stage => "STAGE",
Expand Down
4 changes: 3 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4881,6 +4881,8 @@ impl<'a> Parser<'a> {
ObjectType::Role
} else if self.parse_keyword(Keyword::SCHEMA) {
ObjectType::Schema
} else if self.parse_keyword(Keyword::DATABASE) {
ObjectType::Database
} else if self.parse_keyword(Keyword::SEQUENCE) {
ObjectType::Sequence
} else if self.parse_keyword(Keyword::STAGE) {
Expand All @@ -4897,7 +4899,7 @@ impl<'a> Parser<'a> {
return self.parse_drop_trigger();
} else {
return self.expected(
"TABLE, VIEW, INDEX, ROLE, SCHEMA, FUNCTION, PROCEDURE, STAGE, TRIGGER, SECRET or SEQUENCE after DROP",
"TABLE, VIEW, INDEX, ROLE, SCHEMA, DATABASE, FUNCTION, PROCEDURE, STAGE, TRIGGER, SECRET or SEQUENCE after DROP",
self.peek_token(),
);
};
Expand Down
37 changes: 37 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6734,6 +6734,43 @@ fn parse_create_database_ine() {
}
}

#[test]
fn parse_drop_database() {
let sql = "DROP DATABASE mycatalog.mydb";
match verified_stmt(sql) {
Statement::Drop {
names,
object_type,
if_exists,
..
} => {
assert_eq!(
vec!["mycatalog.mydb"],
names.iter().map(ToString::to_string).collect::<Vec<_>>()
);
assert_eq!(ObjectType::Database, object_type);
assert!(!if_exists);
}
_ => unreachable!(),
}
}

#[test]
fn parse_drop_database_if_exists() {
let sql = "DROP DATABASE IF EXISTS mydb";
match verified_stmt(sql) {
Statement::Drop {
object_type,
if_exists,
..
} => {
assert_eq!(ObjectType::Database, object_type);
assert!(if_exists);
}
_ => unreachable!(),
}
}

#[test]
fn parse_create_view() {
let sql = "CREATE VIEW myschema.myview AS SELECT foo FROM bar";
Expand Down

0 comments on commit 73dc8a3

Please sign in to comment.