@@ -574,6 +574,31 @@ func outputColumns(c core.Catalog, node nodes.Node) ([]core.Column, error) {
574
574
cols = append (cols , core.Column {Name : name , DataType : "any" , NotNull : false })
575
575
}
576
576
577
+ case nodes.CaseExpr :
578
+ name := ""
579
+ if res .Name != nil {
580
+ name = * res .Name
581
+ }
582
+ // TODO: The TypeCase code has been copied from below. Instead, we need a recurse function to get the type of a node.
583
+ if tc , ok := n .Defresult .(nodes.TypeCast ); ok {
584
+ if tc .TypeName == nil {
585
+ return nil , errors .New ("no type name type cast" )
586
+ }
587
+ name := ""
588
+ if ref , ok := tc .Arg .(nodes.ColumnRef ); ok {
589
+ name = join (ref .Fields , "_" )
590
+ }
591
+ if res .Name != nil {
592
+ name = * res .Name
593
+ }
594
+ // TODO Validate column names
595
+ col := catalog .ToColumn (tc .TypeName )
596
+ col .Name = name
597
+ cols = append (cols , col )
598
+ } else {
599
+ cols = append (cols , core.Column {Name : name , DataType : "any" , NotNull : false })
600
+ }
601
+
577
602
case nodes.CoalesceExpr :
578
603
for _ , arg := range n .Args .Items {
579
604
if ref , ok := arg .(nodes.ColumnRef ); ok {
@@ -652,6 +677,14 @@ func outputColumns(c core.Catalog, node nodes.Node) ([]core.Column, error) {
652
677
col := catalog .ToColumn (n .TypeName )
653
678
col .Name = name
654
679
cols = append (cols , col )
680
+
681
+ default :
682
+ name := ""
683
+ if res .Name != nil {
684
+ name = * res .Name
685
+ }
686
+ cols = append (cols , core.Column {Name : name , DataType : "any" , NotNull : false })
687
+
655
688
}
656
689
}
657
690
return cols , nil
0 commit comments