All Products
Search
Document Center

Tablestore:Query data

Last Updated:Sep 09, 2024

After you create a mapping table for a table or search index, you can execute the SELECT statement to query and analyze data by using the mapping table.

Note

For more information about the SELECT statement, see Query data.

Prerequisites

Usage notes

Tablestore SDK for PHP V5.1.0 or later supports the SQL query feature. Before you use the SQL query feature, make sure that Tablestore SDK for PHP V5.1.0 or later is obtained. For information about the versions of Tablestore SDK for PHP, see Version history of Tablestore SDK for PHP.

Parameters

Parameter

Description

query

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

Examples

The following sample code provides an example on how query data in the table named tableName by executing the SELECT `PK0`, `boolean`, `long`, `geo` FROM `tableName` LIMIT 10; statement. In this example, up to 10 rows of data can be returned. The system returns the request type, the schema of the returned results, and the returned results of the query statement.

$request = array(
    'query' => 'SELECT `PK0`, `boolean`, `long`, `geo` FROM `tableName` LIMIT 10;',
);
$response = $this->otsClient->sqlQuery($request);
$sqlRows = $response['sql_rows'];

// print all data metrix
$lines = '';
for ($i = 0; $i < $sqlRows->rowCount; $i++) {
    $line = '';
    for ($j = 0; $j < $sqlRows->columnCount; $j++) {
        $line = $line . (is_null($sqlRows->get($j, $i)) ?  "null" : $sqlRows->get($j, $i)) . "\t";
    }
    $lines = $lines . $line . "\n";
}
print $lines;
$sqlRows = $response['sql_rows'];

FAQ

References

  • If you want to accelerate data queries and computing by executing SQL statements, you can create a secondary index or a search index. For more information, see Index selection policy and Computing pushdown.

  • If an attribute column is added to or deleted from a data table, you can execute the ALTER TABLE statement to modify the mapping table that is created for the data table. For more information, see Update attribute columns of mapping tables.

  • If you want to query the description of a table, you can execute the DESCRIBE statement. For more information, see Query the description of a table.

  • If you no longer require a mapping table that is created for a table or a search index, you can execute the DROP MAPPING TABLE statement to delete the mapping table. For more information, see Delete mapping tables.

  • If you want to view the index information about a table, you can execute the SHOW INDEX statement. For more information, see Query the index information about a table.

  • If you want to query the names of mapping tables in the current database, you can execute the SHOW TABLES statement. For more information, see List the names of mapping tables.

  • You can also use computing engines, such as MaxCompute, Spark, Hive, HadoopMR, Function Compute, Flink, and PrestoDB, to compute and analyze data in tables. For more information, see Overview.