This topic describes how to add or remove predefined columns for a data table by using Tablestore SDK for Go.
Usage notes
You can specify up to 32 predefined columns for a data table. If your business requirements exceed this limit, submit a ticket.
If a predefined column is referenced by a secondary index, you must delete the secondary index before you can delete the predefined column.
Prerequisites
A client is initialized. For more information, see Initialize a Tablestore client.
Add predefined columns
Method
func (tableStoreClient *TableStoreClient) AddDefinedColumn(request *AddDefinedColumnRequest) (*AddDefinedColumnResponse, error)Sample code
The following sample code adds a predefined column named name of the String type to the test_table table.
func AddDefinedColumnSample(client *tablestore.TableStoreClient) {
addDefinedColumnRequest := new(tablestore.AddDefinedColumnRequest)
addDefinedColumnRequest.AddDefinedColumn("name", tablestore.DefinedColumn_STRING)
addDefinedColumnRequest.TableName = "test_table"
_, err := client.AddDefinedColumn(addDefinedColumnRequest)
if err != nil {
fmt.Println("Failed to add DefinedColumn with error:", err)
} else {
fmt.Println("Add DefinedColumn finished.")
}
}Remove predefined columns
Method
func (tableStoreClient *TableStoreClient) DeleteDefinedColumn(request *DeleteDefinedColumnRequest) (*DeleteDefinedColumnResponse, error)Sample code
The following sample code removes the predefined column named name from the test_table table.
func DeleteDefinedColumnSample(client *tablestore.TableStoreClient) {
deleteDefinedColumnRequest := new(tablestore.DeleteDefinedColumnRequest)
deleteDefinedColumnRequest.DefinedColumns = []string{"name"}
deleteDefinedColumnRequest.TableName = "test_table"
_, err := client.DeleteDefinedColumn(deleteDefinedColumnRequest)
if err != nil {
fmt.Println("Failed to delete DefinedColumn with error:", err)
} else {
fmt.Println("Delete DefinedColumn finished.")
}
}