Commit f08c9ff8 authored by Peter Eisentraut's avatar Peter Eisentraut

Make the CREATE TABLE ref page more readable and update some information.

parent e97fe98c
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.29 2001/10/12 00:07:14 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.30 2001/10/22 18:14:47 petere Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -161,15 +161,14 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ...@@ -161,15 +161,14 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
<para> <para>
<command>ALTER TABLE</command> changes the definition of an existing table. <command>ALTER TABLE</command> changes the definition of an existing table.
The <literal>ADD COLUMN</literal> form adds a new column to the table The <literal>ADD COLUMN</literal> form adds a new column to the table
using the same syntax as <xref linkend="SQL-CREATETABLE" using the same syntax as <xref linkend="SQL-CREATETABLE">.
endterm="SQL-CREATETABLE-title">.
The <literal>ALTER COLUMN SET/DROP DEFAULT</literal> forms The <literal>ALTER COLUMN SET/DROP DEFAULT</literal> forms
allow you to set or remove the default for the column. Note that defaults allow you to set or remove the default for the column. Note that defaults
only apply to subsequent <command>INSERT</command> commands; they do not only apply to subsequent <command>INSERT</command> commands; they do not
cause rows already in the table to change. cause rows already in the table to change.
The <literal>ALTER COLUMN SET STATISTICS</literal> form allows you to The <literal>ALTER COLUMN SET STATISTICS</literal> form allows you to
set the statistics-gathering target for subsequent set the statistics-gathering target for subsequent
<xref linkend="sql-analyze" endterm="sql-analyze-title"> operations. <xref linkend="sql-analyze"> operations.
The <literal>RENAME</literal> clause causes the name of a table or column The <literal>RENAME</literal> clause causes the name of a table or column
to change without changing any of the data contained in to change without changing any of the data contained in
the affected table. Thus, the table or column will the affected table. Thus, the table or column will
...@@ -177,7 +176,7 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ...@@ -177,7 +176,7 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
executed. executed.
The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause The ADD <replaceable class="PARAMETER">table constraint definition</replaceable> clause
adds a new constraint to the table using the same syntax as <xref adds a new constraint to the table using the same syntax as <xref
linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title">. linkend="SQL-CREATETABLE">.
The DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> clause The DROP CONSTRAINT <replaceable class="PARAMETER">constraint</replaceable> clause
drops all CHECK constraints on the table (and its children) that match <replaceable class="PARAMETER">constraint</replaceable>. drops all CHECK constraints on the table (and its children) that match <replaceable class="PARAMETER">constraint</replaceable>.
The OWNER clause changes the owner of the table to the user <replaceable class="PARAMETER"> The OWNER clause changes the owner of the table to the user <replaceable class="PARAMETER">
...@@ -205,18 +204,17 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable> ...@@ -205,18 +204,17 @@ ALTER TABLE <replaceable class="PARAMETER">table</replaceable>
You can use the <literal>SET DEFAULT</literal> form You can use the <literal>SET DEFAULT</literal> form
of <command>ALTER TABLE</command> to set the default later. of <command>ALTER TABLE</command> to set the default later.
(You may also want to update the already existing rows to the (You may also want to update the already existing rows to the
new default value, using <xref linkend="sql-update" new default value, using <xref linkend="sql-update">.)
endterm="sql-update-title">.)
</para> </para>
<para> <para>
Currently only CHECK constraints can be dropped from a table. The RESTRICT Currently only CHECK constraints can be dropped from a table. The RESTRICT
keyword is required, although dependencies are not checked. The CASCADE keyword is required, although dependencies are not checked. The CASCADE
option is unsupported. To remove a PRIMARY or UNIQUE constraint, drop the option is unsupported. To remove a PRIMARY or UNIQUE constraint, drop the
relevant index using the <xref linkend="SQL-DROPINDEX" endterm="SQL-DROPINDEX-TITLE"> command. relevant index using the <xref linkend="SQL-DROPINDEX"> command.
To remove FOREIGN KEY constraints you need to recreate To remove FOREIGN KEY constraints you need to recreate
and reload the table, using other parameters to the and reload the table, using other parameters to the
<xref linkend="SQL-CREATETABLE" endterm="SQL-CREATETABLE-title"> <xref linkend="SQL-CREATETABLE">
command. command.
</para> </para>
<para> <para>
......
This diff is collapsed.
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.7 2001/09/03 12:57:49 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table_as.sgml,v 1.8 2001/10/22 18:14:47 petere Exp $
Postgres documentation Postgres documentation
--> -->
<refentry id="SQL-CREATETABLEAS"> <refentry id="SQL-CREATETABLEAS">
<refmeta> <refmeta>
<refentrytitle id="SQL-CREATETABLEAS-TITLE"> <refentrytitle>CREATE TABLE AS</refentrytitle>
CREATE TABLE AS
</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo> <refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta> </refmeta>
<refnamediv> <refnamediv>
<refname> <refname>CREATE TABLE AS</refname>
CREATE TABLE AS <refpurpose>create a new table from the results of a query</refpurpose>
</refname>
<refpurpose>
create a new table from the results of a query
</refpurpose>
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
<refsynopsisdivinfo> <synopsis>
<date>2001-03-03</date> CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable>table_name</replaceable> [ (<replaceable>column_name</replaceable> [, ...] ) ]
</refsynopsisdivinfo> AS <replaceable>query</replaceable>
<synopsis>
CREATE [ TEMPORARY | TEMP ] TABLE <replaceable>table</replaceable> [ (<replaceable>column</replaceable> [, ...] ) ]
AS <replaceable>select_clause</replaceable>
</synopsis> </synopsis>
</refsynopsisdiv>
<refsect2> <refsect1>
<refsect2info> <refsect1info>
<date>1998-09-22</date> <date>2001-03-20</date>
</refsect2info> </refsect1info>
<title> <title>
Inputs Description
</title> </title>
<para> <para>
<command>CREATE TABLE AS</command> creates a table and fills it
with data computed by a <command>SELECT</command> command. The
table columns have the names and data types associated with the
output columns of the <command>SELECT</command> (except that you
can override the column names by giving an explicit list of new
column names).
</para>
<para>
<command>CREATE TABLE AS</command> bears some resemblance to
creating a view, but it is really quite different: it creates a new
table and evaluates the query just once to fill the new table
initially. The new table will not track subsequent changes to the
source tables of the query. In contrast, a view re-evaluates the
underlying <command>SELECT</command> statements whenever it is
queried.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>TEMPORARY or TEMP</term> <term><literal>[LOCAL] TEMPORARY</> or <literal>[LOCAL] TEMP</></term>
<listitem> <listitem>
<para> <para>
If specified, the table is created only within this session, and is If specified, the table is created as a temporary table.
automatically dropped on session exit. Temporary tables are automatically dropped at the end of a
Existing permanent tables with the same name are not visible session. Existing persistent tables with the same name are not
(in this session) while the temporary table exists. visible to the current session while the temporary table exists.
Any indexes created on a temporary table are automatically Any indexes created on a temporary table are automatically
temporary as well. temporary as well.
</para> </para>
<para>
The <literal>LOCAL</literal> word is optional.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><replaceable>table</replaceable></term> <term><replaceable>table_name</replaceable></term>
<listitem> <listitem>
<para> <para>
The name of the new table to be created. The name of the new table to be created. This table must not
This table must not already exist. However, a temporary table already exist. However, a temporary table can be created that
can be created that has the same name as an existing permanent has the same name as an existing permanent table.
table.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><replaceable>column</replaceable></term> <term><replaceable>column_name</replaceable></term>
<listitem> <listitem>
<para> <para>
The name of a column. Multiple column names can be specified using The name of a column in the new table. Multiple column names can
a comma-delimited list of column names. If column names are not be specified using a comma-delimited list of column names. If
provided, they are taken from the output column names of the column names are not provided, they are taken from the output
SELECT query. column names of the query.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><replaceable>select_clause</replaceable></term> <term><replaceable>query</replaceable></term>
<listitem> <listitem>
<para> <para>
A valid query statement. Refer to A query statement (that is, a <command>SELECT</command>
<xref linkend="sql-select" endterm="sql-select-title"> command). Refer to
<xref linkend="sql-select">
for a description of the allowed syntax. for a description of the allowed syntax.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
</para> </refsect1>
</refsect2>
<refsect2> <refsect1>
<refsect2info> <title>Diagnostics</title>
<date>1998-09-22</date>
</refsect2info>
<title>
Outputs
</title>
<para> <para>
Refer to Refer to <xref linkend="sql-createtable"> and
<xref linkend="sql-createtable" endterm="sql-createtable-title"> <xref linkend="sql-select">
and
<xref linkend="sql-select" endterm="sql-select-title">
for a summary of possible output messages. for a summary of possible output messages.
</para> </para>
</refsect2> </refsect1>
</refsynopsisdiv>
<refsect1> <refsect1>
<refsect1info> <title>Notes</title>
<date>2001-03-20</date>
</refsect1info>
<title>
Description
</title>
<para> <para>
<command>CREATE TABLE AS</command> creates a table and fills it This command is functionally equivalent to <xref
with data computed by a <command>SELECT</command> command. The linkend="sql-selectinto">, but it is preferred since it is less
table columns have the names and datatypes associated with the likely to be confused with other uses of the <command>SELECT
output columns of the <command>SELECT</command> (except that you ... INTO</command> syntax.
can override the <command>SELECT</command> column names by giving
an explicit list of column names).
</para> </para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para> <para>
<command>CREATE TABLE AS</command> bears some resemblance to creating This command is modeled after an <productname>Oracle</productname>
a view, but it is really quite different: it creates a new table and feature. There is no command with equivalent functionality in
evaluates the <command>SELECT</command> just once to fill the new table SQL92 or SQL99. However, a combination of <literal>CREATE
initially. The new table will not track subsequent changes to TABLE</literal> and <literal>INSERT ... SELECT</literal> can
the source tables of the <command>SELECT</command>. In contrast, accomplish the same thing with little more effort.
a view re-evaluates the given <command>SELECT</command> whenever queried.
</para> </para>
</refsect1>
<refsect1>
<title>History</title>
<para> <para>
This command is functionally equivalent to The <command>CREATE TABLE AS</command> command has been available
<xref linkend="sql-selectinto" endterm="sql-selectinto-title">, since <productname>PostgreSQL</productname> 6.3.
but it is preferred since it is less likely to be confused with
other uses of the <command>SELECT ... INTO</command> syntax.
</para> </para>
</refsect1> </refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-createtable"></member>
<member><xref linkend="sql-createview"></member>
<member><xref linkend="sql-select"></member>
<member><xref linkend="sql-selectinto"></member>
</simplelist>
</refsect1>
</refentry> </refentry>
<!-- Keep this comment at the end of the file <!-- Keep this comment at the end of the file
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.12 2001/09/23 13:34:44 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/select_into.sgml,v 1.13 2001/10/22 18:14:47 petere Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -89,7 +89,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be: ...@@ -89,7 +89,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
<para> <para>
All other inputs are described in detail for All other inputs are described in detail for
<xref linkend="sql-select" endterm="sql-select-title">. <xref linkend="sql-select">.
</para> </para>
</refsect2> </refsect2>
...@@ -103,9 +103,9 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be: ...@@ -103,9 +103,9 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
<para> <para>
Refer to Refer to
<xref linkend="sql-createtable" endterm="sql-createtable-title"> <xref linkend="sql-createtable">
and and
<xref linkend="sql-select" endterm="sql-select-title"> <xref linkend="sql-select">
for a summary of possible output messages. for a summary of possible output messages.
</para> </para>
</refsect2> </refsect2>
...@@ -128,7 +128,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be: ...@@ -128,7 +128,7 @@ where <replaceable class="PARAMETER">from_item</replaceable> can be:
<note> <note>
<para> <para>
<xref linkend="sql-createtableas" endterm="sql-createtableas-title"> <xref linkend="sql-createtableas">
is functionally equivalent to <command>SELECT INTO</command>. is functionally equivalent to <command>SELECT INTO</command>.
<command>CREATE TABLE AS</command> is the recommended syntax, since <command>CREATE TABLE AS</command> is the recommended syntax, since
<command>SELECT INTO</command> is not standard. In fact, this form of <command>SELECT INTO</command> is not standard. In fact, this form of
......
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/stylesheet.dsl,v 1.14 2001/10/09 18:46:00 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/stylesheet.dsl,v 1.15 2001/10/22 18:14:47 petere Exp $ -->
<!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN" [ <!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN" [
<!-- must turn on one of these with -i on the jade command line --> <!-- must turn on one of these with -i on the jade command line -->
...@@ -123,6 +123,16 @@ ...@@ -123,6 +123,16 @@
;;; XXX The above is very ugly. It might be better to run 'tidy' on ;;; XXX The above is very ugly. It might be better to run 'tidy' on
;;; the resulting *.html files. ;;; the resulting *.html files.
;; Format multiple terms in varlistentry vertically, instead
;; of comma-separated.
(element (varlistentry term)
(make sequence
(process-children-trim)
(if (not (last-sibling?))
(make empty-element gi: "BR")
(empty-sosofo))))
]]> <!-- %output-html --> ]]> <!-- %output-html -->
<![ %output-print; [ <![ %output-print; [
......
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