Skip to content

Commit

Permalink
Only set last_insert_id value if at least one row was inserted/chan…
Browse files Browse the repository at this point in the history
…ged.

Signed-off-by: Arthur Schreiber <[email protected]>
  • Loading branch information
arthurschreiber committed Apr 11, 2024
1 parent 3ccff20 commit 0d8494a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion go/vt/vtgate/engine/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,16 @@ func (ins *Insert) executeInsertQueries(
return nil, vterrors.Aggregate(errs)
}

// If this insert used auto increment values from a sequence, we need to set the `last_insert_id` value.
if insertID != 0 {
result.InsertID = insertID
// If no rows were inserted or updated, clear the `last_insert_id` value.
if result.RowsAffected > 0 {
result.InsertID = insertID
} else {
result.InsertID = 0
}
}

return result, nil
}

Expand Down

0 comments on commit 0d8494a

Please sign in to comment.