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.
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.
If you want to use a mapping table that is created for a search index to query data, the search index is created.
Parameters
Parameter | Description |
query | The SQL statement. Configure the parameter based on the required feature. |
Examples
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 test_table (pk varchar(1024), long_value bigint(20), double_value double, string_value mediumtext, bool_value bool, primary key(pk))
statement to create a mapping table for a table named test_table:
func createMappingTable(client *tablestore.TableStoreClient) {
// Create an SQL request.
request := &tablestore.SQLQueryRequest{Query: "create table test_table (pk varchar(1024), long_value bigint, double_value double, string_value mediumtext, bool_value bool, primary key(pk))"}
// Obtain the response to the SQL request.
res, err := client.SQLQuery(request)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(res.ResponseInfo.RequestId)
}
}
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.
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 information about 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 index information about tables.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 Query the names of mapping tables.