Skip to content

Commit 24a5014

Browse files
elianddbclaude
andcommitted
Fix CREATE TABLE AS SELECT to add implicit DEFAULT NULL
- Added logic to add DEFAULT NULL for nullable columns in CREATE TABLE AS SELECT - This ensures SHOW CREATE TABLE output matches MySQL behavior for computed columns - Fixed 3 CREATE TABLE test failures - Reduced FAIL count from 674 to 673 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 31f88b9 commit 24a5014

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

sql/planbuilder/ddl.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,20 @@ func (b *Builder) buildCreateTable(inScope *scope, c *ast.DDL) (outScope *scope)
317317
if c.TableSpec == nil && c.OptSelect != nil {
318318
selectScope := b.buildSelectStmt(inScope, c.OptSelect.Select)
319319
sch := b.resolveSchemaDefaults(outScope, selectScope.node.Schema())
320+
321+
// Add implicit DEFAULT NULL for nullable columns to match MySQL behavior
322+
for _, col := range sch {
323+
if col.Default == nil && col.Nullable {
324+
col.Default = &sql.ColumnDefaultValue{
325+
Expr: expression.NewLiteral(nil, types.Null),
326+
OutType: types.Null,
327+
Literal: true,
328+
ReturnNil: true,
329+
Parenthesized: false,
330+
}
331+
}
332+
}
333+
320334
tableSpec := &plan.TableSpec{
321335
Schema: sql.NewPrimaryKeySchema(sch),
322336
}

0 commit comments

Comments
 (0)