Update attribute columns of a mapping table
Tablestore SDK for Python adds or removes attribute columns of a mapping table.
Prerequisites
Install Tablestore SDK for Python and initialize a client.
SQL query requires version 5.4.2 or later. We recommend that you use the latest version.
Usage notes
Only mapping tables created by a
CREATE TABLEstatement supportALTER TABLE. Mapping tables automatically bound by operations such asDESCRIBEcannot be updated.Each
ALTER TABLEstatement can add or remove only one attribute column.The operation updates only the mapping table schema. It does not update the Tablestore storage schema and cannot add or remove primary key columns.
The SQL engine refreshes the mapping table asynchronously within 30 seconds. During the refresh, a query for all attribute columns may not return a newly added column.
To change an existing attribute column definition, remove the column and then add it with the new definition.
Description
Call the exe_sql_query method to execute an ALTER TABLE statement and add or remove an attribute column.
def exe_sql_query(self, query)
The following example adds the new_column attribute column to example_table.
query = "ALTER TABLE example_table ADD COLUMN new_column BIGINT"
client.exe_sql_query(query)
Parameters
The exe_sql_query method contains the following parameter.
|
Name |
Type |
Description |
|
query (required) |
String |
The To add an attribute column, use To remove an attribute column, use |
Scenario examples
Remove an attribute column
The following example removes new_column from example_table.
query = "ALTER TABLE example_table DROP COLUMN new_column"
client.exe_sql_query(query)