From c01e054fd85a4dcd16f27ca949e72d6a226d2f66 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 9 Oct 2024 06:59:00 -0700 Subject: [PATCH] Add "DROP TYPE" support. (#1461) --- src/ast/mod.rs | 2 ++ src/parser/mod.rs | 4 ++- tests/sqlparser_common.rs | 54 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index bc559a660..39f9def8e 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -5736,6 +5736,7 @@ pub enum ObjectType { Role, Sequence, Stage, + Type, } impl fmt::Display for ObjectType { @@ -5749,6 +5750,7 @@ impl fmt::Display for ObjectType { ObjectType::Role => "ROLE", ObjectType::Sequence => "SEQUENCE", ObjectType::Stage => "STAGE", + ObjectType::Type => "TYPE", }) } } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index cc60bbbd7..c9e66e1f3 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -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) { @@ -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(), ); }; diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 7068ffc30..15132903c 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -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()");