Commit c9ff1a5a authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Update references to char2 type by using char(2).

Thanks to Garr Updegraff <garru@uci.edu> for the tip.
parent f11bdb9d
This diff is collapsed.
<Chapter Id="inherit">
<Title>Inheritance</Title>
<chapter id="inherit">
<title>Inheritance</title>
<Para>
Let's create two classes. The capitals class contains
state capitals which are also cities. Naturally, the
capitals class should inherit from cities.
<ProgramListing>
<para>
Let's create two classes. The capitals class contains
state capitals which are also cities. Naturally, the
capitals class should inherit from cities.
<programlisting>
CREATE TABLE cities (
name text,
population float,
altitude int -- (in ft)
altitude int -- (in ft)
);
CREATE TABLE capitals (
state char2
state char(2)
) INHERITS (cities);
</ProgramListing>
</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
<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
floating point numbers. State capitals have an extra
attribute, 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
descendants.
<note>
<para>
The inheritance hierarchy is a actually a directed acyclic graph.
</para>
</note>
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
<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
floating point numbers. State capitals have an extra
attribute, 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
descendants.
<Note>
<Para>
The inheritance hierarchy is a actually a directed acyclic graph.
</Para>
</Note>
For example, the following query finds
all the cities that are situated at an attitude of 500ft or higher:
<ProgramListing>
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;
......@@ -50,23 +52,23 @@ SELECT name, altitude
+----------+----------+
|Mariposa | 1953 |
+----------+----------+
</ProgramListing>
</para>
</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:
<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>
<programlisting>
SELECT c.name, c.altitude
FROM cities* c
WHERE c.altitude > 500;
</ProgramListing>
</programlisting>
which returns:
which returns:
<ProgramListing>
<programlisting>
+----------+----------+
|name | altitude |
+----------+----------+
......@@ -76,13 +78,31 @@ SELECT c.name, c.altitude
+----------+----------+
|Madison | 845 |
+----------+----------+
</ProgramListing>
</programlisting>
Here the <Quote>*</Quote> 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 <Quote>*</Quote> notation, as do others, like <Command>alter</Command>.
</Para>
Here the <quote>*</quote> 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 <quote>*</quote> notation, as do others, like
<command>ALTER TABLE</command>.
</para>
</chapter>
</Chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"./reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
......@@ -737,14 +737,14 @@
As an example:
<programlisting>
PgDatabase data;
data.Exec("create table foo (a int4, b char16, d float8)");
data.Exec("copy foo from stdin");
data.putline("3\etHello World\et4.5\en");
data.putline("4\etGoodbye World\et7.11\en");
&amp;...
data.putline(".\en");
data.endcopy();
PgDatabase data;
data.Exec("create table foo (a int4, b char(16), d float8)");
data.Exec("copy foo from stdin");
data.putline("3\etHello World\et4.5\en");
data.putline("4\etGoodbye World\et7.11\en");
&amp;...
data.putline(".\en");
data.endcopy();
</programlisting>
</para>
</sect1>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment