You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Allow ALTER TYPE to change some properties of a base type.
Specifically, this patch allows ALTER TYPE to:* Change the default TOAST strategy for a toastable base type;* Promote a non-toastable type to toastable;* Add/remove binary I/O functions for a type;* Add/remove typmod I/O functions for a type;* Add/remove a custom ANALYZE statistics functions for a type.The first of these can be done by the type's owner; all the othersrequire superuser privilege since misuse could cause problems.The main motivation for this patch is to allow extensions toupgrade the feature sets of their data types, so the set ofalterable properties is biased towards that use-case. Howeverit's also true that changing some other properties would bea lot harder, as they get baked into physical storage and/orstored expressions that depend on the type.Along the way, refactor GenerateTypeDependencies() to make it easierto call, refactor DefineType's volatility checks so they can be sharedby AlterType, and teach typcache.c that it might have to reload datafrom the type's pg_type row, a scenario it never handled before.Also rearrange alter_type.sgml a bit for clarity (put thecomposite-type operations together).Tomas Vondra and Tom LaneDiscussion:https://postgr.es/m/20200228004440.b23ein4qvmxnlpht@development
ALTER TYPE <replaceable class="parameter">name</replaceable> <replaceable class="parameter">action</replaceable> [, ... ]
27
26
ALTER TYPE <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable class="parameter">new_owner</replaceable> | CURRENT_USER | SESSION_USER }
28
-
ALTER TYPE <replaceable class="parameter">name</replaceable> RENAME ATTRIBUTE <replaceable class="parameter">attribute_name</replaceable> TO <replaceable class="parameter">new_attribute_name</replaceable> [ CASCADE | RESTRICT ]
29
27
ALTER TYPE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
30
28
ALTER TYPE <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
29
+
ALTER TYPE <replaceable class="parameter">name</replaceable> RENAME ATTRIBUTE <replaceable class="parameter">attribute_name</replaceable> TO <replaceable class="parameter">new_attribute_name</replaceable> [ CASCADE | RESTRICT ]
30
+
ALTER TYPE <replaceable class="parameter">name</replaceable> <replaceable class="parameter">action</replaceable> [, ... ]
31
31
ALTER TYPE <replaceable class="parameter">name</replaceable> ADD VALUE [ IF NOT EXISTS ] <replaceable class="parameter">new_enum_value</replaceable> [ { BEFORE | AFTER } <replaceable class="parameter">neighbor_enum_value</replaceable> ]
32
32
ALTER TYPE <replaceable class="parameter">name</replaceable> RENAME VALUE <replaceable class="parameter">existing_enum_value</replaceable> TO <replaceable class="parameter">new_enum_value</replaceable>
33
+
ALTER TYPE <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">property</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] )
33
34
34
35
<phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase>
35
36
@@ -48,60 +49,69 @@ ALTER TYPE <replaceable class="parameter">name</replaceable> RENAME VALUE <repla
48
49
49
50
<variablelist>
50
51
<varlistentry>
51
-
<term><literal>ADD ATTRIBUTE</literal></term>
52
+
<term><literal>OWNER</literal></term>
52
53
<listitem>
53
54
<para>
54
-
This form adds a new attribute to a composite type, using the same syntax as
55
-
<xref linkend="sql-createtype"/>.
55
+
This form changes the owner of the type.
56
56
</para>
57
57
</listitem>
58
58
</varlistentry>
59
59
60
60
<varlistentry>
61
-
<term><literal>DROP ATTRIBUTE [ IF EXISTS ]</literal></term>
61
+
<term><literal>RENAME</literal></term>
62
62
<listitem>
63
63
<para>
64
-
This form drops an attribute from a composite type.
65
-
If <literal>IF EXISTS</literal> is specified and the attribute
66
-
does not exist, no error is thrown. In this case a notice
67
-
is issued instead.
64
+
This form changes the name of the type.
68
65
</para>
69
66
</listitem>
70
67
</varlistentry>
71
68
72
69
<varlistentry>
73
-
<term><literal>SETDATA TYPE</literal></term>
70
+
<term><literal>SETSCHEMA</literal></term>
74
71
<listitem>
75
72
<para>
76
-
This formchanges the typeof an attribute of a composite type.
73
+
This formmoves the typeinto another schema.
77
74
</para>
78
75
</listitem>
79
76
</varlistentry>
80
77
81
78
<varlistentry>
82
-
<term><literal>OWNER</literal></term>
79
+
<term><literal>RENAME ATTRIBUTE</literal></term>
83
80
<listitem>
84
81
<para>
85
-
This form changes the owner of the type.
82
+
This form is only usable with composite types.
83
+
It changes the name of an individual attribute of the type.
86
84
</para>
87
85
</listitem>
88
86
</varlistentry>
89
87
90
88
<varlistentry>
91
-
<term><literal>RENAME</literal></term>
89
+
<term><literal>ADD ATTRIBUTE</literal></term>
92
90
<listitem>
93
91
<para>
94
-
This formchanges the name of thetype or thename of an
95
-
individual attribute of a composite type.
92
+
This formadds a new attribute to a compositetype, using thesame syntax as
93
+
<xref linkend="sql-createtype"/>.
96
94
</para>
97
95
</listitem>
98
96
</varlistentry>
99
97
100
98
<varlistentry>
101
-
<term><literal>SET SCHEMA</literal></term>
99
+
<term><literal>DROP ATTRIBUTE [ IF EXISTS ]</literal></term>
102
100
<listitem>
103
101
<para>
104
-
This form moves the type into another schema.
102
+
This form drops an attribute from a composite type.
103
+
If <literal>IF EXISTS</literal> is specified and the attribute
104
+
does not exist, no error is thrown. In this case a notice
105
+
is issued instead.
106
+
</para>
107
+
</listitem>
108
+
</varlistentry>
109
+
110
+
<varlistentry>
111
+
<term><literal>ALTER ATTRIBUTE ... SET DATA TYPE</literal></term>
112
+
<listitem>
113
+
<para>
114
+
This form changes the type of an attribute of a composite type.
105
115
</para>
106
116
</listitem>
107
117
</varlistentry>
@@ -135,6 +145,84 @@ ALTER TYPE <replaceable class="parameter">name</replaceable> RENAME VALUE <repla