Skip to content

Commit fa97159

Browse files
authored
Merge pull request #2895 from dolthub/fulghum/alter_column
Bug fix: resolve column default expressions for ALTER COLUMN nodes
2 parents f61a772 + 57bf63c commit fa97159

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sql/planbuilder/ddl.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,11 @@ func (b *Builder) buildAlterAutoIncrement(inScope *scope, ddl *ast.DDL, table *p
10651065
func (b *Builder) buildAlterNotNull(inScope *scope, ddl *ast.DDL, table *plan.ResolvedTable) (outScope *scope) {
10661066
outScope = inScope
10671067
spec := ddl.NotNullSpec
1068-
for _, c := range table.Schema() {
1068+
1069+
// Resolve the schema defaults, so we don't leave around any UnresolvedColumnDefault expressions,
1070+
// otherwise Doltgres won't be able to process these nodes.
1071+
resolvedSchema := b.resolveSchemaDefaults(inScope, table.Schema())
1072+
for _, c := range resolvedSchema {
10691073
if strings.EqualFold(c.Name, spec.Column.String()) {
10701074
colCopy := *c
10711075
switch strings.ToLower(spec.Action) {
@@ -1093,7 +1097,11 @@ func (b *Builder) buildAlterNotNull(inScope *scope, ddl *ast.DDL, table *plan.Re
10931097
func (b *Builder) buildAlterChangeColumnType(inScope *scope, ddl *ast.DDL, table *plan.ResolvedTable) (outScope *scope) {
10941098
outScope = inScope
10951099
spec := ddl.ColumnTypeSpec
1096-
for _, c := range table.Schema() {
1100+
1101+
// Resolve the schema defaults, so we don't leave around any UnresolvedColumnDefault expressions,
1102+
// otherwise Doltgres won't be able to process these nodes.
1103+
resolvedSchema := b.resolveSchemaDefaults(inScope, table.Schema())
1104+
for _, c := range resolvedSchema {
10971105
if strings.EqualFold(c.Name, spec.Column.String()) {
10981106
colCopy := *c
10991107
typ, err := types.ColumnTypeToType(&spec.Type)

0 commit comments

Comments
 (0)