Skip to content

Commit 555f31e

Browse files
elianddbclaude
andcommitted
Fix auto_increment logic to preserve explicit non-zero values
Restored original logic where sequence value is only used when given value is nil. This fixes last_insert_id(expr) behavior where explicit values should be preserved. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6ea3ed6 commit 555f31e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sql/expression/auto_increment.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ func (i *AutoIncrement) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)
128128
given = nil
129129
}
130130

131+
// Update integrator AUTO_INCREMENT sequence with our value
131132
seq, err := i.autoTbl.GetNextAutoIncrementValue(ctx, given)
132133
if err != nil {
133134
return nil, err
134135
}
135-
given = seq
136+
137+
// Use sequence value if NULL or 0 were provided
138+
if given == nil {
139+
given = seq
140+
}
136141

137142
ret, _, err := i.Type().Convert(ctx, given)
138143
if err != nil {

0 commit comments

Comments
 (0)