すべてのプロダクト
Search
ドキュメントセンター

Tablestore:単一行データの更新

最終更新日:Mar 10, 2026

PHP SDK を使用して、Tablestore テーブル内の属性列の値を更新したり、属性列を追加したり、属性列の特定のバージョンを削除したり、属性列全体を削除したりします。

事前準備

Tablestore クライアントの初期化

メソッド

public function updateRow(array $request)

$request のパラメータの説明

名前

説明

table_name (必須)

string

データテーブルの名前。

primary_key (必須)

array

プライマリキー列名と値を含むプライマリキー情報。

  • プライマリキー列のデータの型には、STRING、INTEGER、BINARY があります。

  • プライマリキーの数と型は、テーブルに定義されているものと一致する必要があります。

update_of_attribute_columns (必須)

array

更新する属性列とその操作タイプ。サポートされている操作タイプは、PUT (列値の追加または更新)、DELETE (特定のバージョンの削除)、DELETE_ALL (列全体の削除) です。

condition (必須)

array

更新条件。詳細については、「条件付き更新」をご参照ください。

return_content (オプション)

array

返されるデータ。

  • return_type (必須)array: 戻り値の型。

    • ReturnTypeConst::CONST_NONE (デフォルト): データは返されません。

    • ReturnTypeConst::CONST_PK: プライマリキー列を返します。

    • ReturnTypeConst::CONST_AFTER_MODIFY: 変更後の列の値を返します。このオプションは、「アトミックカウンター」に使用します。

transaction_id (オプション)

string

ローカルトランザクション ID。この ID は、ローカルトランザクションを一意に識別します。詳細については、「ローカルトランザクション」をご参照ください。

次の例では、test_table テーブル内のプライマリキー値 row1 を持つ行を更新します。属性列 col1changed_val1 に設定されます。

$request = array(
    'table_name' => 'test_table',
    // Build the primary key
    'primary_key' => array(
        array('id', 'row1')
    ),
    // Specify the update condition when updating a row.
    // RowExistenceExpectationConst::CONST_IGNORE means skip row existence checking.
    'condition' => RowExistenceExpectationConst::CONST_IGNORE
);
// Attribute columns to update
$request['update_of_attribute_columns'] = array(
    'PUT' => array(
        array('col1', 'changed_val1')
    )
);

try {
    // Call the updateRow method to update the row
    $response = $client->updateRow($request);
    echo "* Read CU Cost: " . $response['consumed']['capacity_unit']['read'] . "\n";
    echo "* Write CU Cost: " . $response['consumed']['capacity_unit']['write'] . "\n";   
} catch (Exception $e) {
    echo "Update Row failed.";
}

他の行の更新操作を実行するには、次のコードスニペットを使用します。

  • 属性列の追加。

    $request['update_of_attribute_columns'] = array(
        'PUT' => array(
            array('col2', 'val2')
        )
    );
  • 属性列のバージョン番号の設定。

    $request['update_of_attribute_columns'] = array(
        'PUT' => array(
            array('col2', 'val2', null, intval(microtime(true) * 1000))
        )
    );
  • 属性列の特定のバージョンの削除。

    $request['update_of_attribute_columns'] = array(
        'DELETE' => array(
            array('col2', 1754285998447)
        )
    );
  • 属性列内のすべてのデータの削除。

    $request['update_of_attribute_columns'] = array(
        'DELETE_ALL' => array('col2')
    );

参考文献

データを一括更新