Skip to content

Commit

Permalink
Add "DROP TYPE" support. (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
caldwell authored Oct 9, 2024
1 parent 7905fb4 commit c01e054
Show file tree
Hide file tree
Showing 3 changed files with 59 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 @@ -5736,6 +5736,7 @@ pub enum ObjectType {
Role,
Sequence,
Stage,
Type,
}

impl fmt::Display for ObjectType {
Expand All @@ -5749,6 +5750,7 @@ impl fmt::Display for ObjectType {
ObjectType::Role => "ROLE",
ObjectType::Sequence => "SEQUENCE",
ObjectType::Stage => "STAGE",
ObjectType::Type => "TYPE",
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4889,6 +4889,8 @@ impl<'a> Parser<'a> {
ObjectType::Sequence
} else if self.parse_keyword(Keyword::STAGE) {
ObjectType::Stage
} else if self.parse_keyword(Keyword::TYPE) {
ObjectType::Type
} else if self.parse_keyword(Keyword::FUNCTION) {
return self.parse_drop_function();
} else if self.parse_keyword(Keyword::POLICY) {
Expand All @@ -4901,7 +4903,7 @@ impl<'a> Parser<'a> {
return self.parse_drop_trigger();
} else {
return self.expected(
"TABLE, VIEW, INDEX, ROLE, SCHEMA, DATABASE, FUNCTION, PROCEDURE, STAGE, TRIGGER, SECRET or SEQUENCE after DROP",
"TABLE, VIEW, INDEX, ROLE, SCHEMA, DATABASE, FUNCTION, PROCEDURE, STAGE, TRIGGER, SECRET, SEQUENCE, or TYPE after DROP",
self.peek_token(),
);
};
Expand Down
54 changes: 54 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9690,6 +9690,60 @@ fn parse_create_type() {
);
}

#[test]
fn parse_drop_type() {
let sql = "DROP TYPE abc";
match verified_stmt(sql) {
Statement::Drop {
names,
object_type,
if_exists,
cascade,
..
} => {
assert_eq_vec(&["abc"], &names);
assert_eq!(ObjectType::Type, object_type);
assert!(!if_exists);
assert!(!cascade);
}
_ => unreachable!(),
};

let sql = "DROP TYPE IF EXISTS def, magician, quaternion";
match verified_stmt(sql) {
Statement::Drop {
names,
object_type,
if_exists,
cascade,
..
} => {
assert_eq_vec(&["def", "magician", "quaternion"], &names);
assert_eq!(ObjectType::Type, object_type);
assert!(if_exists);
assert!(!cascade);
}
_ => unreachable!(),
}

let sql = "DROP TYPE IF EXISTS my_type CASCADE";
match verified_stmt(sql) {
Statement::Drop {
names,
object_type,
if_exists,
cascade,
..
} => {
assert_eq_vec(&["my_type"], &names);
assert_eq!(ObjectType::Type, object_type);
assert!(if_exists);
assert!(cascade);
}
_ => unreachable!(),
}
}

#[test]
fn parse_call() {
all_dialects().verified_stmt("CALL my_procedure()");
Expand Down

0 comments on commit c01e054

Please sign in to comment.