diff --git a/data/test/vtgate/dml_cases.txt b/data/test/vtgate/dml_cases.txt index 40a9c69a542..fc06a5f3558 100644 --- a/data/test/vtgate/dml_cases.txt +++ b/data/test/vtgate/dml_cases.txt @@ -1512,3 +1512,24 @@ "Query": "delete from unsharded where col = (select id from unsharded_a where id = unsharded.col)" } } + +# update vindex value to null +"update user set name = null where id = 1" +{ + "Original": "update user set name = null where id = 1", + "Instructions": { + "Opcode": "UpdateEqual", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "Query": "update user set name = null where id = 1", + "Vindex": "user_index", + "Values": [1], + "ChangedVindexValues": { + "name_user_map": [null] + }, + "Table": "user", + "OwnedVindexQuery": "select Name, Costly from user where id = 1 for update" + } +} diff --git a/go/vt/vtgate/planbuilder/update.go b/go/vt/vtgate/planbuilder/update.go index bbc870a176b..33c4a366d4b 100644 --- a/go/vt/vtgate/planbuilder/update.go +++ b/go/vt/vtgate/planbuilder/update.go @@ -172,7 +172,7 @@ func generateUpdateSubquery(upd *sqlparser.Update, table *vindexes.Table) string // it's holding. At the moment it only supports: StrVal, HexVal, IntVal, ValArg. // If a complex expression is provided (e.g set name = name + 1), the update will be rejected. func extractValueFromUpdate(upd *sqlparser.UpdateExpr) (pv sqltypes.PlanValue, err error) { - if !sqlparser.IsValue(upd.Expr) { + if !sqlparser.IsValue(upd.Expr) && !sqlparser.IsNull(upd.Expr) { err := vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "unsupported: Only values are supported. Invalid update on column: %v", upd.Name.Name) return sqltypes.PlanValue{}, err }