All Products
Search
Document Center

Tablestore:Create a time series table

Last Updated:Dec 17, 2024

You can call the CreateTimeseriesTable operation to create a time series table. When you create a time series table, you can configure the time to live (TTL) of data and parameters about time series metadata.

Prerequisites

Usage notes

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

TimeseriesTableMeta

The configurations of the time series table.

  • timeseriesTableName: the name of the time series table.

  • timeseriesMetaOptions: the configurations of the time series metadata. The following parameters are included:

    • metaTimeToLive: the TTL of the time series metadata. Unit: seconds. The value must be -1 or a value that is greater than or equal to 604800. A value of -1 specifies that the metadata never expires. A value of 604800 specifies 7 days.

    • allowUpdateAttributes: specifies whether the property columns of the time series metadata can be modified.

    You can call the UpdateTimeseriesTable operation to modify the preceding parameters.

  • timeseriesTableOptions: the configurations of the time series table. The following parameter is included:

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

Example

The following sample code provides an example on how to create a time series table:

/**
 * 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)

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

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

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

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

References