使用 Python SDK 更新資料表的資料生命週期、版本、更新方式和預留讀寫輸送量。
前提條件
安裝Tablestore Python SDK並初始化用戶端。
功能說明
調用 update_table 方法更新表配置。table_options 和 reserved_throughput 至少設定一項。
def update_table(
self,
table_name,
table_options=None,
reserved_throughput=None,
)
以下樣本將 example_table 的資料生命週期更新為 7 天,並禁止通過 update_row 方法更新資料。
table_options = TableOptions(
time_to_live=604800,
max_version=1,
max_time_deviation=86400,
allow_update=False,
)
client.update_table(
"example_table",
table_options=table_options,
)
參數說明
update_table 方法包含以下參數。
|
名稱 |
類型 |
說明 |
|
table_name(必選) |
|
資料表名稱。 |
|
table_options(可選) |
|
待更新的表配置。與 |
|
reserved_throughput(可選) |
|
待更新的預留讀寫輸送量。與 |
表配置
table_options 的類型為 TableOptions,包含以下參數。
|
名稱 |
類型 |
說明 |
|
time_to_live(可選) |
|
資料生命週期,單位為秒。設定為 |
|
max_version(可選) |
|
每個屬性列最多保留的版本數。使用多元索引或二級索引時,必須設定為 |
|
max_time_deviation(可選) |
|
有效版本偏差,單位為秒。寫入資料的時間戳記與系統目前時間的差值必須在有效版本偏差範圍內。屬性列資料的有效版本範圍為 |
|
allow_update(可選) |
|
是否允許通過 |
預留讀寫輸送量
reserved_throughput 的類型為 ReservedThroughput,包含以下參數。
|
名稱 |
類型 |
說明 |
|
capacity_unit(必選) |
|
預留讀寫輸送量,單位為 CU。僅 CU 模式的高效能型執行個體支援設定非零值。 |
傳回值
UpdateTableResponse 包含以下商務資訊。
|
欄位 |
類型 |
說明 |
|
table_options |
|
更新後的表配置。 |
|
reserved_throughput_details |
|
當前預留讀寫輸送量,以及最近一次上調和下調的時間。 |
情境樣本
更新預留讀寫輸送量
以下樣本將 example_table 的預留讀寫輸送量設定為 0 CU。
reserved_throughput = ReservedThroughput(
CapacityUnit(read=0, write=0)
)
client.update_table(
"example_table",
reserved_throughput=reserved_throughput,
)