CREATE VIEW (Create View)

Last updated: 2026-11-04

CREATE VIEW (Create View)

CREATE VIEW saves a query as a reusable virtual table. A view stores no data of its own: each query expands it back into the underlying SQL, which makes views a natural way to narrow privileges, hide table structure, or reuse a complex query. A materialized view is the opposite — it stores the result and must be explicitly refreshed.

Kindcommand
Example LanguageSQL

📝 Syntax

CREATE [OR REPLACE] [TEMP] [RECURSIVE] VIEW <view name> [(<column>, ...)]
AS <query>
[WITH [CASCADED | LOCAL] CHECK OPTION]

⚙️ Parameters

OR REPLACEReplaces the definition when the view already exists
ASThe query that defines the view
CHECK OPTIONBlocks writes that violate the view's condition
TEMPCreates a temporary view that dies with the session

Returns:No return value. Once it succeeds the view can be queried like a table.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

DROP TABLE
DROP VIEW
CREATE TABLE
INSERT 0 3
CREATE VIEW
region | orders | total 
-------+--------+-------
east   |      2 | 350.50
west   |      1 | 300.00

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QShould I use a view or a materialized view?
AUse a view for small data sets that must reflect the latest rows; use a materialized view when the aggregation is expensive and slightly stale data is acceptable.
QCan a view take parameters?
ANo. The query is fixed at definition time; for parameters, write a function returning a table (RETURNS TABLE).
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏