全部產品
Search
文件中心

Tablestore:更新表配置

更新時間:Jun 26, 2025

本文介紹如何通過 Python SDK 更新表的配置資訊。

前提條件

初始化Tablestore Client

方法說明

def update_table(self, table_name, table_options=None, reserved_throughput=None)

參數說明

  • table_name(必選)str:資料表名稱。

  • table_options(可選)TableOptions:表配置資訊,包含以下參數。

    名稱

    類型

    說明

    time_to_live(可選)

    int

    資料生命週期,單位為秒,預設值為-1。

    設定為-1時表示資料永不到期,否則取值最低為86400(1天),超出生命週期的資料將會被自動清除。

    如果要使用多元索引或二級索引功能,必須將資料生命週期設定為-1,或者將AllowUpdate參數設定為False。

    max_version(可選)

    int

    最大版本數,預設值為1。

    • 如果要使用多元索引或二級索引,最大版本數必須設定為1。

    max_time_deviation(可選)

    int

    有效版本偏差,單位為秒,預設值為86400(1天)。

    • 寫入資料的時間戳記與系統目前時間的差值必須在有效版本偏差範圍內,否則寫入資料將會失敗。

    • 屬性列資料的有效版本範圍為[max(資料寫入時間-有效版本偏差, 資料寫入時間-資料生命週期), 資料寫入時間+有效版本偏差)

    allow_update(可選)

    bool

    是否允許更新,預設值為True。

    • 設定為False時,無法通過UpdateRow()方法更新資料。

  • reserved_throughput(可選)ReservedThroughput預留讀寫輸送量,單位為CU,預設值為0,僅CU模式的高效能型執行個體可以設定且有效。

說明

調用update_table()方法時,必須設定table_options和reserved_throughput中的至少一項。

範例程式碼

以下範例程式碼用於修改test_table表的配置資訊。

# 構造資料表的配置資訊
table_options = TableOptions(time_to_live=86400, max_version=3, max_time_deviation=86400, allow_update=False)

# 設定預留讀為0CU,預留寫為0CU(僅CU模式高效能執行個體支援設定資料表的預留讀寫輸送量為非零值)
reserved_throughput = ReservedThroughput(CapacityUnit(0,0))

try:
    # 發起請求
    client.update_table('test_table', table_options, reserved_throughput)
    print("Update table succeeded.")
except Exception as e:
    print("Update table failed. %s" % e)

相關文檔

更新時序表配置