diff --git a/utils/dataconvert/dataconvert.cpp b/utils/dataconvert/dataconvert.cpp index b53f42e74..7b25a33a7 100644 --- a/utils/dataconvert/dataconvert.cpp +++ b/utils/dataconvert/dataconvert.cpp @@ -2975,7 +2975,7 @@ void DataConvert::joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& u case datatypes::SystemCatalog::UBIGINT: case datatypes::SystemCatalog::UDECIMAL: - if (type.scale != 0) + if (type.scale != 0 && unionedType.scale != 0) { const unsigned int digitsBeforeDecimal = type.precision - type.scale; const unsigned int digitsBeforeDecimalUnion = unionedType.precision - unionedType.scale; @@ -2988,7 +2988,18 @@ void DataConvert::joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& u } } - unionedType.precision = std::max(type.precision, unionedType.precision); + // Handle the scenario where the upstream code assigns special values of 9999 + // and -1 as the precision of the unionedType. + if ((unionedType.precision == 9999 || unionedType.precision == -1) && + (type.precision != 9999 && type.precision != -1)) + { + unionedType.precision = type.precision; + } + else + { + unionedType.precision = std::max(type.precision, unionedType.precision); + } + unionedType.scale = std::max(type.scale, unionedType.scale); if (datatypes::Decimal::isWideDecimalTypeByPrecision(unionedType.precision)) @@ -3056,6 +3067,10 @@ void DataConvert::joinColTypeForUnion(datatypes::SystemCatalog::TypeHolderStd& u case datatypes::SystemCatalog::UFLOAT: case datatypes::SystemCatalog::UDOUBLE: case datatypes::SystemCatalog::LONGDOUBLE: + if (datatypes::isWideDecimalType(type.colDataType, type.colWidth)) + unionedType = type; + break; + default: break; }