@@ -2800,17 +2800,33 @@ static void ValidateAlterColumnTypeTarget(const LogicalType &type) {
28002800static bool IsImplicitCastUsingExpression (const ParsedExpression &expr,
28012801 const string &column_name,
28022802 const LogicalType &target_type) {
2803- auto *cast_expr = dynamic_cast <const CastExpression *>(&expr);
2804- if (!cast_expr || cast_expr->try_cast ||
2805- cast_expr->cast_type != target_type) {
2803+ if (expr.GetExpressionClass () != ExpressionClass::CAST) {
28062804 return false ;
28072805 }
2808- auto *col_ref =
2809- dynamic_cast <const ColumnRefExpression *>(cast_expr->child .get ());
2810- if (!col_ref || col_ref->column_names .size () != 1 ) {
2806+ auto &cast_expr = expr.Cast <CastExpression>();
2807+ if (cast_expr.try_cast ) {
28112808 return false ;
28122809 }
2813- return StringUtil::CIEquals (col_ref->column_names [0 ], column_name);
2810+
2811+ LogicalType expression_cast_type;
2812+ try {
2813+ expression_cast_type = UnboundType::TryDefaultBind (cast_expr.cast_type );
2814+ } catch (...) {
2815+ return false ;
2816+ }
2817+ if (expression_cast_type != target_type) {
2818+ return false ;
2819+ }
2820+ if (!cast_expr.child ||
2821+ cast_expr.child ->GetExpressionClass () != ExpressionClass::COLUMN_REF) {
2822+ return false ;
2823+ }
2824+ auto &col_ref = cast_expr.child ->Cast <ColumnRefExpression>();
2825+ if (col_ref.column_names .empty ()) {
2826+ return false ;
2827+ }
2828+ // Accept qualified references and match the leaf name against target column.
2829+ return StringUtil::CIEquals (col_ref.column_names .back (), column_name);
28142830}
28152831
28162832unique_ptr<CatalogEntry>
0 commit comments