Skip to main content

Table TTL

https://clickhouse.com/docs/sql-reference/functions/date-time-functions


Precise TTL

TTL is relative to the exact datetime (e.g., 2025-06-05 15:42:30).

1 month - varying days
ALTER TABLE journal.otel_logs
MODIFY TTL toDateTime(Timestamp) + toIntervalMonth(1);
7 days
ALTER TABLE default.otel_logs
MODIFY TTL toDateTime(Timestamp) + toIntervalDay(7);
12 hours
ALTER TABLE journal.otel_logs
MODIFY TTL toDateTime(Timestamp) + toIntervalHour(12);

Aligned TTL

TTL is relative to the calendar date (e.g., 00:00, 12:00)

Start of month
ALTER TABLE journal.otel_logs
MODIFY TTL toStartOfMonth(Timestamp) + toIntervalMonth(1);
Start of day
ALTER TABLE journal.otel_logs
MODIFY TTL toStartOfDay(Timestamp) + toIntervalDay(1);
12:00
ALTER TABLE journal.otel_logs
MODIFY TTL toStartOfDay(Timestamp) + toIntervalHour(12);