Skip to content

Commit d599807

Browse files
amanomergatorsmile
andcommitted
[SPARK-28795][DOC][SQL] Document CREATE VIEW statement in SQL Reference
### What changes were proposed in this pull request? Added document for CREATE VIEW command. ### Why are the changes needed? As a reference to syntax and examples of CREATE VIEW command. ### How was this patch tested? Documentation update. Verified manually. Closes #25543 from amanomer/spark-28795. Lead-authored-by: aman_omer <amanomer1996@gmail.com> Co-authored-by: Xiao Li <gatorsmile@gmail.com> Co-authored-by: Aman Omer <amanomer1996@gmail.com> Signed-off-by: Xiao Li <gatorsmile@gmail.com>
1 parent b83304f commit d599807

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

docs/sql-ref-syntax-ddl-create-view.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,64 @@ license: |
1919
limitations under the License.
2020
---
2121

22-
**This page is under construction**
22+
### Description
23+
Views are based on the result-set of an `SQL` query. `CREATE VIEW` constructs
24+
a virtual table that has no physical data therefore other operations like
25+
`ALTER VIEW` and `DROP VIEW` only change metadata.
26+
27+
### Syntax
28+
{% highlight sql %}
29+
CREATE [OR REPLACE] [[GLOBAL] TEMPORARY] VIEW [IF NOT EXISTS] [db_name.]view_name
30+
create_view_clauses
31+
AS query;
32+
{% endhighlight %}
33+
34+
### Parameters
35+
<dl>
36+
<dt><code><em>OR REPLACE</em></code></dt>
37+
<dd>If a view of same name already exists, it will be replaced.</dd>
38+
</dl>
39+
<dl>
40+
<dt><code><em>[GLOBAL] TEMPORARY</em></code></dt>
41+
<dd>TEMPORARY views are session-scoped and will be dropped when session ends
42+
because it skips persisting the definition in the underlying metastore, if any.
43+
GLOBAL TEMPORARY views are tied to a system preserved temporary database `global_temp`.</dd>
44+
</dl>
45+
<dl>
46+
<dt><code><em>IF NOT EXISTS</em></code></dt>
47+
<dd>Creates a view if it does not exists.</dd>
48+
</dl>
49+
<dl>
50+
<dt><code><em>create_view_clauses</em></code></dt>
51+
<dd>These clauses are optional and order insensitive. It can be of following formats.
52+
<ul>
53+
<li><code>[(column_name [COMMENT column_comment], ...) ]</code> to specify column-level comments.</li>
54+
<li><code>[COMMENT view_comment]</code> to specify view-level comments.</li>
55+
<li><code>[TBLPROPERTIES (property_name = property_value, ...)]</code> to add metadata key-value pairs.</li>
56+
</ul>
57+
</dd>
58+
</dl>
59+
<dl>
60+
<dt><code><em>query</em></code></dt>
61+
<dd>A <a href="sql-ref-syntax-qry-select.md">SELECT</a> statement that constructs the view from base tables or other views.</dd>
62+
</dl>
63+
64+
### Examples
65+
{% highlight sql %}
66+
-- Create or replace view for `experienced_employee` with comments.
67+
CREATE OR REPLACE VIEW experienced_employee
68+
(ID COMMENT 'Unique identification number', Name)
69+
COMMENT 'View for experienced employees'
70+
AS SELECT id, name FROM all_employee
71+
WHERE working_years > 5;
72+
73+
-- Create a global temporary view `subscribed_movies` if it does not exist.
74+
CREATE GLOBAL TEMPORARY VIEW IF NOT EXISTS subscribed_movies
75+
AS SELECT mo.member_id, mb.full_name, mo.movie_title
76+
FROM movies AS mo INNER JOIN members AS mb
77+
ON mo.member_id = mb.id;
78+
{% endhighlight %}
79+
80+
### Related Statements
81+
- [ALTER VIEW](sql-ref-syntax-ddl-alter-view.md)
82+
- [DROP VIEW](sql-ref-syntax-ddl-drop-view.md)

0 commit comments

Comments
 (0)