All Products
Search
Document Center

Tablestore:Create a mapping table

Last Updated:Aug 19, 2024

You can execute the CREATE TABLE statement to create a mapping table for an existing table or a search index. When you create a mapping table, specify the names and types of fields in the table, the primary key information about the table, and the execution engine for data queries based on your business requirements.

Note

For more information about the CREATE TABLE statement, see Create a mapping table for a table and Create mapping tables for search indexes.

Prerequisites

  • An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.

  • A data table is created. For more information, see Create a data table.

    If you want to use a mapping table that is created for a search index to query data, the search index is created.

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

Note

This topic describes how to create a mapping table for a table. If you want to create a mapping table for a search index, replace the SQL statement in the sample code with the SQL statement that is used to create a mapping table for a search index.

The following sample code provides an example on how to execute the CREATE TABLE `tableName` (`PK0` BIGINT(20),`PK1` VARCHAR(1024),`geo` MEDIUMTEXT,`boolean` BOOL,`array` MEDIUMTEXT,`double` DOUBLE,`text` MEDIUMTEXT,`keyword` MEDIUMTEXT,`nested` MEDIUMTEXT,`long` BIGINT(20),PRIMARY KEY(`PK0`,`PK1`)); statement to create a mapping table for a table named tableName:

$request = array(
    'query' => 'CREATE TABLE `tableName` (`PK0` BIGINT(20),`PK1` VARCHAR(1024),`geo` MEDIUMTEXT,`boolean` BOOL,`array` MEDIUMTEXT,`double` DOUBLE,`text` MEDIUMTEXT,`keyword` MEDIUMTEXT,`nested` MEDIUMTEXT,`long` BIGINT(20),PRIMARY KEY(`PK0`,`PK1`));',
);
$response = $otsClient->sqlQuery($request);
print json_encode($response, JSON_PRETTY_PRINT);

FAQ

How do I troubleshoot common errors of SQL queries?

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.

  • You can execute the SELECT statement to query and analyze data in the table for which you created a mapping table. For more information, see Query data.

  • If an attribute column is added to or removed 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.