MATERIALIZED in a CREATE VIEW statement
will make the view a materialized view.
CREATE MATERIALIZED VIEW Syntax
SELECT list. A new shard key can
be specified for the materialized view by using the
KI_SHARD_KEY(<column list>) pseudo-function in the SELECT list.
Parameters
OR REPLACE
OR REPLACE
Any existing table/view with the same name will be dropped before creating this
materialized view
TEMP
TEMP
The materialized view will be a memory-only table;
which, among other things, means it will not be persisted (if the database is restarted, the
materialized view will be removed), but it will have increased ingest performance
<schema name>
<schema name>
Name of the schema that will contain the created materialized view; if no schema is
specified, the materialized view will be created in the user’s
default schema
<view name>
<view name>
Name of the materialized view to create; must adhere to the supported
naming criteria
REFRESH
REFRESH
Specifies the data refresh scheme for the materialized view. The following schemes are
available:
| Constant | Description |
|---|---|
OFF | (the default) Will prevent the materialized view from being automatically refreshed, but will still allow manual refreshes of the data to be requested |
ON CHANGE | Will cause the materialized view to be updated any time a record is added, modified, or deleted from the subtending tables in its query |
ON QUERY | Will cause the materialized view to be updated any time it is queried |
EVERY | Allows specification of an interval in seconds, minutes, hours, or days, at which the materialized view should be refreshed. By default, the first refresh interval will be one interval’s worth of time from the point at which the materialized view creation was requested. This can be modified with the following options:
|
<select statement>
<select statement>
The query that will define both the structure and content of the created materialized view
WITH OPTIONS
WITH OPTIONS
Optional indicator that a comma-delimited list of connection option/value assignments will
follow. The following options are available:
| Option | Description |
|---|---|
EXECUTE AS | Executes materialized view refreshes as the given user with that user’s privileges, when EVERY … is specified as the REFRESH method. If this user doesn’t exist at the time of a refresh, the refresh will be executed as the creating user, and, failing that, the system administration user. |
<table property clause>
<table property clause>
Optional clause, assigning table properties, from a subset of those available, to the
materialized view
Table Property Clause
A subset of table properties can be applied to the materialized view at creation time. The supported Table Property Clause syntax & features are the same as those in the CREATE TABLE Table Property Clause.Changes-Only Views via Delta Tables
A materialized view can be configured to only show the changes in the query result since its last refresh. This applies strictly for inserts; updates and deletes will not be reflected in the view’s data. Using a materialized view to only show deltas in the result data can be achieved using theKI_HINT_DELTA_TABLE scoped hint. This hint should be
placed immediately after the table name (and before any table alias) of each
source table in the query that should be treated as a delta table—a table
which will contribute to the result set only those records added since the last
time the materialized view referencing it was refreshed.
The marked delta table must be a regular table—it cannot be any of the
following:
For instance, a changes-only materialized view weather_zone can be created
with its weather source table marked as a delta table in order to only
show new weather events since the last refresh of weather_zone:
Create Changes-Only Materialized View
Create Changes-Only Materialized View Output, Round 1
Create Changes-Only Materialized View Output, Round 2
Examples
To create a materialized view with columnsa, b, c, & d and a
new shard key on columns a & b, that refreshes once per half hour,
replacing a view with the same name as the target view, if it exists:
CREATE MATERIALIZED VIEW Example
CREATE MATERIALIZED VIEW Start/Stop Example
weather table and their locations from a static geo_zone table that have
occurred since the last time the materialized view weather_zone joining the
two data sets was refreshed:
CREATE MATERIALIZED VIEW Changes-Only Example