Create a data view
Updated at:
When your business logic requires multi-layer nested statements in a DML statement, issues become difficult to locate and the statement grows hard to read. A data view lets you wrap a nested statement as a named, reusable unit so your DML statements stay concise and easier to debug.
A data view is a logical table that describes computing logic. It does not store physical data.
Syntax
CREATE TEMPORARY VIEW viewName
[( columnName [, columnName]* )]
AS queryStatement;
| Parameter | Description |
|---|---|
viewName |
The name of the view. |
columnName |
The name of a field in the view. Optional. |
queryStatement |
The nested statement that defines the view. |
Example
The following example wraps a source table query in a data view, then reads from the view in a DML statement instead of querying the source table directly.
-- Create a source table using the DataGen connector.
CREATE TEMPORARY TABLE datagen_source (
name VARCHAR,
score BIGINT
) WITH (
'connector' = 'datagen',
'number-of-rows' = '10'
);
-- Create a result table using the BlackHole connector.
CREATE TEMPORARY TABLE rds_output (
name VARCHAR,
score BIGINT
) WITH (
'connector' = 'blackhole'
);
-- Define a data view over the source table.
-- Encapsulate the selection logic here to keep the DML statement simple.
CREATE TEMPORARY VIEW tmp_view AS
SELECT *
FROM datagen_source;
-- Read from the view instead of the source table directly.
INSERT INTO rds_output
SELECT name, score
FROM tmp_view;
What's next
-
DROP VIEW
-
CREATE TEMPORARY TABLE
-
INSERT INTO
Is this page helpful?