This topic describes how to update the configurations of a table by using Tablestore SDK for Python.
Method description
def update_table(self, table_name, table_options=None, reserved_throughput=None)
Parameters
table_name (required) str: the name of the data table.
table_options (optional) TableOptions: the configurations of the table, including the following parameters.
Parameter | Type | Description |
time_to_live (optional) | int | The time to live (TTL) of data, in seconds. The default value is -1. If you set this parameter to -1, the data never expires. Otherwise, the minimum value is 86400 (one day). Data whose retention period exceeds the TTL will be automatically deleted. If you want to use search index or secondary index features, you must set this parameter to -1 or set the AllowUpdate parameter to False. |
max_version (optional) | int | The maximum number of versions. The default value is 1. |
max_time_deviation (optional) | int | The maximum version offset, in seconds. The default value is 86400 (one day). The difference between the current system time and the timestamp of written data 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 written time - Maximum version offset, Data written time - TTL), Data written time + Maximum version offset).
|
allow_update (optional) | bool | Specifies whether to allow updates. The default value is True. |
reserved_throughput (optional) ReservedThroughput: reserved read and write throughput, in capacity unit (CU). The default value is 0. This parameter can be specified and take effect only for high-performance instances in CU mode.
Note When you call the update_table() method, you must specify at least one of the table_options or reserved_throughput parameters.
Sample code
The following sample code demonstrates how to modify the configurations of the test_table table.
# Construct the table configurations.
table_options = TableOptions(time_to_live=86400, max_version=3, max_time_deviation=86400, allow_update=False)
# Set the reserved read throughput to 0 CUs and the reserved write throughput to 0 CUs (only high-performance instances in CU mode allow you to specify non-zero values for reserved read and write throughput).
reserved_throughput = ReservedThroughput(CapacityUnit(0,0))
try:
# Initiate a request.
client.update_table('test_table', table_options, reserved_throughput)
print("Update table succeeded.")
except Exception as e:
print("Update table failed. %s" % e)