Skip to content

Commit 4f08558

Browse files
authored
fix: mismatch in column count and value count (#14417)
Signed-off-by: Prakhar Gurunani <[email protected]>
1 parent bdab2bf commit 4f08558

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

go/vt/vtgate/planbuilder/operators/insert.go

+3
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ func modifyForAutoinc(ctx *plancontext.PlanningContext, ins *sqlparser.Insert, v
641641
case sqlparser.Values:
642642
autoIncValues := make(sqlparser.ValTuple, 0, len(rows))
643643
for rowNum, row := range rows {
644+
if len(ins.Columns) != len(row) {
645+
return nil, vterrors.VT03006()
646+
}
644647
// Support the DEFAULT keyword by treating it as null
645648
if _, ok := row[colNum].(*sqlparser.Default); ok {
646649
row[colNum] = &sqlparser.NullVal{}

go/vt/vtgate/planbuilder/testdata/dml_cases.json

+10
Original file line numberDiff line numberDiff line change
@@ -4889,5 +4889,15 @@
48894889
"comment": "Unsupported update statement with a replica target destination",
48904890
"query": "update `user[-]@replica`.user_metadata set id=2",
48914891
"plan": "VT09002: update statement with a replica target"
4892+
},
4893+
{
4894+
"comment": "insert row values smaller than number of columns",
4895+
"query": "insert into user(one, two, three, four) values (1, 2, 3)",
4896+
"plan": "VT03006: column count does not match value count at row 1"
4897+
},
4898+
{
4899+
"comment": "insert row values greater than number of columns",
4900+
"query": "insert into user(one, two, three) values (1, 2, 3, 4)",
4901+
"plan": "VT03006: column count does not match value count at row 1"
48924902
}
48934903
]

0 commit comments

Comments
 (0)