Configuring Time to Live (TTL)
This section contains recipes for configuration of table's TTL with YQL.
Enabling TTL for an existing table
In the example below, the items of the mytable
table will be deleted an hour after the time set in the created_at
column:
ALTER TABLE `mytable` SET (TTL = Interval("PT1H") ON created_at);
Tip
An Interval
is created from a string literal in ISO 8601 format with some restrictions.
The example below shows how to use the modified_at
column with a numeric type (Uint32
) as a TTL column. The column value is interpreted as the number of seconds since the Unix epoch:
ALTER TABLE `mytable` SET (TTL = Interval("PT1H") ON modified_at AS SECONDS);
Enabling TTL for a newly created table
For a newly created table, you can pass TTL settings along with the table description:
CREATE TABLE `mytable` (
id Uint64,
expire_at Timestamp,
PRIMARY KEY (id)
) WITH (
TTL = Interval("PT0S") ON expire_at
);
Disabling TTL
ALTER TABLE `mytable` RESET (TTL);
Copied
Was the article helpful?
Previous
Next