The Tablestore SDK provides the PutRow, GetRow, UpdateRow, and DeleteRow operations for single-row operations.

PutRow

PutRow

You can call this operation to insert a row of data. If the row does not exist, this operation inserts a row. If the row exists, this operation overwrites it. In other words, all columns and column values of all versions of the existing row are deleted.

When performing PutRow, you can use conditional update to set conditions for the existence of the row to write or values in certain columns of the existing row. For more information, see Conditional update.

Operation
    /**
     * Write a row of data. If the row already exists, the data of the row is overwritten. The number of the consumed capacity units (CUs) is returned.
     * @api
     * @param [] $request Request parameters.
     * @return [] Response.
     * @throws OTSClientException The exception that occurs when a parameter error occurs or the Tablestore server returns a verification error.
     * @throws OTSServerException The exception that occurs when the Tablestore server returns an error.
     */
    public function putRow(array $request); 
			
Sample requests
$result = $client->putRow([
    'table_name' => '<string>', // REQUIRED
    'condition' => [
        'row_existence' => <RowExistence>,   
        'column_condition' => <ColumnCondition>
    ],
    'primary_key' => [                              // REQUIRED
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ],  
    'attribute_columns' => [         // REQUIRED
            ['<string>', <ColumnValue>], 
            ['<string>', <ColumnValue>, <ColumnType>],
            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
    ],
    'return_content' => [
        'return_type' => <ReturnType>
    ]
]);         
Code analysis
  • table_name: required. This parameter specifies the name of the table.
  • condition: the row existence condition and column condition. For more information, see Conditional update.
    • row_existence: the row existence condition.
    • column_condition: the column condition.
  • primary_key: required. This parameter specifies the list of primary key columns.
    • The primary key of a table can contain one to four primary key columns. Primary key columns are sorted based on the order they are added. For example, primary key schema PRIMARY KEY (A, B, C) is different from PRIMARY KEY (A, C, B). Tablestore sorts rows based on the values of all primary key columns.
    • Each item in primary_keys specifies the values in the following sequence: the primary key name, primary key value (PrimaryKeyValue), and primary key value type (PrimaryKeyType, which is optional).
    • The value of PrimaryKeyValue can be an integer or a string. This parameter can be set to null for an auto-increment primary key column.
    • PrimaryKeyType can be set to PrimaryKeyTypeConst::CONST_INTEGER, PrimaryKeyTypeConst::CONST_STRING (UTF-8 encoded string), PrimaryKeyTypeConst::CONST_BINARY, or PrimaryKeyTypeConst::CONST_PK_AUTO_INCR. For more information about PK_AUTO_INCR, see auto-increment primary key columns. If the type of data to query is INTEGER or STRING, this parameter can be ignored. Otherwise, the type must be specified.
  • attribute_columns: required. This parameter specifies the list of attribute columns.
    • Each item specifies the values in the following sequence: the attribute column name, attribute column value (ColumnValue), attribute column value type (ColumnType, which is optional), and timestamp (optional).
    • ColumnType can be set to ColumnTypeConst::CONST_INTEGER, ColumnTypeConst::CONST_STRING (UTF-8 encoded string), ColumnTypeConst::CONST_BINARY, ColumnTypeConst::CONST_BOOLEAN, or ColumnTypeConst::CONST_DOUBLE. If the type of data to query is BINARY, the type must be specified. Otherwise, the type can be ignored or set to null.
    • The timestamp is a 64-bit integer that indicates the version of an attribute column. This parameter is optional. If this parameter is not specified, the server time is used.
  • return_content: the content to return.

    return_type: Only this parameter is available for return_content.

    ReturnTypeConst::CONST_PK: returns the value of the auto-increment primary key column.

Responses
[
    'consumed' => [
        'capacity_unit' => [
            'read' => <integer>,
            'write' => <integer>
        ]
    ],
    'primary_key' => [ 
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ],  
    'attribute_columns' => []
]        
Code analysis
  • consumed: the number of CUs consumed by this operation.
    capacity_unit: the number of read and write CUs consumed.
    • read: the number of read CUs consumed.
    • write: the number of write CUs consumed.
  • primary_key: the primary key value, which is consistent with that in the request. If you set ReturnTypeConst::CONST_PK, the value of the auto-increment primary key column is returned.
  • attribute_columns: the list of the attribute columns, which is consistent with that in the request. No attribute columns are returned in this example.
Example 1

The following code provides an example on how to write a row with 10 attribute columns and write one version of data for each column. The version number (timestamp) is specified by the server.

$attr = array();
for($i = 0; $i < 10; $i++) {
    $attr[] = ['Col'. $i, $i]; 
}
$request = [
    'table_name' => 'MyTable',
    'condition' => RowExistenceExpectationConst::CONST_IGNORE, // You can set the condition to IGNORE, EXPECT_EXIST, or  EXPECT_NOT_EXIST.
    'primary_key' => [ // The primary key.        ['PK0', 123],
        ['PK1', 'abc']
    ],
    'attribute_columns' => $attr
];
$response = $otsClient->putRow ($request);
			
Example 2

The following code provides an example on how to write a row with 10 attribute columns and write three versions of data for each column. The version number (timestamp) is specified by the client.

$attr = array();
$timestamp = getMicroTime();
for($i = 0; $i < 10; $i++) {
    for($j = 0; $j < 3; $j++) {
        $attr[] = ['Col'. $i, $j, null, $timestamp+$j];
    }
}
$request = [
    'table_name' => 'MyTable',
    'condition' => RowExistenceExpectationConst::CONST_IGNORE, // You can set the condition to IGNORE, EXPECT_EXIST, or  EXPECT_NOT_EXIST.
    'primary_key' => [ // The primary key.        ['PK0', 123],
        ['PK1', 'abc']
    ],
    'attribute_columns' => $attr
];
$response = $otsClient->putRow ($request);
			
Example 3

The following code provides an example on how to write data if the target row does not exist:

$attr = array();
$timestamp = getMicroTime();
for($i = 0; $i < 10; $i++) {
    for($j = 0; $j < 3; $j++) {
        $attr[] = ['Col'. $i, $j, null, $timestamp+$j];
    }
}
$request = [
    'table_name' => 'MyTable',
    'condition' => RowExistenceExpectationConst::CONST_EXPECT_NOT_EXIST, // Configure the condition to write data when the target row does not exist.
    'primary_key' => [ // The primary key.        ['PK0', 123],
        ['PK1', 'abc']
    ],
    'attribute_columns' => $attr
];
$response = $otsClient->putRow ($request);
			
Example 4

The following code provides an example on how to write data when the target row already exists and the value of Col0 is greater than 100:

$attr = array();
$timestamp = getMicroTime();
for($i = 0; $i < 10; $i++) {
    for($j = 0; $j < 3; $j++) {
        $attr[] = ['Col'. $i, $j, null, $timestamp+$j];
    }
}
$request = [
    'table_name' => 'MyTable',
    'condition' => [
        'row_existence' => RowExistenceExpectationConst::CONST_EXPECT_EXIST,// Configure the condition to write data when the target row exists.
        'column_condition' => [                  // If the condition is met, the data is updated.
            'column_name' => 'Col0',
            'value' => 100,
            'comparator' => ComparatorTypeConst::CONST_GREATER_THAN
        ]
    ,
    'primary_key' => [ // The primary key.        ['PK0', 123],
        ['PK1', 'abc']
    ],
    'attribute_columns' => $attr
];
$response = $otsClient->putRow ($request);
			

GetRow

GetRow

If the table name and the primary key of a row are specified, the two possible reading results are as follows:

  • If the row exists, the primary key columns and attribute columns of the row are returned.
  • If the row does not exist, no row is returned and no error is reported.
Operation
    /**
     * Read a row of data.
     * @api
     * @param [] $request Request parameters.
     * @return [] Response.
     * @throws OTSClientException The exception that occurs when a parameter error occurs or the Tablestore server returns a verification error.
     * @throws OTSServerException The exception that occurs when the Tablestore server returns an error.
     */
    public function getRow(array $request);
			
Sample requests
$result = $client->getRow([
    'table_name' => '<string>',                     // REQUIRED
    'primary_key' => [                              // REQUIRED
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ], 
    'max_versions' => <integer>,
    'time_range' => [
        'start_time' => <integer>,
        'end_time' => <integer>,
        'specific_time' => <integer>
    ],
    'start_column' => '<string>',
    'end_column' => '<string>',
    'token' => '<string>',
    'columns_to_get' => [
        '<string>',
        '<string>',
        //...   
    ],
    'column_filter' =>  <ColumnCondition>
]);
			
Code analysis
  • table_name: required. This parameter specifies the name of the table.
  • primary_keys: required. This parameter specifies the list of primary key columns for each row.
    • The primary key of a table can contain one to four primary key columns. Primary key columns are sorted based on the order they are added. For example, primary key schema PRIMARY KEY (A, B, C) is different from PRIMARY KEY (A, C, B). Tablestore sorts rows based on the values of all primary key columns.
    • Each item in primary_keys specifies the values in the following sequence: the primary key name, primary key value (PrimaryKeyValue), and primary key value type (PrimaryKeyType, which is optional).
    • The value of PrimaryKeyValue can be an integer or a string.
    • ColumnType can be set to ColumnTypeConst::CONST_INTEGER, ColumnTypeConst::CONST_STRING (UTF-8 encoded string), or ColumnTypeConst::CONST_BINARY. If the type of data to query is INTEGER or STRING, this parameter can be ignored. Otherwise, the type must be specified.
  • max_versions: the maximum number of versions from which data is read.
  • time_range: the range of versions from which data is read. For more information, see TimeRange.
    • start_time: the beginning of the time range to query, in milliseconds. Valid values: [0, INT64.MAX]. To query data within a range, specify start_time and end_time. The range is a left-closed right-open interval.
    • end_time: the end of the time range to query, in milliseconds. Valid values: [0, INT64.MAX].
    • specific_time: the specific timestamp. To query data at a specific point in time, specify specific_time. You can set one of specific_time and [start_time, end_time), in milliseconds. Valid values: [0, INT64.MAX].
  • You must specify at least one of max_versions and time_range.
    • If you specify only max_versions, data of up to the specified number of versions is returned from the latest to the earliest.
    • If you specify only time_range, all data within the range is returned.
    • If you specify both max_versions and time_range, data of up to the specified number of versions within the time range is returned from the latest to the earliest.
  • columns_to_get: the set of columns to read. If you do not specify this parameter, all columns are read.
  • start_column: the start column to read, which is used to read wide rows. The response contains the start column. The column names are sorted alphabetically. Example: A table contains columns a, b, and c. If the value of start_column is b, the reading starts from column b, and columns b and c are returned.
  • end_column: the end column to read, which is used to read wide rows. The response does not contain the end column. The column names are sorted alphabetically. Example: A table contains columns a, b, and c. If the value of end_column is b, the reading ends at column b, and column a is returned.
  • token: the start column of a wide row to read next time. This parameter is unavailable.
  • column_filter: the filtering condition. Only rows that meet the condition are returned. This parameter is similar to column_condition in condition. For more information, see Filter.
Responses
[
    'consumed' => [
        'capacity_unit' => [
            'read' => <integer>,
            'write' => <integer>
        ]
    ],
    'primary_key' => [ 
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ],  
    'attribute_columns' => [
            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
    ],
    'next_token' => '<string>'
]
			
Code analysis
  • consumed: the number of CUs consumed by this operation.
    capacity_unit: the number of read and write CUs consumed.
    • read: the number of read CUs consumed.
    • write: the number of write CUs consumed.
  • primary_key: the primary key value, which is consistent with that in the request. If you set ReturnTypeConst::CONST_PK, the value of the auto-increment primary key column is returned.
  • attribute_columns: required. This parameter specifies the list of attribute columns.
    • Each item specifies the values in the following sequence: the attribute column name, attribute column value (ColumnValue), attribute column value type (ColumnType, which is optional), and timestamp (optional).
    • ColumnType can be set to ColumnTypeConst::CONST_INTEGER, ColumnTypeConst::CONST_STRING (UTF-8 encoded string), ColumnTypeConst::CONST_BINARY, ColumnTypeConst::CONST_BOOLEAN, or ColumnTypeConst::CONST_DOUBLE.
    • The timestamp is a 64-bit integer that indicates a specific version in an attribute column.
    • The attribute columns in the response are sorted by attribute column name in ascending alphabetical order. The versions of the attribute columns are sorted by timestamp in descending order.
    • The order of the columns may be inconsistent with that of columns_to_get in the request.
  • next_token: the start column of a wide row to read next time. The data type of the column is BINARY. This parameter is unavailable.
  • If the row does not exist, the values of primary_key and attribute_columns are empty lists [].
Example 1

The following code provides an example on how to read the latest version of a column in a row:

$request = [
    'table_name' => 'MyTable',
    'primary_key' => [ // The primary key.
        ['PK0', 123],
        ['PK1', 'abc']
    ],
'max_versions' => 1,                     // Set this parameter to read the latest version.
'columns_to_get' => ['Col0']             // Set the column to read.
];
$response = $otsClient->getRow ($request);
			

Note:

  • If you query a row of data, the system returns the data in all columns of the row. You can specify columns_to_get to enable the system to return the data in specific columns. For example, if you set columns_to_get to Col0 and Col1, the system only returns the data in Col0 and Col1.
  • Conditional filtering is supported. For example, you can configure the system to return results only when the value of col0 is greater than 24.
  • When both columns_to_get and column_filter are specified, the system first returns results based on the value of columns_to_get, and then filters the returned columns based on the value of column_filter.
  • When a specified column does not exist, you can specify pass_if_missing to determine the next action. The default value is true, indicating that the condition is valid if the column does not exist.
Example 2

The following code provides an example on how to set a filter:

$request = [
    'table_name' => 'MyTable',
    'primary_key' => [ // The primary key.        ['PK0', 123],
        ['PK1', 'abc']
    ],
'max_versions' => 1,                     // Set this parameter to read the latest version.
'column_filter' => [                     // Set the filter to return a row if the value of Col0 is 0.
        'column_name' => 'Col0',
        'value' => 0,
        'comparator' => ComparatorTypeConst::CONST_EQUAL,
        'pass_if_missing' => false          // If a row does not contain the Col0 column, the row is not returned.
    ]
];
$response = $otsClient->getRow ($request);
			

UpdateRow

UpdateRow

You can call this operation to update a single row of data. If the target row does not exist, a new row is added.

The update operations include writing a column, deleting a column, and deleting a version of a column.

An update operation may be performed in any of the following scenarios:

  • Write a column value without specifying the version number. The Tablestore server automatically generates a version number to ensure that the version number is incremented.
  • Write a column value with a specific version number. The existing column value is overwritten. However, if the column does not have a column value corresponding to the specified version, the data is inserted.
  • Delete the column value of the specified version.
  • Delete the column values of all versions for the entire column.

When performing UpdateRow, you can use conditional update to configure conditions for the existence of the row to update or values in certain columns of the existing row. For more information, see Conditional update.

Operation
    /**
     * Update a row of data.
     * @api
     * @param [] $request Request parameters.
     * @return [] Response.
     * @throws OTSClientException The exception that occurs when a parameter error occurs or the Tablestore server returns a verification error.
     * @throws OTSServerException The exception that occurs when the Tablestore server returns an error.
     */
    public function updateRow(array $request);
			
Sample requests
$result = $client->updateRow([
    'table_name' => '<string>', // REQUIRED
    'condition' => [
        'row_existence' => <RowExistence>,
        'column_condition' => <ColumnCondition>
    ],
    'primary_key' => [                              // REQUIRED
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ], 
    'update_of_attribute_columns' => [         // REQUIRED
        'PUT' => [
            ['<string>', <ColumnValue>], 
            ['<string>', <ColumnValue>, <ColumnType>],
            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
        ],
        'DELETE' => [
            ['<string>', <integer>], 
            ['<string>', <integer>], 
            ['<string>', <integer>], 
            ['<string>', <integer>]
        ],
        'DELETE_ALL' => [
            '<string>',
            '<string>',
            '<string>',
            '<string>'
        ],        
    ],
    'return_content' => [
        'return_type' => <ReturnType>
    ]
]);
			
Code analysis
  • table_name: required. This parameter specifies the name of the table.
  • condition: the condition for the operation to take effect. For more information, see Conditional update.
    • row_existence: the row existence condition.
    • column_condition: the column condition.
  • primary_keys: required. This parameter specifies the list of primary key columns for each row.
    • The primary key of a table can contain one to four primary key columns. Primary key columns are sorted based on the order they are added. For example, primary key schema PRIMARY KEY (A, B, C) is different from PRIMARY KEY (A, C, B). Tablestore sorts rows based on the values of all primary key columns.
    • Each item in primary_keys specifies the values in the following sequence: the primary key name, primary key value (PrimaryKeyValue), and primary key value type (PrimaryKeyType, which is optional).
    • The value of PrimaryKeyValue can be an integer or a string.
    • PrimaryKeyType can be set to PrimaryKeyTypeConst::CONST_INTEGER, PrimaryKeyTypeConst::CONST_STRING (UTF-8 encoded string), or PrimaryKeyTypeConst::CONST_BINARY. If the type of data to query is INTEGER or STRING, this parameter can be ignored. Otherwise, the type must be specified.
  • update_of_attribute_columns: required. This parameter specifies the modification on the attribute columns in a row. If none of the operations is to perform, the corresponding item can be ignored. The update operations are as follows:
    • PUT: If this column does not exist, a new column is added. If the column exists, it is overwritten. The format is the same as that of attribute_columns in PutRow.
      • Each item specifies the values in the following sequence: the attribute column name, attribute column value (ColumnValue), attribute column value type (ColumnType, which is optional), and timestamp (optional).
      • ColumnType can be set to ColumnTypeConst::CONST_INTEGER, ColumnTypeConst::CONST_STRING (UTF-8 encoded string), ColumnTypeConst::CONST_BINARY, ColumnTypeConst::CONST_BOOLEAN, or ColumnTypeConst::CONST_DOUBLE. If the type of data to query is BINARY, the type must be specified. Otherwise, the type can be ignored or set to null.
      • The timestamp is a 64-bit integer that indicates the version of an attribute column. This parameter is optional. If this parameter is not specified, the server time is used.
    • DELETE: You must specify the timestamp. You can set Delete to delete the specified version in the column.
      • Each item specifies the values in the following sequence: the attribute column name, attribute column value (ColumnValue), attribute column value type (ColumnType, which is optional), and timestamp (optional).
      • The timestamp is a 64-bit integer that indicates a specific version in an attribute column.
    • DELETE_ALL: indicates that data of all versions in the column is deleted. You need only to specify the attribute name.
      Note Deleting all attribute columns of a row is not the same as deleting the row. If you want to delete the row, use the DeleteRow operation.
  • return_content: the content to return.

    return_type: Only this parameter is available for return_content.

    ReturnTypeConst::CONST_PK: returns the value of the auto-increment primary key column.

Responses
[
    'consumed' => [
        'capacity_unit' => [
            'read' => <integer>,
            'write' => <integer>
        ]
    ],
    'primary_key' => [ 
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ],  
    'attribute_columns' => []
]
			
Code analysis
  • consumed: the number of CUs consumed by this operation.
    capacity_unit: the number of read and write CUs consumed.
    • read: the number of read CUs consumed.
    • write: the number of write CUs consumed.
  • primary_key: the primary key value, which is consistent with that in the request. If you set ReturnTypeConst::CONST_PK, the value of the auto-increment primary key column is returned.
  • attribute_columns: the list of the attribute columns, which is consistent with that in the request. No attribute columns are returned in this example.
Example 1

The following code provides an example on how to update several columns, delete the specified version of a column, and delete the specified column:

$request = [
    'table_name' => 'MyTable',
    'condition' => RowExistenceExpectationConst::CONST_IGNORE,
    'primary_key' => [ // The primary key.
        ['PK0', 123],
        ['PK1', 'abc']
    ],
    'update_of_attribute_columns' => [
        'PUT' => [                       // Update several columns.
            ['Col0', 100],
            ['Col1', 'Hello'],
            ['Col2', 'a binary', ColumnTypeConst::CONST_BINARY],
            ['Col3', 100, null, 1526418378526]
        ],
        'DELETE' => [                    // Delete a version of a column.
            ['Col10', 1526418378526]
        ],
        'DELETE_ALL' => [
            'Col11'                      // Delete a column.
        ]
    ]
];
$response = $otsClient->updateRow($request);
			
Note You can use conditional statements to update rows.
Example 2

The following code provides an example on how to configure update conditions:

$request = [
    'table_name' => 'MyTable',
    'condition' => RowExistenceExpectationConst::CONST_IGNORE,
    'primary_key' => [ // The primary key.
        ['PK0', 123],
        ['PK1', 'abc']
    ],
    'condition' => [
        'row_existence' => RowExistenceExpectationConst::CONST_EXPECT_EXIST, // Update the row if it exists.
        'column_filter' => [                                                 // Update the row when the value of Col0 is greater than 100.
            'column_name' => 'Col0',
            'value' => 100,
            'comparator' => ComparatorTypeConst::CONST_GREATER_THAN
        ]
    ],    
    'update_of_attribute_columns' => [
        'PUT' => [                       // Update several columns.
            ['Col0', 100],
            ['Col1', 'Hello'],
            ['Col2', 'a binary', ColumnTypeConst::CONST_BINARY],
            ['Col3', 100, null, 1526418378526]
        ],
        'DELETE' => [                    // Delete a version of a column.
            ['Col10', 1526418378526]
        ],
        'DELETE_ALL' => [
            'Col11'                      // Delete a column.
        ]
    ]
];         

DeleteRow

DeleteRow

You can call this operation to delete a row. No errors are reported regardless of whether the specified row exists.

When performing DeleteRow, you can use conditional update to configure conditions for the existence of the row to delete or values in certain columns of the existing row. For more information, see Conditional update.

Operation
    /**
     * Delete a row of data.
     * @api
     * @param [] $request Request parameters.
     * @return [] Response.
     * @throws OTSClientException The exception that occurs when a parameter error occurs or the Tablestore server returns a verification error.
     * @throws OTSServerException The exception that occurs when the Tablestore server returns an error.
     */
    public function deleteRow(array $request);
			
Sample requests
$result = $client->deleteRow([
    'table_name' => '<string>', // REQUIRED
    'condition' => [
        'row_existence' => <RowExistence>,
        'column_condition' => <ColumnCondition>
    ],
    'primary_key' => [                              // REQUIRED
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ],
    'return_content' => [
        'return_type' => <ReturnType>
    ]
]);
			
Code analysis
  • table_name: required. This parameter specifies the name of the table.
  • condition: the condition for the operation to take effect. For more information, see Conditional update.
    • row_existence: the row existence condition.
    • column_condition: the column condition.
  • primary_keys: required. This parameter specifies the list of primary key columns for each row.
    • The primary key of a table can contain one to four primary key columns. Primary key columns are sorted based on the order they are added. For example, primary key schema PRIMARY KEY (A, B, C) is different from PRIMARY KEY (A, C, B). Tablestore sorts rows based on the values of all primary key columns.
    • Each item in primary_keys specifies the values in the following sequence: the primary key name, primary key value (PrimaryKeyValue), and primary key value type (PrimaryKeyType, which is optional).
    • The value of PrimaryKeyValue can be an integer or a string.
    • ColumnType can be set to ColumnTypeConst::CONST_INTEGER, ColumnTypeConst::CONST_STRING (UTF-8 encoded string), or ColumnTypeConst::CONST_BINARY. If the type of data to query is INTEGER or STRING, this parameter can be ignored. Otherwise, the type must be specified.
  • return_content: the content to return.

    return_type: Only this parameter is available for return_content.

    ReturnTypeConst::CONST_PK: returns the value of the auto-increment primary key column.

Responses
[
    'consumed' => [
        'capacity_unit' => [
            'read' => <integer>,
            'write' => <integer>
        ]
    ],
    'primary_key' => [
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ],
    'attribute_columns' => []
]
			
Code analysis
  • consumed: the number of CUs consumed by this operation.
    capacity_unit: the number of read and write CUs consumed.
    • read: the number of read CUs consumed.
    • write: the number of write CUs consumed.
  • primary_key: the primary key value, which is consistent with that in the request. If you set ReturnTypeConst::CONST_PK, the value of the auto-increment primary key column is returned.
  • attribute_columns: the list of the attribute columns, which is consistent with that in the request. No attribute columns are returned in this example.
Example 1

The following code provides an example on how to delete a row of data:

$request = [
    'table_name' => 'MyTable',
    'condition' => RowExistenceExpectationConst::CONST_IGNORE,
    'primary_key' => [ // The primary key.
        ['PK0', 123],
        ['PK1', 'abc']
    ],
    'return_content' => [
    'return_type' => ReturnTypeConst::CONST_PK     // Set return_type to ReturnTypeConst::CONST_PK to return the value of the auto-increment primary key column.
    ]
];
$response = $otsClient->deleteRow($request);
			
Example 2

The following code provides an example on how to configure delete conditions:

$request = [
    'table_name' => 'MyTable',
    'condition' => [
        'row_existence' => RowExistenceExpectationConst::CONST_EXPECT_EXIST, // Delete the row if it exists.
        'column_filter' => [          // Delete the row when the value of Col0 is greater than 100.
            'column_name' => 'Col0',
            'value' => 100,
            'comparator' => ComparatorTypeConst::CONST_GREATER_THAN
        ],
    ],
    'primary_key' => [ // The primary key.        ['PK0', 123],
        ['PK1', 'abc']
    ]
];
$response = $otsClient->deleteRow ($request);