All Products
Search
Document Center

Tablestore:Read a row

Last Updated:Aug 12, 2026

Use the Tablestore SDK for Go to read a row from a Wide Column model table by specifying its complete primary key.

Prerequisites

Install the Tablestore SDK for Go and initialize the client.

Description

Call GetRow to read a row by specifying its complete primary key. You can limit the returned attribute columns, data versions, and version time range, or use a filter to screen attribute columns.

func (tableStoreClient *TableStoreClient) GetRow(request *GetRowRequest) (*GetRowResponse, error)

The following sample reads the row whose primary key value is row1 from the example_table table.

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

request := &tablestore.GetRowRequest{
    SingleRowQueryCriteria: &tablestore.SingleRowQueryCriteria{
        TableName:  "example_table",
        PrimaryKey: primaryKey,
        MaxVersion: 1,
    },
}

response, err := client.GetRow(request)
if err != nil {
    log.Fatal(err)
}

fmt.Println(response.PrimaryKey)
fmt.Println(response.Columns)

Parameters

GetRowRequest contains the following parameter.

Name

Type

Description

SingleRowQueryCriteria (required)

*SingleRowQueryCriteria

The row query criteria.

Row query criteria

SingleRowQueryCriteria contains the following parameters.

Name

Type

Description

TableName (required)

string

The table name.

PrimaryKey (required)

*PrimaryKey

The complete primary key of the row. To read a row that contains an auto-increment primary key column, also specify the actual auto-increment value.

MaxVersion (optional)

int32

The maximum number of versions to return. At least one of MaxVersion and TimeRange is required.

TimeRange (optional)

*TimeRange

The version time range, which specifies a start time, end time, or exact version in milliseconds. At least one of MaxVersion and TimeRange is required.

ColumnsToGet (optional)

[]string

The attribute columns to return. If this parameter is not specified, all attribute columns are returned. If both ColumnsToGet and Filter are specified, Tablestore first selects the columns specified by ColumnsToGet and then applies Filter to the selected columns. If Filter references a column that is not included in ColumnsToGet, the column is treated as missing. Whether the row is filtered out is determined by FilterIfMissing.

Filter (optional)

ColumnFilter

The attribute column filter. For more information, see Use filters.

StartColumn (optional)

*string

The start attribute column of the name range. This column is included in the result.

EndColumn (optional)

*string

The end attribute column of the name range. This column is excluded from the result.

TransactionId (optional)

*string

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

Response

GetRowResponse contains the following business information. If the row does not exist, the response does not contain a primary key or attribute columns.

Field

Type

Description

PrimaryKey

PrimaryKey

The primary key of the row.

Columns

[]*AttributeColumn

The returned attribute columns, values, and versions.

Examples

Read data versions in a time range

The following sample reads data versions generated within the previous day.

now := time.Now().UnixMilli()
request.SingleRowQueryCriteria.MaxVersion = 0
request.SingleRowQueryCriteria.TimeRange = &tablestore.TimeRange{
    Start: now - 24*60*60*1000,
    End:   now,
}