Run the ALTER TABLE statement to add or remove attribute columns from 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 to a mapping table
The following example adds a
colvaluecolumn of theBIGINTtype to a mapping table namedexampletable:def alter_table_add_column(client): query = 'alter table exampletable add column colvalue bigint' client.exe_sql_query(query) -
Remove an attribute column from a mapping table
The following example removes the
colvaluecolumn from a mapping table namedexampletable:def alter_table_drop_column(client): query = 'alter table exampletable drop column colvalue' client.exe_sql_query(query)
Remove attribute columns that are no longer needed before adding new ones to meet your business requirements.
FAQ
References
-
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.
After updating attribute columns, use the
SELECTstatement to query and analyze data. For more information, see Query data.To view the description of a table, use the
DESCRIBEstatement. For more information, see Query information about tables.To delete a mapping table that is no longer needed, use the
DROP MAPPING TABLEstatement. For more information, see Delete mapping tables.To view index information for a table, use the
SHOW INDEXstatement. For more information, see Query index information about tables.To list mapping tables in the current database, use the
SHOW TABLESstatement. For more information, see Query the names of tables.