All Products
Search
Document Center

Tablestore:Operations on predefined columns

Last Updated:Jun 24, 2025

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)

AddDefinedColumnRequest parameters

  • TableName (required) string: the name of the data table.

  • DefinedColumns (required) []*DefinedColumnSchema: the information about predefined columns. Each predefined column contains the following parameters.

    Parameter

    Type

    Description

    Name (required)

    string

    The name of the predefined column.

    ColumnType (required)

    DefinedColumnType

    The data type of the predefined column.

    • Data types include STRING, INTEGER, BINARY, DOUBLE, and BOOLEAN.

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)

DeleteDefinedColumnRequest parameters

  • TableName (required) string: the name of the data table.

  • DefinedColumns (required) []string: the information about predefined columns.

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.")
    }
}