Overview

CREATE [ OR REPLACE ] VIEW view_name AS query

Description

Creates a view. A view is a logic table that does not contain any data. It can be referenced by queries. The statement that defines a view is executed each time a query references the view.

You can use the OR REPLACE clause to suppress the error that is reported when the view already exists.

Example

--- Create a simple view.
CREATE VIEW test AS
SELECT orderkey, orderstatus, totalprice / 2 AS half
FROM orders
--- Create a view by using an aggregate function.
CREATE VIEW orders_by_date AS
SELECT orderdate, sum(totalprice) AS price
FROM orders
GROUP BY orderdate
--- Create a view, or replace a view if it already exists.
CREATE OR REPLACE VIEW test AS
SELECT orderkey, orderstatus, totalprice / 4 AS quarter
FROM orders