void resolveTypesForCaseWhen ( Session session ) { if ( dataType != null ) { return ; } Expression expr = this ; while ( expr . opType == OpTypes . CASEWHEN ) { expr . nodes [ LEFT ] . resolveTypes ( session , expr ) ; if ( expr . nodes [ LEFT ] . isParam ) { expr . nodes [ LEFT ] . dataType = Type . SQL_BOOLEAN ; } expr . nodes [ RIGHT ] . nodes [ LEFT ] . resolveTypes ( session , nodes [ RIGHT ] ) ; expr . nodes [ RIGHT ] . nodes [ RIGHT ] . resolveTypes ( session , nodes [ RIGHT ] ) ; expr = expr . nodes [ RIGHT ] . nodes [ RIGHT ] ; } expr = this ; while ( expr . opType == OpTypes . CASEWHEN ) { dataType = Type . getAggregateType ( expr . nodes [ RIGHT ] . nodes [ LEFT ] . dataType , dataType ) ; dataType = Type . getAggregateType ( expr . nodes [ RIGHT ] . nodes [ RIGHT ] . dataType , dataType ) ; expr = expr . nodes [ RIGHT ] . nodes [ RIGHT ] ; } expr = this ; while ( expr . opType == OpTypes . CASEWHEN ) { if ( expr . nodes [ RIGHT ] . nodes [ LEFT ] . dataType == null ) { expr . nodes [ RIGHT ] . nodes [ LEFT ] . dataType = dataType ; } if ( expr . nodes [ RIGHT ] . nodes [ RIGHT ] . dataType == null ) { expr . nodes [ RIGHT ] . nodes [ RIGHT ] . dataType = dataType ; } if ( expr . nodes [ RIGHT ] . dataType == null ) { expr . nodes [ RIGHT ] . dataType = dataType ; } expr = expr . nodes [ RIGHT ] . nodes [ RIGHT ] ; } if ( dataType == null ) { throw Error . error ( ErrorCode . X_42567 ) ; } }
For CASE WHEN and its special cases section 9 . 3 of the SQL standard on type aggregation is implemented .