All Products
Search
Document Center

Tablestore:Query information about tables

Last Updated:Nov 03, 2023

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

Note For more information about the describe statement, see Query the information about a table.

Prerequisites

Parameters

Parameter

Description

query

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

Example

Execute the describe test_table statement to query information about the table named test_table.

def get_table_desc(client):
    query = 'describe test_table'
    rowlist, _, _ = client.exe_sql_query(query)
    ret = []
    for row in rowlist:
        ret.append(row.attribute_columns)
    print(ret)

The following output is returned:

[[('Field', 'pk'), ('Type', 'varchar(1024)'), ('Null', 'NO'), ('Key', 'PRI'), ('Default', None), ('Extra', '')],
[('Field', 'long_value'), ('Type', 'bigint(20)'), ('Null', 'YES'), ('Key', ''), ('Default', None), ('Extra', '')],
[('Field', 'double_value'), ('Type', 'double'), ('Null', 'YES'), ('Key', ''), ('Default', None), ('Extra', '')],
[('Field', 'string_value'), ('Type', 'mediumtext'), ('Null', 'YES'), ('Key', ''), ('Default', None), ('Extra', '')],
[('Field', 'bool_value'), ('Type', 'tinyint(1)'), ('Null', 'YES'), ('Key', ''), ('Default', None), ('Extra', '')]]