Postgresql 中文操作指南
3.2. Views #
参考 Section 2.6中的查询。假设天气记录和城市位置的组合列表对你的应用程序特别重要,但你不想在每次需要时都键入查询。你可以在该查询上创建一个 view,为可以像普通表一样引用的查询命名:
Refer back to the queries in Section 2.6. Suppose the combined listing of weather records and city location is of particular interest to your application, but you do not want to type the query each time you need it. You can create a view over the query, which gives a name to the query that you can refer to like an ordinary table:
CREATE VIEW myview AS
SELECT name, temp_lo, temp_hi, prcp, date, location
FROM weather, cities
WHERE city = name;
SELECT * FROM myview;
充分利用视图是良好的 SQL 数据库设计的一个关键方面。视图允许您将表的结构细节(随着应用程序的发展可能会发生变化)封装在一致的接口之后。
Making liberal use of views is a key aspect of good SQL database design. Views allow you to encapsulate the details of the structure of your tables, which might change as your application evolves, behind consistent interfaces.
视图几乎可以在使用真实表的所有地方使用。在其他视图上构建视图并不少见。
Views can be used in almost any place a real table can be used. Building views upon other views is not uncommon.