diff --git a/pkg/sql/logictest/testdata/logic_test/enums b/pkg/sql/logictest/testdata/logic_test/enums index 05c10f1ac1d8..65e47e85c7ec 100644 --- a/pkg/sql/logictest/testdata/logic_test/enums +++ b/pkg/sql/logictest/testdata/logic_test/enums @@ -1090,7 +1090,7 @@ statement ok CREATE TABLE enum_data_type (x STRING); INSERT INTO enum_data_type VALUES ('notagreeting') -statement error pq: invalid input value for enum greeting: "notagreeting" +statement error pq: .*invalid input value for enum greeting: "notagreeting" ALTER TABLE enum_data_type ALTER COLUMN x SET DATA TYPE greeting USING x::greeting statement ok diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_type.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_type.go index 0bed230067e5..23b24519d040 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_type.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_type.go @@ -284,14 +284,6 @@ func handleGeneralColumnConversion( "old active version; ALTER COLUMN TYPE requires backfill. Reverting to legacy handling")) } - // TODO(#132936): Not yet supported in the DSC. Throwing an error to trigger - // fallback to legacy. - if newColType.Type.Family() == types.EnumFamily { - panic(scerrors.NotImplementedErrorf(t, - "backfilling during ALTER COLUMN TYPE for an enum column "+ - "type is not supported")) - } - // Generate the ID of the new column we are adding. newColID := b.NextTableColumnID(tbl) newColType.ColumnID = newColID @@ -447,7 +439,7 @@ func getComputeExpressionForBackfill( return } - _, _, _, err = schemaexpr.DequalifyAndValidateExprImpl(b, expr, newColType.Type, + typedExpr, _, _, err := schemaexpr.DequalifyAndValidateExprImpl(b, expr, newColType.Type, tree.AlterColumnTypeUsingExpr, b.SemaCtx(), volatility.Volatile, tn, b.ClusterSettings().Version.ActiveVersion(b), func() colinfo.ResultColumns { return getNonDropResultColumns(b, tableID) @@ -456,6 +448,14 @@ func getComputeExpressionForBackfill( return columnLookupFn(b, tableID, columnName) }, ) + if err != nil { + return + } + + // Return the updated expression from DequalifyAndValidateExprImpl. For expressions + // involving user-defined types like enums, the types will be resolved to ensure + // they can be used during backfill. + expr, err = parser.ParseExpr(typedExpr) return }