mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Terminology cleanup: class -> table, instance -> row, attribute -> column,
etc.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.20 2001/01/05 06:34:15 tgl Exp $
|
||||
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.21 2001/01/13 23:58:55 petere Exp $
|
||||
-->
|
||||
|
||||
<chapter id="advanced">
|
||||
@ -22,14 +22,14 @@ $Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.20 2001/01/05 06:34:15 tg
|
||||
<title>Inheritance</title>
|
||||
|
||||
<para>
|
||||
Let's create two classes. The capitals class contains
|
||||
Let's create two tables. The capitals table contains
|
||||
state capitals that are also cities. Naturally, the
|
||||
capitals class should inherit from cities.
|
||||
capitals table should inherit from cities.
|
||||
|
||||
<programlisting>
|
||||
CREATE TABLE cities (
|
||||
name text,
|
||||
population float,
|
||||
population real,
|
||||
altitude int -- (in ft)
|
||||
);
|
||||
|
||||
@ -38,20 +38,19 @@ CREATE TABLE capitals (
|
||||
) INHERITS (cities);
|
||||
</programlisting>
|
||||
|
||||
In this case, an instance of capitals <firstterm>inherits</firstterm> all
|
||||
attributes (name, population, and altitude) from its
|
||||
parent, cities. The type of the attribute name is
|
||||
In this case, a row of capitals <firstterm>inherits</firstterm> all
|
||||
columns (name, population, and altitude) from its
|
||||
parent, cities. The type of the column name is
|
||||
<type>text</type>, a native <productname>Postgres</productname>
|
||||
type for variable length
|
||||
ASCII strings. The type of the attribute population is
|
||||
<type>float</type>, a native <productname>Postgres</productname>
|
||||
type for double precision
|
||||
ASCII strings. The type of the column population is
|
||||
<type>real</type>, a type for single precision
|
||||
floating point numbers. State capitals have an extra
|
||||
attribute, state, that shows their state.
|
||||
column, state, that shows their state.
|
||||
In <productname>Postgres</productname>,
|
||||
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
|
||||
a table can inherit from zero or more other tables,
|
||||
and a query can reference either all rows of a
|
||||
table or all rows of a tables plus all of its
|
||||
descendants.
|
||||
|
||||
<note>
|
||||
@ -109,7 +108,7 @@ SELECT name, altitude
|
||||
|
||||
<para>
|
||||
Here the <quote>ONLY</quote> before cities indicates that the query should
|
||||
be run over only the cities table, and not classes below cities in the
|
||||
be run over only the cities table, and not tables 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> --
|
||||
@ -122,7 +121,7 @@ SELECT name, altitude
|
||||
In previous versions of <productname>Postgres</productname>, the
|
||||
default was not to get access to child tables. This was found to
|
||||
be error prone and is also in violation of SQL99. Under the old
|
||||
syntax, to get the sub-classes you append "*" to the table name.
|
||||
syntax, to get the sub-tables you append "*" to the table name.
|
||||
For example
|
||||
<programlisting>
|
||||
SELECT * from cities*;
|
||||
@ -147,11 +146,11 @@ SET SQL_Inheritance TO OFF;
|
||||
|
||||
<para>
|
||||
One of the tenets of the relational model is that the
|
||||
attributes of a relation are atomic.
|
||||
columns of a table are atomic.
|
||||
<productname>Postgres</productname> does not
|
||||
have this restriction; attributes can themselves contain
|
||||
have this restriction; columns can themselves contain
|
||||
sub-values that can be accessed from the query
|
||||
language. For example, you can create attributes that
|
||||
language. For example, you can create columns that
|
||||
are arrays of base types.
|
||||
</para>
|
||||
|
||||
@ -159,26 +158,26 @@ SET SQL_Inheritance TO OFF;
|
||||
<title>Arrays</title>
|
||||
|
||||
<para>
|
||||
<productname>Postgres</productname> allows attributes of an
|
||||
instance to be defined
|
||||
<productname>Postgres</productname> allows columns of a
|
||||
row to be defined
|
||||
as fixed-length or variable-length multi-dimensional
|
||||
arrays. Arrays of any base type or user-defined type
|
||||
can be created. To illustrate their use, we first create a
|
||||
class with arrays of base types.
|
||||
table with arrays of base types.
|
||||
|
||||
<programlisting>
|
||||
CREATE TABLE SAL_EMP (
|
||||
name text,
|
||||
pay_by_quarter int4[],
|
||||
pay_by_quarter integer[],
|
||||
schedule text[][]
|
||||
);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The above query will create a class named SAL_EMP with
|
||||
The above query will create a table named SAL_EMP with
|
||||
a <firstterm>text</firstterm> string (name), a one-dimensional
|
||||
array of <firstterm>int4</firstterm>
|
||||
array of <firstterm>integer</firstterm>
|
||||
(pay_by_quarter), which represents the employee's
|
||||
salary by quarter and a two-dimensional array of
|
||||
<firstterm>text</firstterm>
|
||||
|
Reference in New Issue
Block a user