ttlclickhouse

How do I use TTL on clickhouse table?


Reading documentation, i've found the TTL feature that is very userful for me. However, I can't construct valid SQL to engage it.

How do I do that:

CREATE TABLE t1 (
  name String, 
  date DateTime default now(),
  number UInt64 default 0 TTL date + INTERVAL 1 DAY 
) Engine MergeTree() ORDER BY name;

which gives error as follows:

Syntax error: failed at position 92 (line 4, col 27):
...[copy of my code here]
Expected one of: NOT, LIKE, AND, OR, IN, BETWEEN, COMMENT, CODEC, token, IS, NOT LIKE, NOT IN, GLOBAL IN, GLOBAL NOT IN, ClosingRoundBracket, Comma, QuestionMark

I've also tried to engage table-wide TTL:

CREATE TABLE t1 (
  name String, 
  date DateTime default now(),
  number UInt64 default 0  
) Engine MergeTree() ORDER BY name TTL date + INTERVAL 1 DAY;

Which lead to an error as well.

As far as I can see, I'm doing everything according to the documentation (https://clickhouse.yandex/docs/en/operations/table_engines/mergetree/#table_engine-mergetree-creating-a-table), but I still can't use this feature.

I'm using server version 19.5.3 revision 54417.

Please provide any examples or thoughts about how to use the TTL feature!


Solution

  • TTLs for tables and columns are net yet released, those will be available in 19.6.x. Documentation reflects the 'master' state of the art, not the latest release. This is certainly confusing. In order to see the particular release you may refer to documentation for particular major version, like this: https://clickhouse.yandex/docs/v19.5/en/operations/table_engines/mergetree/