Home  >  Article  >  Backend Development  >  How spanner.Mutation understands which row to update

How spanner.Mutation understands which row to update

PHPz
PHPzforward
2024-02-13 23:30:091219browse

spanner.Mutation 如何理解要更新哪一行

php editor Zimo is here to introduce to you how to understand which row to update spanner.Mutation. When using spanner.Mutation for data update, we need to specify the rows and columns to be updated. To update a specific row, you can use spanner.KeyRange to specify a range of rows. If you only need to update a single row, you can use spanner.KeyRange.withPrefix to specify the row prefix. Alternatively, spanner.KeySet can be used to specify the set of rows to be updated. Through these methods, we can clearly understand which row of data spanner.Mutation wants to update.

Question content

From the document:

65bed0b31ec07

spanner How to understand which row to update? I noticed it was missing the where clause. Does it automatically use certain fields as keys (e.g. implicit user_id = "...")?

Workaround

Cloud Spanner will automatically use the primary key of the table being updated by the mutation. This means you must include all columns of the primary key in the Update mutation. Therefore, an Update mutation will also update only one row (if the row does not exist, it will return a NOT_FOUND error).

This also means that the primary key value of the row cannot be updated. Conversely, if you want to "change" the primary key value, you have to delete the row and insert a new row.

See https://cloud.google. com/spanner/docs/reference/rpc/google.spanner.v1#mutation to learn more about how mutations work.

The above is the detailed content of How spanner.Mutation understands which row to update. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete