@@ -40,7 +40,10 @@ use serde::{Deserialize, Serialize};
4040#[ cfg( feature = "visitor" ) ]
4141use sqlparser_derive:: { Visit , VisitMut } ;
4242
43- use crate :: tokenizer:: { Span , Token } ;
43+ use crate :: {
44+ display_utils:: SpaceOrNewline ,
45+ tokenizer:: { Span , Token } ,
46+ } ;
4447use crate :: {
4548 display_utils:: { Indent , NewLine } ,
4649 keywords:: Keyword ,
@@ -631,7 +634,12 @@ pub struct CaseWhen {
631634
632635impl fmt:: Display for CaseWhen {
633636 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
634- write ! ( f, "WHEN {} THEN {}" , self . condition, self . result)
637+ f. write_str ( "WHEN " ) ?;
638+ self . condition . fmt ( f) ?;
639+ f. write_str ( " THEN" ) ?;
640+ SpaceOrNewline . fmt ( f) ?;
641+ Indent ( & self . result ) . fmt ( f) ?;
642+ Ok ( ( ) )
635643 }
636644}
637645
@@ -1671,17 +1679,23 @@ impl fmt::Display for Expr {
16711679 conditions,
16721680 else_result,
16731681 } => {
1674- write ! ( f , "CASE" ) ?;
1682+ f . write_str ( "CASE" ) ?;
16751683 if let Some ( operand) = operand {
1676- write ! ( f, " {operand}" ) ?;
1684+ f. write_str ( " " ) ?;
1685+ operand. fmt ( f) ?;
16771686 }
16781687 for when in conditions {
1679- write ! ( f, " {when}" ) ?;
1688+ SpaceOrNewline . fmt ( f) ?;
1689+ Indent ( when) . fmt ( f) ?;
16801690 }
16811691 if let Some ( else_result) = else_result {
1682- write ! ( f, " ELSE {else_result}" ) ?;
1692+ SpaceOrNewline . fmt ( f) ?;
1693+ Indent ( "ELSE" ) . fmt ( f) ?;
1694+ SpaceOrNewline . fmt ( f) ?;
1695+ Indent ( Indent ( else_result) ) . fmt ( f) ?;
16831696 }
1684- write ! ( f, " END" )
1697+ SpaceOrNewline . fmt ( f) ?;
1698+ f. write_str ( "END" )
16851699 }
16861700 Expr :: Exists { subquery, negated } => write ! (
16871701 f,
0 commit comments