Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite440e12

Browse files
committed
Add ALTER TYPE ... ADD/DROP/ALTER/RENAME ATTRIBUTE
Like with tables, this also requires allowing the existence ofcomposite types with zero attributes.reviewed by KaiGai Kohei
1 parent899beb7 commite440e12

File tree

15 files changed

+636
-148
lines changed

15 files changed

+636
-148
lines changed

‎doc/src/sgml/ref/alter_type.sgml

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ PostgreSQL documentation
2323

2424
<refsynopsisdiv>
2525
<synopsis>
26-
ALTER TYPE <replaceable class="PARAMETER">name</replaceable>RENAME TO<replaceable class="PARAMETER">new_name</replaceable>
26+
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> <replaceable class="PARAMETER">action</replaceable> [, ... ]
2727
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
28+
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> TO <replaceable class="PARAMETER">new_attribute_name</replaceable>
29+
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
2830
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
31+
32+
<phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
33+
34+
ADD ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable>
35+
DROP ATTRIBUTE [ IF EXISTS ] <replaceable class="PARAMETER">attribute_name</replaceable>
36+
ALTER ATTRIBUTE <replaceable class="PARAMETER">attribute_name</replaceable> [ SET DATA ] TYPE <replaceable class="PARAMETER">data_type</replaceable>
2937
</synopsis>
3038
</refsynopsisdiv>
3139

@@ -34,6 +42,76 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replace
3442

3543
<para>
3644
<command>ALTER TYPE</command> changes the definition of an existing type.
45+
There are several subforms:
46+
47+
<variablelist>
48+
<varlistentry>
49+
<term><literal>ADD ATTRIBUTE</literal></term>
50+
<listitem>
51+
<para>
52+
This form adds a new attribute to a composite type, using the same syntax as
53+
<xref linkend="SQL-CREATETYPE">.
54+
</para>
55+
</listitem>
56+
</varlistentry>
57+
58+
<varlistentry>
59+
<term><literal>DROP ATTRIBUTE [ IF EXISTS ]</literal></term>
60+
<listitem>
61+
<para>
62+
This form drops an attribute from a composite type.
63+
If <literal>IF EXISTS</literal> is specified and the attribute
64+
does not exist, no error is thrown. In this case a notice
65+
is issued instead.
66+
</para>
67+
</listitem>
68+
</varlistentry>
69+
70+
<varlistentry>
71+
<term><literal>SET DATA TYPE</literal></term>
72+
<listitem>
73+
<para>
74+
This form changes the type of an attribute of a composite type.
75+
</para>
76+
</listitem>
77+
</varlistentry>
78+
79+
<varlistentry>
80+
<term><literal>OWNER</literal></term>
81+
<listitem>
82+
<para>
83+
This form changes the owner of the type.
84+
</para>
85+
</listitem>
86+
</varlistentry>
87+
88+
<varlistentry>
89+
<term><literal>RENAME</literal></term>
90+
<listitem>
91+
<para>
92+
This form changes the name of the type or the name of an
93+
individual attribute of a composite type.
94+
</para>
95+
</listitem>
96+
</varlistentry>
97+
98+
<varlistentry>
99+
<term><literal>SET SCHEMA</literal></term>
100+
<listitem>
101+
<para>
102+
This form moves the type into another schema.
103+
</para>
104+
</listitem>
105+
</varlistentry>
106+
</variablelist>
107+
</para>
108+
109+
<para>
110+
The <literal>ADD ATTRIBUTE</literal>, <literal>DROP
111+
ATTRIBUTE</literal>, and <literal>ALTER ATTRIBUTE</literal> actions
112+
can be combined into a list of multiple alterations to apply in
113+
parallel. For example, it is possible to add several attributes
114+
and/or alter the type of several attributes in a single command.
37115
</para>
38116

39117
<para>
@@ -90,6 +168,34 @@ ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replace
90168
</listitem>
91169
</varlistentry>
92170

171+
<varlistentry>
172+
<term><replaceable class="PARAMETER">attribute_name</replaceable></term>
173+
<listitem>
174+
<para>
175+
The name of the attribute to add, alter, or drop.
176+
</para>
177+
</listitem>
178+
</varlistentry>
179+
180+
<varlistentry>
181+
<term><replaceable class="PARAMETER">new_attribute_name</replaceable></term>
182+
<listitem>
183+
<para>
184+
The new name of the attribute begin renamed.
185+
</para>
186+
</listitem>
187+
</varlistentry>
188+
189+
<varlistentry>
190+
<term><replaceable class="PARAMETER">data_type</replaceable></term>
191+
<listitem>
192+
<para>
193+
The data type of the attribute to add, or the new type of the
194+
attribute to alter.
195+
</para>
196+
</listitem>
197+
</varlistentry>
198+
93199
</variablelist>
94200
</para>
95201
</refsect1>
@@ -117,16 +223,32 @@ ALTER TYPE email OWNER TO joe;
117223
to <literal>customers</literal>:
118224
<programlisting>
119225
ALTER TYPE email SET SCHEMA customers;
226+
</programlisting>
227+
</para>
228+
229+
<para>
230+
To add a new attribute to a type:
231+
<programlisting>
232+
ALTER TYPE compfoo ADD ATTRIBUTE f3 int;
120233
</programlisting>
121234
</para>
122235
</refsect1>
123236

124237
<refsect1>
125238
<title>Compatibility</title>
126-
239+
127240
<para>
128-
There is no <command>ALTER TYPE</command> statement in the SQL
129-
standard.
241+
The variants to add and drop attributes are part of the SQL
242+
standard; the other variants are PostgreSQL extensions.
130243
</para>
131244
</refsect1>
245+
246+
<refsect1 id="SQL-ALTERTYPE-see-also">
247+
<title>See Also</title>
248+
249+
<simplelist type="inline">
250+
<member><xref linkend="sql-createtype"></member>
251+
<member><xref linkend="sql-droptype"></member>
252+
</simplelist>
253+
</refsect1>
132254
</refentry>

‎doc/src/sgml/ref/create_type.sgml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PostgreSQL documentation
2222
<refsynopsisdiv>
2323
<synopsis>
2424
CREATE TYPE <replaceable class="parameter">name</replaceable> AS
25-
( <replaceable class="PARAMETER">attribute_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] )
25+
([<replaceable class="PARAMETER">attribute_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] ] )
2626

2727
CREATE TYPE <replaceable class="parameter">name</replaceable> AS ENUM
2828
( [ '<replaceable class="parameter">label</replaceable>' [, ... ] ] )
@@ -768,21 +768,29 @@ CREATE TABLE big_objs (
768768
<title>Compatibility</title>
769769

770770
<para>
771-
This <command>CREATE TYPE</command> command is a
772-
<productname>PostgreSQL</productname> extension. There is a
773-
<command>CREATE TYPE</command> statement in the <acronym>SQL</> standard
774-
that is rather different in detail.
771+
The first form of the <command>CREATE TYPE</command> command, which
772+
creates a composite type, conforms to the <acronym>SQL</> standard.
773+
The other forms are <productname>PostgreSQL</productname>
774+
extensions. The <command>CREATE TYPE</command> statement in
775+
the <acronym>SQL</> standard also defines other forms that are not
776+
implemented in <productname>PostgreSQL</>.
777+
</para>
778+
779+
<para>
780+
The ability to create a composite type with zero attributes is
781+
a <productname>PostgreSQL</productname>-specific deviation from the
782+
standard (analogous to <command>CREATE TABLE</command>).
775783
</para>
776784
</refsect1>
777785

778786
<refsect1 id="SQL-CREATETYPE-see-also">
779787
<title>See Also</title>
780788

781789
<simplelist type="inline">
782-
<member><xref linkend="sql-createfunction"></member>
783-
<member><xref linkend="sql-droptype"></member>
784790
<member><xref linkend="sql-altertype"></member>
785791
<member><xref linkend="sql-createdomain"></member>
792+
<member><xref linkend="sql-createfunction"></member>
793+
<member><xref linkend="sql-droptype"></member>
786794
</simplelist>
787795
</refsect1>
788796

‎doc/src/sgml/ref/drop_type.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ DROP TYPE box;
9797
This command is similar to the corresponding command in the SQL
9898
standard, apart from the <literal>IF EXISTS</>
9999
option, which is a <productname>PostgreSQL</> extension.
100-
But note that the <command>CREATE TYPE</command> command
100+
But note thatmuch ofthe <command>CREATE TYPE</command> command
101101
and the data type extension mechanisms in
102102
<productname>PostgreSQL</productname> differ from the SQL standard.
103103
</para>
@@ -107,8 +107,8 @@ DROP TYPE box;
107107
<title>See Also</title>
108108

109109
<simplelist type="inline">
110-
<member><xref linkend="sql-createtype"></member>
111110
<member><xref linkend="sql-altertype"></member>
111+
<member><xref linkend="sql-createtype"></member>
112112
</simplelist>
113113
</refsect1>
114114

‎src/backend/commands/alter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ ExecRenameStmt(RenameStmt *stmt)
8989
caseOBJECT_VIEW:
9090
caseOBJECT_INDEX:
9191
caseOBJECT_COLUMN:
92+
caseOBJECT_ATTRIBUTE:
9293
caseOBJECT_TRIGGER:
9394
{
9495
Oidrelid;
@@ -123,6 +124,7 @@ ExecRenameStmt(RenameStmt *stmt)
123124
break;
124125
}
125126
caseOBJECT_COLUMN:
127+
caseOBJECT_ATTRIBUTE:
126128
renameatt(relid,
127129
stmt->subname,/* old att name */
128130
stmt->newname,/* new att name */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp