Update attribute columns of a mapping table
Use Tablestore SDK for Java to add or remove attribute columns from a mapping table.
Prerequisites
-
Install the Tablestore SDK for Java and initialize a client.
-
Use Tablestore SDK for Java 5.13.0 or later.
Usage notes
-
Only mapping tables that are created with a
CREATE TABLEstatement support attribute column updates withALTER TABLE. Mapping tables that are automatically bound by operations such asDESCRIBEdo not support attribute column updates. -
Each
ALTER TABLEstatement can add or remove only one attribute column. To update multiple attribute columns, execute anALTER TABLEstatement for each column. -
An
ALTER TABLEstatement updates only the mapping table schema. It does not update the data storage schema of the Tablestore table. -
An
ALTER TABLEstatement cannot add or remove primary key columns from a mapping table. -
After you execute an
ALTER TABLEstatement, the SQL engine refreshes the mapping table asynchronously. The refresh can take up to 30 seconds. During the refresh, queries that return all attribute columns may not return the newly added column. -
To change the definition of an existing attribute column, use
DROP COLUMNto remove the column and then useADD COLUMNto add the column with the new definition.
Description
Call the sqlQuery method to execute an ALTER TABLE statement and add or remove attribute columns from a mapping table.
SQLQueryResponse sqlQuery(SQLQueryRequest request)
The following example adds the new_column attribute column of the BIGINT type to the example_table mapping table.
SQLQueryRequest request = new SQLQueryRequest(
"ALTER TABLE example_table ADD COLUMN new_column BIGINT");
client.sqlQuery(request);
Parameters
SQLQueryRequest contains the following parameter.
|
Name |
Type |
Description |
|
query (required) |
String |
The To add an attribute column, use To remove an attribute column, use |
Scenario example
Remove an attribute column
The following example removes the new_column attribute column from the example_table mapping table.
SQLQueryRequest request = new SQLQueryRequest(
"ALTER TABLE example_table DROP COLUMN new_column");
client.sqlQuery(request);