Update attribute columns of a mapping table
Run the ALTER TABLE statement to add or remove an attribute column in an existing mapping table.
For more information, see Update attribute columns of mapping tables.
Prerequisites
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
A mapping table is created. For more information, see Create mapping tables.
Usage notes
-
You can execute the
ALTER TABLEstatement to update an attribute column in only a mapping table that is created by executing theCREATE TABLEstatement. You cannot execute theALTER TABLEstatement to update an attribute column in a mapping table that is automatically created for a table by executing theDESCRIBEstatement. -
You can add or remove only one attribute column in a mapping table by executing the
ALTER TABLEstatement. If you want to add or remove multiple attribute columns in a mapping table, you can execute theALTER TABLEstatement multiple times. -
You can execute the
ALTER TABLEstatement to update only the schema of a mapping table. The schema of the Tablestore table for which the mapping table is created is not updated. -
You cannot execute the
ALTER TABLEstatement to add or remove the primary key columns in a mapping table. -
After you execute the
ALTER TABLEstatement, the SQL engine asynchronously refreshes the mapping table. Up to 30 seconds are required to complete the refresh. During the refresh period, the column that you added may not be returned when you perform the operations that are supposed to return all columns.
Parameters
|
Parameter |
Description |
|
query |
The SQL statement. Configure this parameter based on the required feature. |
Examples
-
Add an attribute column
The following example adds a
colvaluecolumn of the BIGINT type to a mapping table namedexampletable:const params = { query: "alter table exampletable add column colvalue bigint", } client.sqlQuery(params, function (err, data) { if (err) { console.log('sqlQuery error:', err.toString()); } else { console.log('sqlQuery success:', data); } }); -
Remove an attribute column
The following example removes the
colvaluecolumn from a mapping table namedexampletable:const params = { query: "alter table exampletable drop column colvalue", } client.sqlQuery(params, function (err, data) { if (err) { console.log('sqlQuery error:', err.toString()); } else { console.log('sqlQuery success:', data); } });
You can remove attribute columns that you no longer need and then add attribute columns based on your business requirements.
FAQ
What's next
-
To accelerate SQL data queries and computing, you can create a secondary index or a search index. For more information, see Index selection policy and Computation pushdown.
Run the
SELECTstatement to query and analyze data using the mapping table. For more information, see Query data.Run the
DESCRIBEstatement to view table details. For more information, see Query information about tables.Run the
DROP MAPPING TABLEstatement to delete a mapping table that is created for a table or a search index. For more information, see Delete mapping tables.Run the
SHOW INDEXstatement to view index information for a table. For more information, see Query index information about tables.Run the
SHOW TABLESstatement to list mapping tables in the current database. For more information, see List the names of tables.