All Products
Search
Document Center

Tablestore:Query data

Last Updated:Nov 03, 2023

You can execute the SELECT statement to query data in a table.

Note For more information about the select statement, see Query data.

Prerequisites

Parameters

Parameter

Description

query

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

Example

Execute the select pk, long_value, double_value, string_value, bool_value from test_table limit 20 statement to query data in the table named test_table and set the maximum number of rows that you want to return to 20. The system returns the request type, response schema, and response results of the SQL statement.

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])