summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorPeter Eisentraut2010-09-26 11:41:03 +0000
committerPeter Eisentraut2010-09-26 11:41:03 +0000
commite440e12c562432a2a695b8054964fb34e3bd823e (patch)
tree9f075dbc9e292746f81390f0f44803090bf73d07 /doc/src
parent899beb78941aa955aac2e19cb82458c6f4c7dd52 (diff)
Add ALTER TYPE ... ADD/DROP/ALTER/RENAME ATTRIBUTE
Like with tables, this also requires allowing the existence of composite types with zero attributes. reviewed by KaiGai Kohei
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/alter_type.sgml130
-rw-r--r--doc/src/sgml/ref/create_type.sgml22
-rw-r--r--doc/src/sgml/ref/drop_type.sgml4
3 files changed, 143 insertions, 13 deletions
diff --git a/doc/src/sgml/ref/alter_type.sgml b/doc/src/sgml/ref/alter_type.sgml
index d76feb48c30..315922ea836 100644
--- a/doc/src/sgml/ref/alter_type.sgml
+++ b/doc/src/sgml/ref/alter_type.sgml
@@ -23,9 +23,17 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
-ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
+ALTER TYPE <replaceable class="PARAMETER">name</replaceable> <replaceable class="PARAMETER">action</replaceable> [, ... ]
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
+ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> TO <replaceable class="PARAMETER">new_attribute_name</replaceable>
+ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
+
+<phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
+
+ ADD ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable>
+ DROP ATTRIBUTE [ IF EXISTS ] <replaceable class="PARAMETER">attribute_name</replaceable>
+ ALTER ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> [ SET DATA ] TYPE <replaceable class="PARAMETER">data_type</replaceable>
</synopsis>
</refsynopsisdiv>
@@ -34,6 +42,76 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replace
<para>
<command>ALTER TYPE</command> changes the definition of an existing type.
+ There are several subforms:
+
+ <variablelist>
+ <varlistentry>
+ <term><literal>ADD ATTRIBUTE</literal></term>
+ <listitem>
+ <para>
+ This form adds a new attribute to a composite type, using the same syntax as
+ <xref linkend="SQL-CREATETYPE">.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>DROP ATTRIBUTE [ IF EXISTS ]</literal></term>
+ <listitem>
+ <para>
+ This form drops an attribute from a composite type.
+ If <literal>IF EXISTS</literal> is specified and the attribute
+ does not exist, no error is thrown. In this case a notice
+ is issued instead.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>SET DATA TYPE</literal></term>
+ <listitem>
+ <para>
+ This form changes the type of an attribute of a composite type.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>OWNER</literal></term>
+ <listitem>
+ <para>
+ This form changes the owner of the type.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>RENAME</literal></term>
+ <listitem>
+ <para>
+ This form changes the name of the type or the name of an
+ individual attribute of a composite type.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>SET SCHEMA</literal></term>
+ <listitem>
+ <para>
+ This form moves the type into another schema.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </para>
+
+ <para>
+ The <literal>ADD ATTRIBUTE</literal>, <literal>DROP
+ ATTRIBUTE</literal>, and <literal>ALTER ATTRIBUTE</literal> actions
+ can be combined into a list of multiple alterations to apply in
+ parallel. For example, it is possible to add several attributes
+ and/or alter the type of several attributes in a single command.
</para>
<para>
@@ -90,6 +168,34 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replace
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><replaceable class="PARAMETER">attribute_name</replaceable></term>
+ <listitem>
+ <para>
+ The name of the attribute to add, alter, or drop.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="PARAMETER">new_attribute_name</replaceable></term>
+ <listitem>
+ <para>
+ The new name of the attribute begin renamed.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="PARAMETER">data_type</replaceable></term>
+ <listitem>
+ <para>
+ The data type of the attribute to add, or the new type of the
+ attribute to alter.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
</refsect1>
@@ -119,14 +225,30 @@ ALTER TYPE email OWNER TO joe;
ALTER TYPE email SET SCHEMA customers;
</programlisting>
</para>
+
+ <para>
+ To add a new attribute to a type:
+<programlisting>
+ALTER TYPE compfoo ADD ATTRIBUTE f3 int;
+</programlisting>
+ </para>
</refsect1>
<refsect1>
<title>Compatibility</title>
-
+
<para>
- There is no <command>ALTER TYPE</command> statement in the SQL
- standard.
+ The variants to add and drop attributes are part of the SQL
+ standard; the other variants are PostgreSQL extensions.
</para>
</refsect1>
+
+ <refsect1 id="SQL-ALTERTYPE-see-also">
+ <title>See Also</title>
+
+ <simplelist type="inline">
+ <member><xref linkend="sql-createtype"></member>
+ <member><xref linkend="sql-droptype"></member>
+ </simplelist>
+ </refsect1>
</refentry>
diff --git a/doc/src/sgml/ref/create_type.sgml b/doc/src/sgml/ref/create_type.sgml
index ca521b387b3..a3c75b51d0f 100644
--- a/doc/src/sgml/ref/create_type.sgml
+++ b/doc/src/sgml/ref/create_type.sgml
@@ -22,7 +22,7 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
CREATE TYPE <replaceable class="parameter">name</replaceable> AS
- ( <replaceable class="PARAMETER">attribute_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] )
+ ( [ <replaceable class="PARAMETER">attribute_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] ] )
CREATE TYPE <replaceable class="parameter">name</replaceable> AS ENUM
( [ '<replaceable class="parameter">label</replaceable>' [, ... ] ] )
@@ -768,10 +768,18 @@ CREATE TABLE big_objs (
<title>Compatibility</title>
<para>
- This <command>CREATE TYPE</command> command is a
- <productname>PostgreSQL</productname> extension. There is a
- <command>CREATE TYPE</command> statement in the <acronym>SQL</> standard
- that is rather different in detail.
+ The first form of the <command>CREATE TYPE</command> command, which
+ creates a composite type, conforms to the <acronym>SQL</> standard.
+ The other forms are <productname>PostgreSQL</productname>
+ extensions. The <command>CREATE TYPE</command> statement in
+ the <acronym>SQL</> standard also defines other forms that are not
+ implemented in <productname>PostgreSQL</>.
+ </para>
+
+ <para>
+ The ability to create a composite type with zero attributes is
+ a <productname>PostgreSQL</productname>-specific deviation from the
+ standard (analogous to <command>CREATE TABLE</command>).
</para>
</refsect1>
@@ -779,10 +787,10 @@ CREATE TABLE big_objs (
<title>See Also</title>
<simplelist type="inline">
- <member><xref linkend="sql-createfunction"></member>
- <member><xref linkend="sql-droptype"></member>
<member><xref linkend="sql-altertype"></member>
<member><xref linkend="sql-createdomain"></member>
+ <member><xref linkend="sql-createfunction"></member>
+ <member><xref linkend="sql-droptype"></member>
</simplelist>
</refsect1>
diff --git a/doc/src/sgml/ref/drop_type.sgml b/doc/src/sgml/ref/drop_type.sgml
index 10e3e143bc2..76e31517a1a 100644
--- a/doc/src/sgml/ref/drop_type.sgml
+++ b/doc/src/sgml/ref/drop_type.sgml
@@ -97,7 +97,7 @@ DROP TYPE box;
This command is similar to the corresponding command in the SQL
standard, apart from the <literal>IF EXISTS</>
option, which is a <productname>PostgreSQL</> extension.
- But note that the <command>CREATE TYPE</command> command
+ But note that much of the <command>CREATE TYPE</command> command
and the data type extension mechanisms in
<productname>PostgreSQL</productname> differ from the SQL standard.
</para>
@@ -107,8 +107,8 @@ DROP TYPE box;
<title>See Also</title>
<simplelist type="inline">
- <member><xref linkend="sql-createtype"></member>
<member><xref linkend="sql-altertype"></member>
+ <member><xref linkend="sql-createtype"></member>
</simplelist>
</refsect1>