@@ -4887,6 +4887,8 @@ impl<'a> Parser<'a> {
4887
4887
ObjectType :: Stage
4888
4888
} else if self . parse_keyword ( Keyword :: FUNCTION ) {
4889
4889
return self . parse_drop_function ( ) ;
4890
+ } else if self . parse_keyword ( Keyword :: POLICY ) {
4891
+ return self . parse_drop_policy ( ) ;
4890
4892
} else if self . parse_keyword ( Keyword :: PROCEDURE ) {
4891
4893
return self . parse_drop_procedure ( ) ;
4892
4894
} else if self . parse_keyword ( Keyword :: SECRET ) {
@@ -4928,38 +4930,56 @@ impl<'a> Parser<'a> {
4928
4930
} )
4929
4931
}
4930
4932
4933
+ fn parse_optional_referential_action ( & mut self ) -> Option < ReferentialAction > {
4934
+ match self . parse_one_of_keywords ( & [ Keyword :: CASCADE , Keyword :: RESTRICT ] ) {
4935
+ Some ( Keyword :: CASCADE ) => Some ( ReferentialAction :: Cascade ) ,
4936
+ Some ( Keyword :: RESTRICT ) => Some ( ReferentialAction :: Restrict ) ,
4937
+ _ => None ,
4938
+ }
4939
+ }
4940
+
4931
4941
/// ```sql
4932
4942
/// DROP FUNCTION [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
4933
4943
/// [ CASCADE | RESTRICT ]
4934
4944
/// ```
4935
4945
fn parse_drop_function ( & mut self ) -> Result < Statement , ParserError > {
4936
4946
let if_exists = self . parse_keywords ( & [ Keyword :: IF , Keyword :: EXISTS ] ) ;
4937
4947
let func_desc = self . parse_comma_separated ( Parser :: parse_function_desc) ?;
4938
- let option = match self . parse_one_of_keywords ( & [ Keyword :: CASCADE , Keyword :: RESTRICT ] ) {
4939
- Some ( Keyword :: CASCADE ) => Some ( ReferentialAction :: Cascade ) ,
4940
- Some ( Keyword :: RESTRICT ) => Some ( ReferentialAction :: Restrict ) ,
4941
- _ => None ,
4942
- } ;
4948
+ let option = self . parse_optional_referential_action ( ) ;
4943
4949
Ok ( Statement :: DropFunction {
4944
4950
if_exists,
4945
4951
func_desc,
4946
4952
option,
4947
4953
} )
4948
4954
}
4949
4955
4956
+ /// ```sql
4957
+ /// DROP POLICY [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ]
4958
+ /// ```
4959
+ ///
4960
+ /// [PostgreSQL Documentation](https://www.postgresql.org/docs/current/sql-droppolicy.html)
4961
+ fn parse_drop_policy ( & mut self ) -> Result < Statement , ParserError > {
4962
+ let if_exists = self . parse_keywords ( & [ Keyword :: IF , Keyword :: EXISTS ] ) ;
4963
+ let name = self . parse_identifier ( false ) ?;
4964
+ self . expect_keyword ( Keyword :: ON ) ?;
4965
+ let table_name = self . parse_object_name ( false ) ?;
4966
+ let option = self . parse_optional_referential_action ( ) ;
4967
+ Ok ( Statement :: DropPolicy {
4968
+ if_exists,
4969
+ name,
4970
+ table_name,
4971
+ option,
4972
+ } )
4973
+ }
4974
+
4950
4975
/// ```sql
4951
4976
/// DROP PROCEDURE [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
4952
4977
/// [ CASCADE | RESTRICT ]
4953
4978
/// ```
4954
4979
fn parse_drop_procedure ( & mut self ) -> Result < Statement , ParserError > {
4955
4980
let if_exists = self . parse_keywords ( & [ Keyword :: IF , Keyword :: EXISTS ] ) ;
4956
4981
let proc_desc = self . parse_comma_separated ( Parser :: parse_function_desc) ?;
4957
- let option = match self . parse_one_of_keywords ( & [ Keyword :: CASCADE , Keyword :: RESTRICT ] ) {
4958
- Some ( Keyword :: CASCADE ) => Some ( ReferentialAction :: Cascade ) ,
4959
- Some ( Keyword :: RESTRICT ) => Some ( ReferentialAction :: Restrict ) ,
4960
- Some ( _) => unreachable ! ( ) , // parse_one_of_keywords does not return other keywords
4961
- None => None ,
4962
- } ;
4982
+ let option = self . parse_optional_referential_action ( ) ;
4963
4983
Ok ( Statement :: DropProcedure {
4964
4984
if_exists,
4965
4985
proc_desc,
0 commit comments