All Products
Search
Document Center

Tablestore:Query data by executing SQL statements

Last Updated:May 26, 2025

This topic describes how to use Tablestore SDK for Python to query data by executing SQL statements.

Prerequisites

Parameters

Parameter

Description

query

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

Example

You can use the select pk, long_value, double_value, string_value, bool_value from test_table limit 20 statement to query data in the test_table table and return a maximum of 20 rows. The system returns the request type of the SQL statement, the schema of the return value, and the returned results.

def query_data(client):
    query = 'select pk, long_value, double_value, string_value, bool_value from test_table limit 20'
    rowlist, _, _ = client.exe_sql_query(query)
    ret_map = collections.defaultdict(list)
    for row in rowlist:
        for tup in row.attribute_columns:
            ret_map[tup[0]].append(tup[1])
    for item in ret_map:
        print(item, ret_map[item])
  

FAQ

References