Manage predefined columns
Use the Tablestore SDK for Go to add or delete predefined columns for an existing Wide Column model table.
Prerequisites
Install the Tablestore SDK for Go and initialize the client.
Description
Add predefined columns
Call AddDefinedColumn to add one or more predefined columns to a table.
By default, you can add up to 32 predefined columns to a table. To increase this limit, submit a ticket or join DingTalk technical support group 36165029092.
func (tableStoreClient *TableStoreClient) AddDefinedColumn(request *AddDefinedColumnRequest) (*AddDefinedColumnResponse, error)
The following sample adds the score and status predefined columns to the example_table table.
request := &tablestore.AddDefinedColumnRequest{
TableName: "example_table",
}
request.AddDefinedColumn("score", tablestore.DefinedColumn_INTEGER)
request.AddDefinedColumn("status", tablestore.DefinedColumn_STRING)
_, err := client.AddDefinedColumn(request)
if err != nil {
log.Fatal(err)
}
Delete predefined columns
Call DeleteDefinedColumn to delete one or more predefined columns from a table.
If a predefined column is referenced by a secondary index, you must delete the corresponding secondary index before you delete the predefined column.
func (tableStoreClient *TableStoreClient) DeleteDefinedColumn(request *DeleteDefinedColumnRequest) (*DeleteDefinedColumnResponse, error)
The following sample deletes the status predefined column from the example_table table.
request := &tablestore.DeleteDefinedColumnRequest{
TableName: "example_table",
DefinedColumns: []string{"status"},
}
_, err := client.DeleteDefinedColumn(request)
if err != nil {
log.Fatal(err)
}
Parameters
Add predefined columns request
AddDefinedColumnRequest contains the following parameters.
|
Name |
Type |
Description |
|
TableName (required) |
|
The table name. |
|
DefinedColumns (required) |
|
The predefined columns to add. |
Predefined column
Each element in DefinedColumns is of the DefinedColumnSchema type and contains the following parameters.
|
Name |
Type |
Description |
|
Name (required) |
|
The predefined column name. |
|
ColumnType (required) |
|
The data type of the predefined column. Valid values: |
Delete predefined columns request
DeleteDefinedColumnRequest contains the following parameters.
|
Name |
Type |
Description |
|
TableName (required) |
|
The table name. |
|
DefinedColumns (required) |
|
The names of the predefined columns to delete. |