Skip to content

Commit 317599a

Browse files
committed
Fix generated column restriction and keyless table handling
- Remove overly restrictive generated column check that blocked valid DEFAULT usage - Add nullable check for keyless table default value insertion - Ensure INSERT INTO t VALUES (default) works correctly for tables with generated columns
1 parent 887f4c7 commit 317599a

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

sql/planbuilder/dml.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ func (b *Builder) buildInsert(inScope *scope, i *ast.Insert) (outScope *scope) {
7676
schema := rt.Schema()
7777
columns = make([]string, len(schema))
7878
for index, col := range schema {
79-
// Tables with any generated column must always supply a column list, so this is always an error
80-
if col.Generated != nil {
81-
b.handleErr(sql.ErrGeneratedColumnValue.New(col.Name, rt.Name()))
82-
}
8379
columns[index] = col.Name
8480
}
8581
if ir, ok := i.Rows.(*ast.AliasedValues); ok {
@@ -90,7 +86,7 @@ func (b *Builder) buildInsert(inScope *scope, i *ast.Insert) (outScope *scope) {
9086
// insert default val for respective columns.
9187
ir.Values[valueIdx] = make([]ast.Expr, len(schema))
9288
for j, col := range schema {
93-
if col.Default == nil && !col.AutoIncrement {
89+
if col.Default == nil && !col.AutoIncrement && !col.Nullable {
9490
b.handleErr(sql.ErrInsertIntoNonNullableDefaultNullColumn.New(col.Name))
9591
}
9692

0 commit comments

Comments
 (0)