@@ -3019,6 +3019,36 @@ impl From<Set> for Statement {
30193019 }
30203020}
30213021
3022+ /// A representation of a `WHEN` arm with all the identifiers catched and the statements to execute
3023+ /// for the arm.
3024+ ///
3025+ /// Snowflake: <https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
3026+ /// BigQuery: <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
3027+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
3028+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
3029+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
3030+ pub struct ExceptionWhen {
3031+ pub idents : Vec < Ident > ,
3032+ pub statements : Vec < Statement > ,
3033+ }
3034+
3035+ impl Display for ExceptionWhen {
3036+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3037+ write ! (
3038+ f,
3039+ "WHEN {idents} THEN" ,
3040+ idents = display_separated( & self . idents, " OR " )
3041+ ) ?;
3042+
3043+ if !self . statements . is_empty ( ) {
3044+ write ! ( f, " " ) ?;
3045+ format_statement_list ( f, & self . statements ) ?;
3046+ }
3047+
3048+ Ok ( ( ) )
3049+ }
3050+ }
3051+
30223052/// A top-level statement (SELECT, INSERT, CREATE, etc.)
30233053#[ allow( clippy:: large_enum_variant) ]
30243054#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -3707,17 +3737,20 @@ pub enum Statement {
37073737 /// END;
37083738 /// ```
37093739 statements : Vec < Statement > ,
3710- /// Statements of an exception clause .
3740+ /// Exception handling with exception clauses .
37113741 /// Example:
37123742 /// ```sql
3713- /// BEGIN
3714- /// SELECT 1;
3715- /// EXCEPTION WHEN ERROR THEN
3716- /// SELECT 2;
3717- /// SELECT 3;
3718- /// END;
3743+ /// EXCEPTION
3744+ /// WHEN EXCEPTION_1 THEN
3745+ /// SELECT 2;
3746+ /// WHEN EXCEPTION_2 OR EXCEPTION_3 THEN
3747+ /// SELECT 3;
3748+ /// WHEN OTHER THEN
3749+ /// SELECT 4;
3750+ /// ```
37193751 /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#beginexceptionend>
3720- exception_statements : Option < Vec < Statement > > ,
3752+ /// <https://docs.snowflake.com/en/sql-reference/snowflake-scripting/exception>
3753+ exception : Option < Vec < ExceptionWhen > > ,
37213754 /// TRUE if the statement has an `END` keyword.
37223755 has_end_keyword : bool ,
37233756 } ,
@@ -5562,7 +5595,7 @@ impl fmt::Display for Statement {
55625595 transaction,
55635596 modifier,
55645597 statements,
5565- exception_statements ,
5598+ exception ,
55665599 has_end_keyword,
55675600 } => {
55685601 if * syntax_begin {
@@ -5584,11 +5617,10 @@ impl fmt::Display for Statement {
55845617 write ! ( f, " " ) ?;
55855618 format_statement_list ( f, statements) ?;
55865619 }
5587- if let Some ( exception_statements) = exception_statements {
5588- write ! ( f, " EXCEPTION WHEN ERROR THEN" ) ?;
5589- if !exception_statements. is_empty ( ) {
5590- write ! ( f, " " ) ?;
5591- format_statement_list ( f, exception_statements) ?;
5620+ if let Some ( exception_when) = exception {
5621+ write ! ( f, " EXCEPTION" ) ?;
5622+ for when in exception_when {
5623+ write ! ( f, " {when}" ) ?;
55925624 }
55935625 }
55945626 if * has_end_keyword {
0 commit comments