Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.
Having covered the basics of using
PostgresSQL to
access your data, we will now discuss those features of
Postgres that distinguish it from conventional data
managers. These features include inheritance, time
travel and non-atomic data values (array- and
set-valued attributes).
Examples in this section can also be found in
advance.sql in the tutorial directory.
(Refer to Chapter 5 for how to use it.)
Let's create two classes. The capitals class contains
state capitals which are also cities. Naturally, the
capitals class should inherit from cities.
CREATE TABLE cities (
name text,
population float,
altitude int -- (in ft)
);
CREATE TABLE capitals (
state char(2)
) INHERITS (cities);
In this case, an instance of capitals inherits all
attributes (name, population, and altitude) from its
parent, cities. The type of the attribute name is
text, a native Postgres
type for variable length
ASCII strings. The type of the attribute population is
float, a native Postgres
type for double precision
floating point numbers. State capitals have an extra
attribute, state, that shows their state.
In Postgres,
a class can inherit from zero or more other classes,
and a query can reference either all instances of a
class or all instances of a class plus all of its
descendants.
Note: The inheritance hierarchy is a directed acyclic graph.
For example, the following query finds
all the cities that are situated at an attitude of 500ft or higher:
Here the "*" after cities indicates that the query should
be run over cities and all classes below cities in the
inheritance hierarchy. Many of the commands that we
have already discussed (SELECT,
UPDATE and DELETE)
support this inheritance notation using "*" as do other commands like
ALTER.