1 ---------------------------------------------------------------------------
4 -- Tutorial on advanced more PostgreSQL features
7 -- Copyright (c) 1994, Regents of the University of California
11 ---------------------------------------------------------------------------
13 -----------------------------
15 -- A table can inherit from zero or more tables. A query can reference
16 -- either all rows of a table or all rows of a table plus all of its
18 -----------------------------
20 -- For example, the capitals table inherits from cities table. (It inherits
21 -- all data fields from cities.)
26 altitude int -- (in ft)
29 CREATE TABLE capitals (
33 -- Now, let's populate the tables.
34 INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63);
35 INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174);
36 INSERT INTO cities VALUES ('Mariposa', 1200, 1953);
38 INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA');
39 INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI');
42 SELECT * FROM capitals;
44 -- You can find all cities, including capitals, that
45 -- are located at an altitude of 500 ft or higher by:
47 SELECT c.name, c.altitude
49 WHERE c.altitude > 500;
51 -- To scan rows of the parent table only, use ONLY:
58 -- clean up (you must remove the children first)