You can call the CreateTimeseriesTable operation to create a time series table. When you call the CreateTimeseriesTable operation to create a time series table, you must specify the configurations of the table.

Prerequisites

Usage note

The name of the time series table that you create cannot be the same as the name of an existing data table.

Parameters

Parameter Description
timeseriesTableName The name of the time series table.
timeseriesTableOptions The configurations of the time series table, which include the following content:

timeToLive: the retention period of the data in the time series table. Unit: seconds. If you want the data in the time series table to never expire, set this parameter to -1. You can call the UpdateTimeseriesTable operation to modify the value of this parameter.

Example

/**
 * Use CreateTimeseriesTableSample to create a time series table named timeseriesTableName and specify the time to live (TTL) of the data in the time series table. 
 */
func CreateTimeseriesTableSample(client *tablestore.TimeseriesClient, timeseriesTableName string , timeToLive int64) {
    fmt.Println("[Info]: Begin to create timeseries table: " , timeseriesTableName)

    timeseriesTableOptions := tablestore.NewTimeseriesTableOptions(timeToLive)        // Construct the configurations of the time series table. 

    // Construct the metadata of the time series table.
    timeseriesTableMeta := tablestore.NewTimeseriesTableMeta(timeseriesTableName)    // Specify the name of the time series table. 
    timeseriesTableMeta.SetTimeseriesTableOptions(timeseriesTableOptions)            // Specify the configurations of the time series table.

    createTimeseriesTableRequest := tablestore.NewCreateTimeseriesTableRequest()    // Construct the request to create the time series table. 
    createTimeseriesTableRequest.SetTimeseriesTableMeta(timeseriesTableMeta)

    createTimeseriesTableResponse , err := client.CreateTimeseriesTable(createTimeseriesTableRequest)    // Call the client to create the time series table. 
    if err != nil {
        fmt.Println("[Error]: Failed to create timeseries table with error: " , err)
        return
    }
    fmt.Println("[Info]: CreateTimeseriesTable finished! RequestId: " , createTimeseriesTableResponse.RequestId)
}