All Products
Search
Document Center

Tablestore:Write a single row of data

Last Updated:Jun 22, 2026

Call the `putRow` method in the Tablestore Node.js SDK to insert a row with primary key columns and optional attribute columns into a data table.

Prerequisites

Initialize the Tablestore client

Method

putRow: function putRow(params, callback)

Parameter descriptions

Name

Type

Description

tableName (required)

string

The name of the table.

primaryKey (required)

Array

Primary key columns, including their names and values.

  • Supported data types: STRING, INTEGER, and BINARY.

  • The number and types of primary key columns must match the table schema.

  • If a primary key column is an auto-increment column, set its value to a placeholder. For more information, see auto-increment primary key column.

attributeColumns (optional)

Array

Attribute columns, including their names, values, and version numbers.

  • Supported data types: STRING, INTEGER, BINARY, DOUBLE, and BOOLEAN.

  • The version number is a timestamp that the system generates automatically by default. You can also specify it manually. For more information, see data versions and lifecycle.

condition (required)

TableStore.Condition

The write condition. For more information, see conditional update.

returnContent (optional)

object

The data to return.

  • returnType (optional) number: The return type.

    • TableStore.ReturnType.NONE (default): Returns no data.

    • TableStore.ReturnType.Primarykey: Returns the primary key columns. Use this option for auto-increment primary key columns.

    • TableStore.ReturnType.AfterModify: Returns the updated column values. Use this option for atomic counters.

transactionId (optional)

string

The ID that uniquely identifies a local transaction. For more information, see local transaction.

Examples

The following example inserts a row into the test_table table with the primary key value row1.

var params = {
    tableName: 'test_table',
    primaryKey: [{ 'id': 'row1' }],
    // Specify a write condition when writing data. TableStore.RowExistenceExpectation.IGNORE means that the system does not check whether the row exists.
    condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null)
};

client.putRow(params, function (err, data) {
    if (err) {
        console.log('Put row failed with error: ', err);
        return;
    }
    console.log('* RequestId: ', data.RequestId);
    console.log('* Read CU Cost: ', data.consumed.capacityUnit.read);
    console.log('* Write CU Cost: ', data.consumed.capacityUnit.write);
});
  • Add an attribute column.

    params.attributeColumns = [{ 'col1': 'val1' }];
  • Specify a version number. You can assign a separate version number to each attribute column.

    params.attributeColumns = [{ 'col1': 'val1', 'timestamp': Date.now() }];

References

Batch update data