@@ -2990,6 +2990,36 @@ impl From<Set> for Statement {
29902990 }
29912991}
29922992
2993+ /// A representation of a `WHEN` arm with all the identifiers catched and the statements to execute
2994+ /// for the arm.
2995+ ///
2996+ /// Snowflake: <https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
2997+ /// BigQuery: <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
2998+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2999+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
3000+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
3001+ pub struct ExceptionWhen {
3002+ pub idents : Vec < Ident > ,
3003+ pub statements : Vec < Statement > ,
3004+ }
3005+
3006+ impl Display for ExceptionWhen {
3007+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3008+ write ! (
3009+ f,
3010+ "WHEN {idents} THEN" ,
3011+ idents = display_separated( & self . idents, " OR " )
3012+ ) ?;
3013+
3014+ if !self . statements . is_empty ( ) {
3015+ write ! ( f, " " ) ?;
3016+ format_statement_list ( f, & self . statements ) ?;
3017+ }
3018+
3019+ Ok ( ( ) )
3020+ }
3021+ }
3022+
29933023/// A top-level statement (SELECT, INSERT, CREATE, etc.)
29943024#[ allow( clippy:: large_enum_variant) ]
29953025#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -3678,17 +3708,20 @@ pub enum Statement {
36783708 /// END;
36793709 /// ```
36803710 statements : Vec < Statement > ,
3681- /// Statements of an exception clause .
3711+ /// Exception handling with exception clauses .
36823712 /// Example:
36833713 /// ```sql
3684- /// BEGIN
3685- /// SELECT 1;
3686- /// EXCEPTION WHEN ERROR THEN
3687- /// SELECT 2;
3688- /// SELECT 3;
3689- /// END;
3714+ /// EXCEPTION
3715+ /// WHEN EXCEPTION_1 THEN
3716+ /// SELECT 2;
3717+ /// WHEN EXCEPTION_2 OR EXCEPTION_3 THEN
3718+ /// SELECT 3;
3719+ /// WHEN OTHER THEN
3720+ /// SELECT 4;
3721+ /// ```
36903722 /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
3691- exception_statements : Option < Vec < Statement > > ,
3723+ /// <https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
3724+ exception : Option < Vec < ExceptionWhen > > ,
36923725 /// TRUE if the statement has an `END` keyword.
36933726 has_end_keyword : bool ,
36943727 } ,
@@ -5533,7 +5566,7 @@ impl fmt::Display for Statement {
55335566 transaction,
55345567 modifier,
55355568 statements,
5536- exception_statements ,
5569+ exception ,
55375570 has_end_keyword,
55385571 } => {
55395572 if * syntax_begin {
@@ -5555,11 +5588,10 @@ impl fmt::Display for Statement {
55555588 write ! ( f, " " ) ?;
55565589 format_statement_list ( f, statements) ?;
55575590 }
5558- if let Some ( exception_statements) = exception_statements {
5559- write ! ( f, " EXCEPTION WHEN ERROR THEN" ) ?;
5560- if !exception_statements. is_empty ( ) {
5561- write ! ( f, " " ) ?;
5562- format_statement_list ( f, exception_statements) ?;
5591+ if let Some ( exception_when) = exception {
5592+ write ! ( f, " EXCEPTION" ) ?;
5593+ for when in exception_when {
5594+ write ! ( f, " {when}" ) ?;
55635595 }
55645596 }
55655597 if * has_end_keyword {
0 commit comments