From 57bf63ca8a13668b9d7eec8a58ab8d057f5c08e9 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Mon, 17 Mar 2025 13:32:13 -0700 Subject: [PATCH] Bug fix: resolve column default expressions for ALTER COLUMN nodes --- sql/planbuilder/ddl.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sql/planbuilder/ddl.go b/sql/planbuilder/ddl.go index 1e3df39ede..285e1c819c 100644 --- a/sql/planbuilder/ddl.go +++ b/sql/planbuilder/ddl.go @@ -1065,7 +1065,11 @@ func (b *Builder) buildAlterAutoIncrement(inScope *scope, ddl *ast.DDL, table *p func (b *Builder) buildAlterNotNull(inScope *scope, ddl *ast.DDL, table *plan.ResolvedTable) (outScope *scope) { outScope = inScope spec := ddl.NotNullSpec - for _, c := range table.Schema() { + + // Resolve the schema defaults, so we don't leave around any UnresolvedColumnDefault expressions, + // otherwise Doltgres won't be able to process these nodes. + resolvedSchema := b.resolveSchemaDefaults(inScope, table.Schema()) + for _, c := range resolvedSchema { if strings.EqualFold(c.Name, spec.Column.String()) { colCopy := *c switch strings.ToLower(spec.Action) { @@ -1093,7 +1097,11 @@ func (b *Builder) buildAlterNotNull(inScope *scope, ddl *ast.DDL, table *plan.Re func (b *Builder) buildAlterChangeColumnType(inScope *scope, ddl *ast.DDL, table *plan.ResolvedTable) (outScope *scope) { outScope = inScope spec := ddl.ColumnTypeSpec - for _, c := range table.Schema() { + + // Resolve the schema defaults, so we don't leave around any UnresolvedColumnDefault expressions, + // otherwise Doltgres won't be able to process these nodes. + resolvedSchema := b.resolveSchemaDefaults(inScope, table.Schema()) + for _, c := range resolvedSchema { if strings.EqualFold(c.Name, spec.Column.String()) { colCopy := *c typ, err := types.ColumnTypeToType(&spec.Type)