]> begriffs open source - ai-pg/blob - full-docs/txt/tutorial-views.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / tutorial-views.txt
1
2 3.2. Views #
3
4    Refer back to the queries in Section 2.6. Suppose the combined listing
5    of weather records and city location is of particular interest to your
6    application, but you do not want to type the query each time you need
7    it. You can create a view over the query, which gives a name to the
8    query that you can refer to like an ordinary table:
9 CREATE VIEW myview AS
10     SELECT name, temp_lo, temp_hi, prcp, date, location
11         FROM weather, cities
12         WHERE city = name;
13
14 SELECT * FROM myview;
15
16    Making liberal use of views is a key aspect of good SQL database
17    design. Views allow you to encapsulate the details of the structure of
18    your tables, which might change as your application evolves, behind
19    consistent interfaces.
20
21    Views can be used in almost any place a real table can be used.
22    Building views upon other views is not uncommon.