From c5e5a0e78661fce99779877b4ad8f520c4b21cfe Mon Sep 17 00:00:00 2001 From: PedroHenrique0713 Date: Fri, 10 Jul 2026 22:31:48 -0300 Subject: [PATCH] docs: cover TTL on materialized views in the TTL concept page The TTL concept page only documented TTL for tables under "Setting TTL", while materialized views were mentioned only in the Enterprise caution. Add a subsection showing TTL at view creation and on an existing view, linking the canonical CREATE MATERIALIZED VIEW and ALTER MATERIALIZED VIEW SET TTL references. Closes #275 --- documentation/concepts/ttl.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/documentation/concepts/ttl.md b/documentation/concepts/ttl.md index 8620df238..9c1ee9f40 100644 --- a/documentation/concepts/ttl.md +++ b/documentation/concepts/ttl.md @@ -71,6 +71,25 @@ ALTER TABLE trades SET TTL 2w; For full syntax, see [ALTER TABLE SET TTL](/docs/query/sql/alter-table-set-ttl/). +### On materialized views + +Materialized views support TTL as well, both at creation and afterward: + +```questdb-sql +-- At view creation +CREATE MATERIALIZED VIEW trades_hourly AS ( + SELECT timestamp, symbol, avg(price) AS avg_price FROM trades SAMPLE BY 1h +) PARTITION BY DAY TTL 7 DAYS; + +-- On an existing view +ALTER MATERIALIZED VIEW trades_hourly SET TTL 7 DAYS; +``` + +A view's TTL is independent of its base table's TTL. For full syntax, see +[CREATE MATERIALIZED VIEW](/docs/query/sql/create-mat-view/#ttl-time-to-live) +and +[ALTER MATERIALIZED VIEW SET TTL](/docs/query/sql/alter-mat-view-set-ttl/). + ## How TTL works TTL drops partitions based on the **partition's time range**, not individual row