Query data with SQL
Tablestore SDK for Python executes a SELECT statement to query data from 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.
For the data table that you want to access, create a mapping table.
Description
Call the exe_sql_query method to execute a SELECT statement and query data from a mapping table.
def exe_sql_query(self, query)
The following example queries the row whose primary key is row1 from example_table.
query = (
"SELECT pk, long_value, double_value, string_value, bool_value "
"FROM example_table WHERE pk = 'row1' LIMIT 20"
)
row_list, table_capacity_units, search_capacity_units = 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 |
Response
The exe_sql_query method returns a tuple that contains the following elements.
|
Element |
Type |
Description |
|
|
List[Row] |
A list of result rows. The |
|
|
List[Tuple] |
Read and write CUs consumed by data tables. Each tuple contains a table name and a |
|
|
List[Tuple] |
Read and write CUs consumed by search indexes. Each tuple contains a search index name and a |