Skip to content

Commit

Permalink
fix: mismatch in column count and value count (#14417)
Browse files Browse the repository at this point in the history
Signed-off-by: Prakhar Gurunani <[email protected]>
  • Loading branch information
FirePing32 authored Nov 21, 2023
1 parent bdab2bf commit 4f08558
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/vt/vtgate/planbuilder/operators/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ func modifyForAutoinc(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, v
case sqlparser.Values:
autoIncValues := make(sqlparser.ValTuple, 0, len(rows))
for rowNum, row := range rows {
if len(ins.Columns) != len(row) {
return nil, vterrors.VT03006()
}
// Support the DEFAULT keyword by treating it as null
if _, ok := row[colNum].(*sqlparser.Default); ok {
row[colNum] = &sqlparser.NullVal{}
Expand Down
10 changes: 10 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/dml_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4889,5 +4889,15 @@
"comment": "Unsupported update statement with a replica target destination",
"query": "update `user[-]@replica`.user_metadata set id=2",
"plan": "VT09002: update statement with a replica target"
},
{
"comment": "insert row values smaller than number of columns",
"query": "insert into user(one, two, three, four) values (1, 2, 3)",
"plan": "VT03006: column count does not match value count at row 1"
},
{
"comment": "insert row values greater than number of columns",
"query": "insert into user(one, two, three) values (1, 2, 3, 4)",
"plan": "VT03006: column count does not match value count at row 1"
}
]

0 comments on commit 4f08558

Please sign in to comment.