@@ -75,12 +75,24 @@ func (b *Builder) buildInsert(inScope *scope, i *ast.Insert) (outScope *scope) {
75
75
if len (columns ) == 0 && len (destScope .cols ) > 0 && rt != nil {
76
76
schema := rt .Schema ()
77
77
columns = make ([]string , len (schema ))
78
- for i , col := range schema {
78
+ for index , col := range schema {
79
79
// Tables with any generated column must always supply a column list, so this is always an error
80
80
if col .Generated != nil {
81
81
b .handleErr (sql .ErrGeneratedColumnValue .New (col .Name , rt .Name ()))
82
82
}
83
- columns [i ] = col .Name
83
+ columns [index ] = col .Name
84
+ }
85
+ if ir , ok := i .Rows .(* ast.AliasedValues ); ok && len (ir .Values [0 ]) == 0 {
86
+ // VALUES() clause is empty in conjunction with empty column list, so we need to
87
+ // insert default val for respective columns.
88
+ ir .Values [0 ] = make ([]ast.Expr , len (schema ))
89
+ for j , col := range schema {
90
+ if col .Default == nil {
91
+ b .handleErr (sql .ErrInsertIntoNonNullableDefaultNullColumn .New (col .Name ))
92
+ }
93
+
94
+ ir .Values [0 ][j ] = & ast.Default {}
95
+ }
84
96
}
85
97
}
86
98
}
@@ -214,8 +226,6 @@ func (b *Builder) buildInsertValues(inScope *scope, v *ast.AliasedValues, column
214
226
literalOnly = true
215
227
exprTuples := make ([][]sql.Expression , len (v .Values ))
216
228
for i , vt := range v .Values {
217
- // noExprs is an edge case where we fill VALUES with nil expressions
218
- //noExprs := len(vt) == 0
219
229
// triggerUnknownTable is an edge case where we ignored an unresolved
220
230
// table error and do not have a schema for resolving defaults
221
231
triggerUnknownTable := (len (columnNames ) == 0 && len (vt ) > 0 ) && (len (b .TriggerCtx ().UnresolvedTables ) > 0 )
0 commit comments