All Products
Search
Document Center

Tablestore:Update a table configuration

Last Updated:Apr 01, 2026

This topic describes how to update table configurations using Tablestore SDK for Go.

Prerequisites

Initialize a Tablestore Client

Method description

func (tableStoreClient *TableStoreClient) UpdateTable(request *UpdateTableRequest) (*UpdateTableResponse, error)

UpdateTableRequest parameters

  • TableName (required) string: The name of the data table.

  • TableOption (optional) *TableOption: The table configuration information, which includes the following parameters.

    Parameter

    Type

    Description

    TimeToAlive (required)

    int

    The time to live (TTL) of data in the time series table. Unit: seconds.

    • If you set the value to -1, the data never expires. The minimum value is 86400 (1 day). Data that exceeds the TTL will be automatically purged.

    • To use search index or secondary index features, set the TTL to -1 or set the AllowUpdate parameter to false.

    MaxVersion (required)

    int

    The maximum number of versions.

    • To use search index or secondary index features, set the maximum number of versions to 1.

    DeviationCellVersionInSec (optional)

    int64

    The maximum version offset. Unit: seconds.

    • The difference between the timestamp of written data and the current system time must be within the maximum version offset range. Otherwise, the data write will fail.

    • The valid version range for attribute column data is [max(data write time - valid version offset, data write time - TTL), data write time + valid version offset).

    AllowUpdate (optional)

    *bool

    Specifies whether updates are allowed.

    • If you set the value to false, you cannot update data using the UpdateRow() method.

  • StreamSpec (optional) *StreamSpecification: The Stream configuration information, which includes the following parameters.

    Parameter

    Type

    Description

    EnableStream (required)

    bool

    Specifies whether to enable Stream. Default value: false.

    Important

    If EnableStream is set to true, you must also set ExpirationTime.

    ExpirationTime (optional)

    int32

    The expiration time of the Stream, which indicates the expiration duration of incremental logs. Unit: hours. Maximum value: 168 (7 days).

    Important

    When you modify the ExpirationTime parameter, you must also set EnableStream to true. Otherwise, the existing data channel becomes unavailable and affects data synchronization for the table's search index.

  • ReservedThroughput (optional) *ReservedThroughput: Reserved read and write throughput, in CU. Default value: 0. Only high-performance instances in CU mode can be set to non-zero values.

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.
    updateTableReq.TableOption = new(tablestore.TableOption)
    // Set the time to live (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
    // Specify whether to allow data updates.
    updateTableReq.TableOption.AllowUpdate = proto.Bool(false)

    // Enable Stream and set the Stream expiration time to 7 days.
    // When you modify the ExpirationTime parameter, you must also set EnableStream to true.
    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. 
    // Non-zero throughput is applicable only to high-performance instances in CU mode.
    updateTableReq.ReservedThroughput = new(tablestore.ReservedThroughput)
    updateTableReq.ReservedThroughput.Readcap = 0
    updateTableReq.ReservedThroughput.Writecap = 0

    // Call the UpdateTable method to update the table configuration.
    _, err := client.UpdateTable(updateTableReq)
    if (err != nil) {
        fmt.Println("Failed to update table with error:", err)
    } else {
        fmt.Println("Update table finished.")
    }
}

References

Update a time series table