Skip to content

Commit 31f88b9

Browse files
elianddbclaude
andcommitted
Fix generated column INSERT validation logic
- Moved generated column validation to only apply to empty VALUES() tuples - Allows INSERT INTO table VALUES (value, DEFAULT) for generated columns - Fixed TestGeneratedColumns by allowing explicit DEFAULT values - This was preventing valid INSERT statements with DEFAULT for generated columns - Reduced FAIL count from 681 to 674 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6f293c0 commit 31f88b9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sql/planbuilder/dml.go

Lines changed: 4 additions & 4 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,6 +86,10 @@ 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 {
89+
// Tables with generated columns cannot use empty VALUES() tuples
90+
if col.Generated != nil {
91+
b.handleErr(sql.ErrGeneratedColumnValue.New(col.Name, rt.Name()))
92+
}
9393
if col.Default == nil && !col.AutoIncrement && !col.Nullable {
9494
b.handleErr(sql.ErrInsertIntoNonNullableDefaultNullColumn.New(col.Name))
9595
}

0 commit comments

Comments
 (0)