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.
From the document:
65bed0b31ec07spanner 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 = "..."
)?
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!