This topic describes how to update table configurations using Tablestore SDK for Go.
Prerequisites
Method description
func (tableStoreClient *TableStoreClient) UpdateTable(request *UpdateTableRequest) (*UpdateTableResponse, error)Note
When calling the
UpdateTable()method, set at least one of the TableOption, StreamSpec, or ReservedThroughput parameters.When setting TableOption, set the TimeToAlive and MaxVersion parameters.
Sample code
The following sample code is used to modify the configurations of the test_table table.
func UpdateTableSample(client *tablestore.TableStoreClient) {
updateTableReq := new(tablestore.UpdateTableRequest)
updateTableReq.TableName = "test_table"
// Table configuration information
updateTableReq.TableOption = new(tablestore.TableOption)
// Set the TTL in seconds
updateTableReq.TableOption.TimeToAlive = 86400
// Set the maximum number of versions
updateTableReq.TableOption.MaxVersion = 3
// Set the maximum version offset in seconds
updateTableReq.TableOption.DeviationCellVersionInSec = 86400
// Set whether updates are allowed
updateTableReq.TableOption.AllowUpdate = proto.Bool(false)
// Enable Stream and set the Stream expiration time to 7 days
updateTableReq.StreamSpec = new(tablestore.StreamSpecification)
updateTableReq.StreamSpec.EnableStream = true
updateTableReq.StreamSpec.ExpirationTime = 168
// Set the reserved read throughput to 0 CU and the reserved write throughput to 0 CU (only high-performance instances in CU mode support setting non-zero values for reserved read and write throughput)
updateTableReq.ReservedThroughput = new(tablestore.ReservedThroughput)
updateTableReq.ReservedThroughput.Readcap = 0
updateTableReq.ReservedThroughput.Writecap = 0
// Call the UpdateTable method to modify table configurations
_, err := client.UpdateTable(updateTableReq)
if (err != nil) {
fmt.Println("Failed to update table with error:", err)
} else {
fmt.Println("Update table finished.")
}
}