All Products
Search
Document Center

Tablestore:Write a row

Last Updated:Aug 12, 2026

Use the Tablestore SDK for Go to write or update a row in a Wide Column model table.

Prerequisites

Install the Tablestore SDK for Go and initialize the client.

Description

Call PutRow to write attribute columns to a row identified by its primary key. If the row exists, new data versions are added or overwritten for the specified attribute columns. You can use Condition to control whether the write is performed.

func (tableStoreClient *TableStoreClient) PutRow(request *PutRowRequest) (*PutRowResponse, error)

The following sample writes a row whose primary key value is row1 to the example_table table.

primaryKey := &tablestore.PrimaryKey{}
primaryKey.AddPrimaryKeyColumn("id", "row1")

change := &tablestore.PutRowChange{
    TableName:  "example_table",
    PrimaryKey: primaryKey,
}
change.AddColumn("name", "Alice")
change.AddColumn("age", int64(30))
change.SetCondition(tablestore.RowExistenceExpectation_IGNORE)

_, err := client.PutRow(&tablestore.PutRowRequest{PutRowChange: change})
if err != nil {
    log.Fatal(err)
}

Parameters

PutRowRequest contains the following parameter.

Name

Type

Description

PutRowChange (required)

*PutRowChange

The row write configuration.

Row change

PutRowChange contains the following parameters.

Name

Type

Description

TableName (required)

string

The table name.

PrimaryKey (required)

*PrimaryKey

The primary key of the row. The names, order, and types of the primary key columns must match the table schema. To read or operate on a row that contains an auto-increment primary key column, specify the complete primary key.

Columns (optional)

[]AttributeColumn

The attribute columns to write. Call AddColumn to let the server generate the data version or AddColumnWithTimestamp to specify the version.

Condition (required)

*RowCondition

The write condition, which can include a row existence condition and a column condition. For more information, see Use conditional updates.

ReturnType (optional)

ReturnType

The return type. Default value: ReturnType_RT_NONE. Set this parameter to ReturnType_RT_PK to return the complete primary key, such as when you need an auto-increment value.

TransactionId (optional)

*string

The local transaction ID. Specify this parameter only for a write in a local transaction. For more information, see Use local transactions.

Attribute column

Each element in Columns is of the AttributeColumn type and contains the following parameters.

Name

Type

Description

ColumnName (required)

string

The attribute column name.

Value (required)

interface{}

The attribute column value. String, integer, binary, floating-point, and Boolean values are supported.

Timestamp (optional)

int64

The data version, in milliseconds. If this parameter is not specified, the server generates the version.

Response

PutRowResponse contains the following business field.

Field

Type

Description

PrimaryKey

PrimaryKey

The complete primary key of the written row. This field is returned only when ReturnType is set to ReturnType_RT_PK.

Examples

Specify data versions

The following sample uses the current time and a specified timestamp as data versions for attribute columns.

currentTimestamp := time.Now().UnixMilli()
change.AddColumnWithTimestamp("status", "active", currentTimestamp)
change.AddColumnWithTimestamp("score", int64(95), int64(1758249013000))