Query information about tables

更新时间:
复制 MD 格式

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 information about tables.

Prerequisites

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

Example

The following sample code provides an example on how to execute the describe test_table statement to query the information about 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', '')]]