360643 {
360644 LogicalType res;
360645 bool is_equality;
360646 switch (comparison_type) {
360647 case ExpressionType::COMPARE_EQUAL:
360648 case ExpressionType::COMPARE_NOTEQUAL:
360649 case ExpressionType::COMPARE_IN:
360650 case ExpressionType::COMPARE_NOT_IN:
360651 case ExpressionType::COMPARE_DISTINCT_FROM:
360652 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
360653 is_equality = true;
360654 break;
360655 default:
360656 is_equality = false;
360657 break;
360658 }
360659 if (is_equality) {
360661 } else {
360662 if (!LogicalType::TryGetMaxLogicalType(context, left_type, right_type, res)) {
360663 return false;
360664 }
360665 }
360666 switch (res.id()) {
360667 case LogicalTypeId::DECIMAL: {
360668
360669 vector<LogicalType> argument_types = {left_type, right_type};
360670 uint8_t max_width = 0, max_scale = 0, max_width_over_scale = 0;
360671 for (
idx_t i = 0; i < argument_types.size(); i++) {
360673 auto can_convert = argument_types[i].GetDecimalProperties(width, scale);
360674 if (!can_convert) {
360675 result_type = res;
360676 return true;
360677 }
360678 max_width = MaxValue<uint8_t>(width, max_width);
360679 max_scale = MaxValue<uint8_t>(scale, max_scale);
360680 max_width_over_scale = MaxValue<uint8_t>(width - scale, max_width_over_scale);
360681 }
360682 max_width = MaxValue<uint8_t>(max_scale + max_width_over_scale, max_width);
360683 if (max_width > Decimal::MAX_WIDTH_DECIMAL) {
360684
360685 max_width = Decimal::MAX_WIDTH_DECIMAL;
360686 }
360687 res = LogicalType::DECIMAL(max_width, max_scale);
360688 break;
360689 }
360690 case LogicalTypeId::VARCHAR:
360691
360692 if (left_type.id() != LogicalTypeId::VARCHAR && SwitchVarcharComparison(left_type)) {
360694 } else if (right_type.id() != LogicalTypeId::VARCHAR && SwitchVarcharComparison(right_type)) {
360696 } else {
360697
360698 auto left_collation = StringType::GetCollation(left_type);
360699 auto right_collation = StringType::GetCollation(right_type);
360700 if (!left_collation.empty() && !right_collation.empty() && left_collation != right_collation) {
360701 throw BinderException("Cannot combine types with different collation!");
360702 }
360703 }
360704 break;
360705 default:
360706 break;
360707 }
360708 result_type = res;
360709 return true;
360710}
void scale(cv::Mat &mat, const cv::Mat &range, const T min, const T max)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API LogicalType ForceMaxLogicalType(const LogicalType &left, const LogicalType &right)
Forcibly returns a maximum logical type - similar to MaxLogicalType but never throws....
Definition duckdb.cpp:140319
static DUCKDB_API LogicalType NormalizeType(const LogicalType &type)
Normalize a type - removing literals.
Definition duckdb.cpp:139907