All Products
Search
Document Center

Tablestore:Query information about a table

Last Updated:Jun 11, 2024

You can execute the DESCRIBE statement to query information about a table, such as the field names and field types.

Note

For more information about the DESCRIBE statement, see Query information about tables.

Prerequisites

Parameters

Parameter

Description

query

The SQL statement. Configure the parameter based on the required feature.

Examples

The following sample code provides an example on how to execute the describe test_table statement to query the information about test_table:


func getTableDesc(client *tablestore.TableStoreClient) {
    // Create an SQL request. 
    request := &tablestore.SQLQueryRequest{Query: "describe test_table"}

    // Obtain the response to the SQL request. 
    response, err := client.SQLQuery(request)
    if err != nil {
        panic(err)
    }

    // Obtain the schema of the returned results of the SQL request. 
    columns := response.ResultSet.Columns()
    for l := 0; l< len(columns); l++ {
        fmt.Printf("%v:%v ", columns[l].Name, columns[l].Type.String())
    }

    // Use SQL ResultSet to obtain all returned results of the SQL request. 
    fmt.Println("]\nresponse resultset:")
    resultSet := response.ResultSet
    for resultSet.HasNext() {
        row := resultSet.Next()
        for i := range columns {
            if i > 0 {
                fmt.Printf(", ")
            }
            value, err := row.GetString(i)
            if err != nil {
                panic(err)
            }
            fmt.Printf(value)
        }
        fmt.Println()
    }
}

Sample response:

response table schema: [Field:STRING Type:STRING Null:STRING Key:STRING Default:STRING Extra:STRING]
response resultset:
pk, varchar(1024), NO, PRI, ,
long_value, bigint(20), YES, , ,
double_value, double, YES, , ,
string_value, mediumtext, YES, , ,
bool_value, tinyint(1), YES, , ,

References

  • To use a mapping table to query data that meets specific conditions, execute the SELECT statement. For more information, see Query data.

  • To update the attribute column of a mapping table after an attribute column of the data table is changed, execute the ALTER TABLE statement. For more information, see Update attribute columns of mapping tables.

  • To delete a mapping table, execute the DROP MAPPING TABLE statement. For more information, see Delete mapping tables.