Update attribute columns of a mapping table
Tablestore SDK for Go adds or removes attribute columns of a mapping table.
Prerequisites
Install Tablestore SDK for Go and initialize a client. SQL query requires version 1.7.4 or later. We recommend that you use the latest version.
Considerations
-
Execute a
CREATE TABLEstatement to create a mapping table for the data table first, and then use anALTER TABLEstatement to update attribute columns. -
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 SQLQuery method to execute an ALTER TABLE statement and add or remove an attribute column.
func (client *TableStoreClient) SQLQuery(request *SQLQueryRequest) (*SQLQueryResponse, error)
The following example adds the new_column attribute column to example_table.
request := &tablestore.SQLQueryRequest{
Query: "ALTER TABLE example_table ADD COLUMN new_column BIGINT",
}
if _, err := client.SQLQuery(request); err != nil {
log.Fatalf("SQLQuery failed: %v", err)
}
Parameters
SQLQueryRequest contains the following parameters.
|
Name |
Type |
Description |
|
Query (required) |
string |
The |
Examples
Remove an attribute column
The following example removes new_column from example_table.
request := &tablestore.SQLQueryRequest{
Query: "ALTER TABLE example_table DROP COLUMN new_column",
}
if _, err := client.SQLQuery(request); err != nil {
log.Fatalf("SQLQuery failed: %v", err)
}