1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Inheritance overhaul by Chris Bitmead <chris@bitmead.com>

This commit is contained in:
Bruce Momjian
2000-06-09 01:44:34 +00:00
parent fb070464c1
commit 8c1d09d591
32 changed files with 484 additions and 204 deletions

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.12 2000/05/02 20:01:51 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.13 2000/06/09 01:43:55 momjian Exp $
-->
<chapter id="advanced">
@ -35,7 +35,7 @@ CREATE TABLE cities (
CREATE TABLE capitals (
state char(2)
) INHERITS (cities);
) UNDER cities;
</programlisting>
In this case, an instance of capitals <firstterm>inherits</firstterm> all
@ -60,38 +60,20 @@ CREATE TABLE capitals (
</para>
</note>
For example, the following query finds
all the cities that are situated at an attitude of 500ft or higher:
<programlisting>
SELECT name, altitude
FROM cities
WHERE altitude &gt; 500;
<para>
For example, the following query finds the names of all cities,
including state capitals, that are located at an altitude
over 500ft, the query is:
+----------+----------+
|name | altitude |
+----------+----------+
|Las Vegas | 2174 |
+----------+----------+
|Mariposa | 1953 |
+----------+----------+
</programlisting>
</para>
<para>
On the other hand, to find the names of all cities,
including state capitals, that are located at an altitude
over 500ft, the query is:
<programlisting>
SELECT c.name, c.altitude
FROM cities* c
<programlisting>
SELECT c.name, c.altitude
FROM cities c
WHERE c.altitude > 500;
</programlisting>
</programlisting>
which returns:
<programlisting>
which returns:
<programlisting>
+----------+----------+
|name | altitude |
+----------+----------+
@ -101,16 +83,50 @@ SELECT c.name, c.altitude
+----------+----------+
|Madison | 845 |
+----------+----------+
</programlisting>
</programlisting>
</para>
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 (<command>SELECT</command>,
<command>UPDATE</command> and <command>DELETE</command>)
support this inheritance notation using "*" as do other commands like
<command>ALTER</command>.
</para>
<para>
On the other hand, the following query finds
all the cities, but not capital cities
that are situated at an attitude of 500ft or higher:
<programlisting>
SELECT name, altitude
FROM ONLY cities
WHERE altitude &gt; 500;
+----------+----------+
|name | altitude |
+----------+----------+
|Las Vegas | 2174 |
+----------+----------+
|Mariposa | 1953 |
+----------+----------+
</programlisting>
</para>
Here the <quote>ONLY</quote> before cities indicates that the query should
be run over only cities and not classes below cities in the
inheritance hierarchy. Many of the commands that we
have already discussed -- <command>SELECT</command>,
<command>UPDATE</command> and <command>DELETE</command> --
support this <quote>ONLY</quote> notation.
</para>
<para>
Deprecated: In previous versions of postgres, the default was not to
get access to child classes. By experience this was found to be error
prone. Under the old syntax, to get the sub-classes you append "*"
to the table name. For example
<programlisting>
SELECT * from cities*;
</programlisting>
This old behaviour is still available by using a SET command...
<programlisting>
SET EXAMINE_SUBCLASS TO on;
</programlisting>
</para>
</sect1>
<sect1>