更新表配置

更新時間:
Copy as MD

通過 Python SDK調用 update_table() 方法,更新資料表的生命週期、最大版本數、有效版本偏差和預留讀寫輸送量等配置。

前提條件

已初始化 Client。詳情請參見初始化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,或將 allow_update 設定為 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 表的配置資訊。

# 配置表參數:生命週期 1 天、最大版本數 3、有效版本偏差 1 天、禁止更新
table_options = TableOptions(time_to_live=86400, max_version=3, max_time_deviation=86400, allow_update=False)

# 設定預留讀寫輸送量為 0 CU(僅 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)

相關文檔

更新時序表配置