romanb commented on code in PR #1791:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1791#discussion_r2029344741


##########
src/ast/mod.rs:
##########
@@ -2145,116 +2149,189 @@ impl fmt::Display for CaseStatement {
         }
 
         if let Some(else_block) = else_block {
-            write!(f, " ELSE ")?;
-            format_statement_list(f, else_block)?;
+            write!(f, " {else_block}")?;
         }
 
         write!(f, " END")?;
-        if *has_end_case {
-            write!(f, " CASE")?;
+
+        if let Token::Word(w) = &end.token {
+            if w.keyword == Keyword::CASE {
+                write!(f, " CASE")?;
+            }
         }
 
         Ok(())
     }
 }
 
 /// An `IF` statement.
-///
-/// Examples:
-/// ```sql
-/// IF TRUE THEN
-///     SELECT 1;
-///     SELECT 2;
-/// ELSEIF TRUE THEN
-///     SELECT 3;
-/// ELSE
-///     SELECT 4;
-/// END IF
-/// ```
-///
-/// 
[BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#if)
-/// 
[Snowflake](https://docs.snowflake.com/en/sql-reference/snowflake-scripting/if)
 #[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
-pub struct IfStatement {
-    pub if_block: ConditionalStatements,
-    pub elseif_blocks: Vec<ConditionalStatements>,
-    pub else_block: Option<Vec<Statement>>,
+pub enum IfStatement {
+    /// An `IF ... THEN [ELSE[IF] ...] END IF` statement.
+    ///
+    /// Example:
+    /// ```sql
+    /// IF TRUE THEN
+    ///     SELECT 1;
+    ///     SELECT 2;
+    /// ELSEIF TRUE THEN
+    ///     SELECT 3;
+    /// ELSE
+    ///     SELECT 4;
+    /// END IF
+    /// ```
+    ///
+    /// 
[BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#if)
+    /// 
[Snowflake](https://docs.snowflake.com/en/sql-reference/snowflake-scripting/if)
+    IfThenElseEnd {
+        /// The `IF` token that starts the statement.
+        if_token: AttachedToken,
+        if_block: ConditionalStatements,
+        elseif_blocks: Vec<ConditionalStatements>,
+        else_block: Option<ConditionalStatements>,
+        /// The `IF` token that ends the statement.
+        end_if_token: AttachedToken,
+    },
+    /// An MSSQL `IF ... ELSE ...` statement.
+    ///
+    /// Example:
+    /// ```sql
+    /// IF 1=1 SELECT 1 ELSE SELECT 2
+    /// ```
+    ///
+    /// 
[MSSQL](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/if-else-transact-sql?view=sql-server-ver16)
+    MsSqlIfElse {

Review Comment:
   Thank you for your feedback. I pushed further changes to avoid the 
dialect-specific AST nodes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to