@@ -7,9 +7,11 @@ description:
77
88::: info
99
10- Materialized View support is now generally available (GA) and ready for production use.
10+ Materialized View support is now generally available (GA) and ready for
11+ production use.
1112
12- If you are using versions earlier than ` 8.3.1 ` , we suggest you upgrade at your earliest convenience.
13+ If you are using versions earlier than ` 8.3.1 ` , we suggest you upgrade at your
14+ earliest convenience.
1315
1416:::
1517
@@ -24,16 +26,19 @@ the [introduction](/docs/concept/mat-views/) and
2426
2527## Syntax
2628
27- To create a materialized view, manually enter the parameters and settings:
29+ The ` CREATE MATERIALIZED VIEW ` statement comes in two flavors: compact and full
30+ syntax. The compact syntax can be used when the default parameters are
31+ sufficient.
2832
29- ![ Flow chart showing the syntax of the CREATE MATERIALIZED VIEW keyword ] ( /images/docs/diagrams/createMatViewDef .svg )
33+ ![ Flow chart showing the syntax of the compact CREATE MATERIALIZED VIEW syntax ] ( /images/docs/diagrams/createMatViewCompactDef .svg )
3034
31- ::: tip
35+ For more on the semantics of the compact syntax, see the
36+ [ materialized view guide] ( /docs/guides/mat-views/#compact-syntax ) .
3237
33- For simple materialized views , you can alternatively use the
34- [ compact syntax ] ( #compact-syntax ) .
38+ To create a materialized view with full syntax , you need to enter the following
39+ parameters and settings:
3540
36- :::
41+ ![ Flow chart showing the syntax of the CREATE MATERIALIZED VIEW keyword ] ( /images/docs/diagrams/createMatViewDef.svg )
3742
3843## Metadata
3944
@@ -63,14 +68,13 @@ Now we can create a materialized view holding aggregated data from the base
6368table:
6469
6570``` questdb-sql title="Hourly materialized view"
66- CREATE MATERIALIZED VIEW trades_hourly_prices AS (
67- SELECT
68- timestamp,
69- symbol,
70- avg(price) AS avg_price
71- FROM trades
72- SAMPLE BY 1h
73- ) PARTITION BY HOUR;
71+ CREATE MATERIALIZED VIEW trades_hourly_prices AS
72+ SELECT
73+ timestamp,
74+ symbol,
75+ avg(price) AS avg_price
76+ FROM trades
77+ SAMPLE BY 1h;
7478```
7579
7680Now, we've created a materialized view that will be automatically refreshed each
@@ -96,17 +100,15 @@ one of them as the base table.
96100
97101``` questdb-sql title="Hourly materialized view with LT JOIN"
98102CREATE MATERIALIZED VIEW trades_ext_hourly_prices
99- WITH BASE trades
100- AS (
101- SELECT
102- t.timestamp,
103- t.symbol,
104- avg(t.price) AS avg_price,
105- avg(e.price) AS avg_ext_price
106- FROM trades t
107- LT JOIN ext_trades e ON (symbol)
108- SAMPLE BY 1d
109- ) PARTITION BY WEEK;
103+ WITH BASE trades AS
104+ SELECT
105+ t.timestamp,
106+ t.symbol,
107+ avg(t.price) AS avg_price,
108+ avg(e.price) AS avg_ext_price
109+ FROM trades t
110+ LT JOIN ext_trades e ON (symbol)
111+ SAMPLE BY 1d;
110112```
111113
112114## Partitioning
@@ -156,7 +158,7 @@ depending on your needs.
156158
157159### Examples
158160
159- ``` questdb-sql title="Creating a materialized view with TTL"
161+ ``` questdb-sql title="Creating a materialized view with PARTITION BY and TTL"
160162CREATE MATERIALIZED VIEW trades_hourly_prices AS (
161163 SELECT
162164 timestamp,
@@ -174,14 +176,13 @@ An optional `IF NOT EXISTS` clause may be added directly after the
174176created only if a view with the desired view name does not already exist.
175177
176178``` questdb-sql
177- CREATE MATERIALIZED VIEW IF NOT EXISTS trades_weekly_prices AS (
178- SELECT
179- timestamp,
180- symbol,
181- avg(price) AS avg_price
182- FROM trades
183- SAMPLE BY 7d
184- ) PARTITION BY YEAR;
179+ CREATE MATERIALIZED VIEW IF NOT EXISTS trades_weekly_prices AS
180+ SELECT
181+ timestamp,
182+ symbol,
183+ avg(price) AS avg_price
184+ FROM trades
185+ SAMPLE BY 7d;
185186```
186187
187188## Materialized view names
@@ -214,26 +215,6 @@ CREATE MATERIALIZED VIEW trades_hourly_prices AS (
214215OWNED BY analysts;
215216```
216217
217- ## Compact syntax
218-
219- The ` CREATE MATERIALIZED VIEW ` statement also supports a compact syntax which
220- can be used when the default parameters are sufficient.
221-
222- ![ Flow chart showing the syntax of the compact CREATE MATERIALIZED VIEW syntax] ( /images/docs/diagrams/createMatViewCompactDef.svg )
223-
224- ``` questdb-sql
225- CREATE MATERIALIZED VIEW trades_hourly_prices AS
226- SELECT
227- timestamp,
228- symbol,
229- avg(price) AS avg_price
230- FROM trades
231- SAMPLE BY 1h;
232- ```
233-
234- For more on the semantics of the compact syntax, see the
235- [ materialized view guide] ( /docs/guides/mat-views/#compact-syntax ) .
236-
237218## SYMBOL column capacity
238219
239220By default, SYMBOL column capacities in a materialized view are set to the same
0 commit comments