Manage views

Updated at:
Copy as MD

Views in AnalyticDB for PostgreSQL let you save frequently used or complex queries as named objects. A view has no physical storage — each time you reference it, the database runs the underlying query as a subquery.

Use views to:

  • Simplify complex joins or aggregations behind a stable, queryable name

  • Restrict access to specific rows or columns of a base table without duplicating data

  • Build query hierarchies by composing views from other views

Create a view

Run CREATE VIEW to create a view.

Example:

The following example creates a view that returns only food products from a products table:

CREATE VIEW myview AS SELECT * FROM products WHERE kind = 'food';

Query the view like a regular table:

SELECT * FROM myview;

Drop a view

Run DROP VIEW to remove a view:

DROP VIEW myview;

Limitations

  • ORDER BY and SORT clauses in a view definition are ignored when the view is queried.

References

For the full CREATE VIEW syntax and advanced options, see the Greenplum documentation.