This topic describes how to use the Tablestore CLI to perform operations on a time series table. For example, you can use the Tablestore CLI to create, use, update, and delete a time series table. You can also use the Tablestore CLI to view information about a time series table and query the names of time series tables.
For more information about the TimeSeries model, see Overview.
Create a time series table
Create a time series table for which the time to live (TTL) value is specified.
Command syntax
create -m mode -t tableName --ttl timeToLive
The following table describes the parameters that you can configure to create a time series table.
Parameter | Required | Example | Description |
-m, --model | Yes | timeseries | The type of the table that you want to create. Default value: widecolumn. Valid values:
|
-t, --table | Yes | mytable | The name of the time series table. |
--ttl | No | 864000 | The TTL of the data in the time series table. Unit: seconds. The default value is -1, which specifies that the data never expires. If the system detects that the difference between the current time and the time column that is passed to the table exceeds the specified TTL value, the system automatically deletes the expired data. Important In a time series table, the system determines the time when the data is generated based on the time column that is passed to the table, not based on the time when the data is written to the table. The value of this parameter must be -1, or greater than or equal to 86400 (1 day). A value of -1 specifies that the data never expires. |
Examples
Create a time series table named mytable in which the data never expires.
create -m timeseries -t mytable --ttl -1
Use a time series table
Select the table on which you want to perform table operations or data operations.
Command syntax
use --ts -t tableName
The following table describes the parameters that you must configure to use a time series table.
Parameter | Required | Example | Description |
--ts | Yes | N/A | Specifies that the table you want to use is a time series table. |
-t, --table | Yes | mytable | The name of the time series table. |
Examples
Use a time series table named mytable.
use --ts -t mytable
Update a time series table
Modify the TTL configuration of a time series table.
Command syntax
alter --ttl timeToLive --ts
The following table describes the parameters that you must configure to update a time series table.
Parameter | Required | Example | Description |
--ts | Yes | N/A | Specifies that the table whose TTL configuration you want to modify is a time series table. |
--ttl | Yes | 864000 | The TTL of the data in the time series table. Unit: seconds. The default value is -1, which specifies that the data never expires. If the system detects that the difference between the current time and the time column that is passed to the table exceeds the specified TTL value, the system automatically deletes the expired data. Important In a time series table, the system determines the time when the data is generated based on the time column that is passed to the table, not based on the time when the data is written to the table. The value of this parameter must be -1, or greater than or equal to 86400 (1 day). A value of -1 specifies that the data never expires. |
Examples
Set the TTL value of the current table to 86400 seconds.
alter --ttl 86400 --ts
Query the information about a time series table
Query the information about a time series table.
Command syntax
desc --ts -t tableName
The following table describes the parameters that you can configure to query the information about a time series table.
Parameter | Required | Example | Description |
--ts | No | N/A | Specifies that the table whose information you want to query is a time series table. |
-t,--table | No | mytable | The name of the time series table. This parameter is optional. |
-f,--print_format | No | json | The output format of information about the table. Default value: json. Valid values: json and table. |
-o, --output | No | /tmp/describe_table_meta.json | The path of the local JSON file in which the information about the time series table is stored. |
Examples
Query the information about the current table.
desc
Query the information about a time series table named mytable.
desc --ts -t mytable
Delete a time series table
Delete a time series table that you no longer need.
Command syntax
drop -t tableName --ts -y
The following table describes the parameters that you must configure to delete a time series table.
Parameter | Required | Example | Description |
-t, --table | Yes | mytable | The name of the time series table. |
-y, --yes | Yes | N/A | Specifies that the confirmation information is displayed. This parameter is required. |
--ts | Yes | N/A | Specifies that the table you want to delete is a time series table. |
Examples
Delete a time series table named mytable.
drop -t mytable --ts -y
List the names of tables
List the names of all tables, all data tables, or all time series tables in an instance.
List the names of all tables of the same type as the current table
list
List the names of all tables
list -a
List the names of all data tables
list -w
List the names of all time series tables
list -t
The following table describes the parameters that you can configure to list tables.
Parameter | Required | Example | Description |
-a, --all | No | N/A | Lists the names of all tables. |
-d, --detail | No | N/A | Lists the details about the tables. |
-w, --wc | No | N/A | Lists the names of all data tables. |
-t, --ts | No | N/A | Lists the names of all time series tables. |