Query mapping table information

Updated at:

Tablestore SDK for Python queries the field names, field types, and primary key information of a mapping table.

Prerequisites

  • Install Tablestore SDK for Python and initialize a client.

  • SQL query requires version 5.4.2 or later. We recommend that you use the latest version.

Description

Call the exe_sql_query method to execute a DESCRIBE statement and query the field names, field types, primary key information, nullability, and other schema information of a mapping table.

def exe_sql_query(self, query)

The following example queries the schema of example_table.

query = "DESCRIBE example_table"
row_list, _, _ = client.exe_sql_query(query)

for row in row_list:
    print(dict(row.attribute_columns))

Parameters

The exe_sql_query method contains the following parameter.

Name

Type

Description

query (required)

String

The DESCRIBE <mapping_table_name> statement to execute, where <mapping_table_name> is the mapping table name.

Response

The exe_sql_query method returns a tuple that contains the following elements.

Element

Type

Description

row_list

List[Row]

A list of mapping table fields. Each Row object contains the following result-set fields.

table_capacity_units

List[Tuple]

Read and write CUs consumed by data tables. Each tuple contains a table name and a CapacityUnit object.

search_capacity_units

List[Tuple]

Read and write CUs consumed by search indexes. Each tuple contains a search index name and a CapacityUnit object.

Result-set fields

Field

Type

Description

Field

String

The field name.

Type

String

The SQL field type.

Null

String

Whether the field can be null.

Key

String

Whether the field is a primary key. A primary key column returns PRI.

Default

String

The default value.

Extra

String

Additional field information.