Manage predefined columns

Updated at:

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.

Important

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.

Important

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)

string

The table name.

DefinedColumns (required)

[]*DefinedColumnSchema

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)

string

The predefined column name.

ColumnType (required)

DefinedColumnType

The data type of the predefined column. Valid values: DefinedColumn_STRING, DefinedColumn_INTEGER, DefinedColumn_BINARY, DefinedColumn_DOUBLE, and DefinedColumn_BOOLEAN.

Delete predefined columns request

DeleteDefinedColumnRequest contains the following parameters.

Name

Type

Description

TableName (required)

string

The table name.

DefinedColumns (required)

[]string

The names of the predefined columns to delete.