Skip to content

Commit 16fabab

Browse files
elianddbclaude
andcommitted
Fix DEFAULT NULL issues in DDL and test expectations
- Remove overly broad DEFAULT NULL assignment in DDL schema creation - Update INSERT empty VALUES logic to properly handle nullable columns - Revert test expectations to not expect DEFAULT NULL for all nullable columns - Maintain original insert validation functionality for column count mismatches 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 786eab0 commit 16fabab

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

enginetest/queries/queries.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10462,28 +10462,28 @@ var KeylessQueries = []QueryTest{
1046210462
{
1046310463
Query: "DESCRIBE keyless",
1046410464
Expected: []sql.Row{
10465-
{"c0", "bigint", "YES", "", "NULL", ""},
10466-
{"c1", "bigint", "YES", "", "NULL", ""},
10465+
{"c0", "bigint", "YES", "", nil, ""},
10466+
{"c1", "bigint", "YES", "", nil, ""},
1046710467
},
1046810468
},
1046910469
{
1047010470
Query: "SHOW COLUMNS FROM keyless",
1047110471
Expected: []sql.Row{
10472-
{"c0", "bigint", "YES", "", "NULL", ""},
10473-
{"c1", "bigint", "YES", "", "NULL", ""},
10472+
{"c0", "bigint", "YES", "", nil, ""},
10473+
{"c1", "bigint", "YES", "", nil, ""},
1047410474
},
1047510475
},
1047610476
{
1047710477
Query: "SHOW FULL COLUMNS FROM keyless",
1047810478
Expected: []sql.Row{
10479-
{"c0", "bigint", nil, "YES", "", "NULL", "", "", ""},
10480-
{"c1", "bigint", nil, "YES", "", "NULL", "", "", ""},
10479+
{"c0", "bigint", nil, "YES", "", nil, "", "", ""},
10480+
{"c1", "bigint", nil, "YES", "", nil, "", "", ""},
1048110481
},
1048210482
},
1048310483
{
1048410484
Query: "SHOW CREATE TABLE keyless",
1048510485
Expected: []sql.Row{
10486-
{"keyless", "CREATE TABLE `keyless` (\n `c0` bigint DEFAULT NULL,\n `c1` bigint DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
10486+
{"keyless", "CREATE TABLE `keyless` (\n `c0` bigint,\n `c1` bigint\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
1048710487
},
1048810488
},
1048910489
}

sql/planbuilder/ddl.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,15 +1419,6 @@ func (b *Builder) tableSpecToSchema(inScope, outScope *scope, db sql.Database, t
14191419

14201420
for i, def := range defaults {
14211421
schema[i].Default = b.convertDefaultExpression(outScope, def, schema[i].Type, schema[i].Nullable)
1422-
if schema[i].Default == nil && schema[i].Nullable {
1423-
schema[i].Default = &sql.ColumnDefaultValue{
1424-
Expr: b.buildScalar(inScope, &ast.NullVal{}),
1425-
OutType: types.Null,
1426-
Literal: true,
1427-
ReturnNil: true,
1428-
Parenthesized: false,
1429-
}
1430-
}
14311422
err := validateDefaultExprs(schema[i])
14321423
if err != nil {
14331424
b.handleErr(err)

sql/planbuilder/dml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (b *Builder) buildInsert(inScope *scope, i *ast.Insert) (outScope *scope) {
9090
// insert default val for respective columns.
9191
ir.Values[valueIdx] = make([]ast.Expr, len(schema))
9292
for j, col := range schema {
93-
if col.Default == nil && !col.AutoIncrement {
93+
if col.Default == nil && !col.AutoIncrement && !col.Nullable {
9494
b.handleErr(sql.ErrInsertIntoNonNullableDefaultNullColumn.New(col.Name))
9595
}
9696

0 commit comments

Comments
 (0)