All Products
Search
Document Center

Tablestore:Query information of a table

Last Updated:Jun 25, 2025

This topic describes how to query information of a table by using Tablestore SDK for Go.

Prerequisites

A client is initialized. For more information, see Initialize a Tablestore client.

Method description

func (tableStoreClient *TableStoreClient) DescribeTable(request *DescribeTableRequest) (*DescribeTableResponse, error)

DescribeTableRequest parameters

TableName (required) string: The name of the data table.

Sample code

The following sample code provides an example on how to query information of the test_table table.

func DescribeTableSample(client *tablestore.TableStoreClient) {
    describeTableReq := new(tablestore.DescribeTableRequest)
    describeTableReq.TableName = "test_table"
    response, err := client.DescribeTable(describeTableReq)
    if err != nil {
        fmt.Println("Failed to describe table with error:", err)
    } else {
        // Obtain the schema information of the data table.
        tableMeta := response.TableMeta
        fmt.Printf("* Table name: %s \n", tableMeta.TableName)
        fmt.Println("* Primary key information (primary key type 1:INTEGER,2:STRING,3:BINARY)")
        for _, schemaEntry := range tableMeta.SchemaEntry {
            fmt.Printf("%s:%v \n", *schemaEntry.Name, *schemaEntry.Type)
        }
        fmt.Println("* Predefined column information (predefined column type 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING,5:BINARY)")
        for _, definedColumn := range tableMeta.DefinedColumns {
            fmt.Printf("%s:%v \n", definedColumn.Name, definedColumn.ColumnType)
        }

        // Obtain the configuration information of the data table.
        tableOption := response.TableOption
        fmt.Println("* Table configuration information")
        fmt.Printf("Max versions: %d \n", tableOption.MaxVersion)
        fmt.Printf("Time to live: %d \n", tableOption.TimeToAlive)
        fmt.Printf("Max version offset: %d \n", tableOption.DeviationCellVersionInSec)
        fmt.Printf("Allow updates: %t \n", *tableOption.AllowUpdate)

        // Obtain the Stream information of the table.
        streamDetails := response.StreamDetails
        fmt.Printf("* Whether to enable Stream: %t \n", streamDetails.EnableStream)
        if streamDetails.EnableStream {
            fmt.Printf("Stream expiration time: %d \n", streamDetails.ExpirationTime)
        }

        // Obtain the encryption settings of the table.
        sseDetails := response.SSEDetails
        fmt.Printf("* Whether to enable table encryption: %t \n", sseDetails.Enable)
        if sseDetails.Enable {
            fmt.Printf("Encryption method: %s \n", sseDetails.KeyType.String())
        }

        // Obtain the reserved read/write throughput of the table.
        reservedThroughput := response.ReservedThroughput
        fmt.Println("* Reserved read/write throughput")
        fmt.Printf("Reserved read throughput: %d \n", reservedThroughput.Readcap)
        fmt.Printf("Reserved write throughput: %d \n", reservedThroughput.Writecap)

        // Obtain the secondary index information.
        indexMetas := response.IndexMetas
        for _, indexMeta := range indexMetas {
            fmt.Printf("* Secondary index name: %s \n", indexMeta.IndexName)
            fmt.Printf("Primary key columns: %v \n", indexMeta.Primarykey)
            fmt.Printf("Predefined columns: %v \n", indexMeta.DefinedColumns)
            fmt.Printf("Secondary index type: %d (0:IT_GLOBAL_INDEX,1:IT_LOCAL_INDEX) \n", indexMeta.IndexType)
        }
    }
}

References

Query information of a time series table