]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/alter_foreign_table.sgml
Create a "sort support" interface API for faster sorting.
[postgresql] / doc / src / sgml / ref / alter_foreign_table.sgml
1 <!--
2 doc/src/sgml/rel/alter_foreign_table.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="SQL-ALTERFOREIGNTABLE">
7  <refmeta>
8   <refentrytitle>ALTER FOREIGN TABLE</refentrytitle>
9   <manvolnum>7</manvolnum>
10   <refmiscinfo>SQL - Language Statements</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname>ALTER FOREIGN TABLE</refname>
15   <refpurpose>change the definition of a foreign table</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="sql-alterforeigntable">
19   <primary>ALTER FOREIGN TABLE</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23 <synopsis>
24 ALTER FOREIGN TABLE <replaceable class="PARAMETER">name</replaceable>
25     <replaceable class="PARAMETER">action</replaceable> [, ... ]
26 ALTER FOREIGN TABLE <replaceable class="PARAMETER">name</replaceable>
27     RENAME [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> TO <replaceable class="PARAMETER">new_column</replaceable>
28 ALTER FOREIGN TABLE <replaceable class="PARAMETER">name</replaceable>
29     RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
30 ALTER FOREIGN TABLE <replaceable class="PARAMETER">name</replaceable>
31     SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
32
33 <phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
34
35     ADD [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> <replaceable class="PARAMETER">type</replaceable> [ NULL | NOT NULL ]
36     DROP [ COLUMN ] [ IF EXISTS ] <replaceable class="PARAMETER">column</replaceable> [ RESTRICT | CASCADE ]
37     ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> [ SET DATA ] TYPE <replaceable class="PARAMETER">type</replaceable>
38     ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> { SET | DROP } NOT NULL
39     ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ])
40     OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
41     OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ])
42 </synopsis>
43  </refsynopsisdiv>
44
45  <refsect1>
46   <title>Description</title>
47
48   <para>
49    <command>ALTER FOREIGN TABLE</command> changes the definition of an
50    existing foreign table.  There are several subforms:
51
52   <variablelist>
53    <varlistentry>
54     <term><literal>ADD COLUMN</literal></term>
55     <listitem>
56      <para>
57       This form adds a new column to the foreign table, using the same syntax as
58       <xref linkend="SQL-CREATEFOREIGNTABLE">.
59      </para>
60     </listitem>
61    </varlistentry>
62
63    <varlistentry>
64     <term><literal>DROP COLUMN [ IF EXISTS ]</literal></term>
65     <listitem>
66      <para>
67       This form drops a column from a foreign table.
68       You will need to say <literal>CASCADE</> if
69       anything outside the table depends on the column; for example,
70       views.
71       If <literal>IF EXISTS</literal> is specified and the column
72       does not exist, no error is thrown. In this case a notice
73       is issued instead.
74      </para>
75     </listitem>
76    </varlistentry>
77
78    <varlistentry>
79     <term><literal>SET DATA TYPE</literal></term>
80     <listitem>
81      <para>
82       This form changes the type of a column of a foreign table.
83      </para>
84     </listitem>
85    </varlistentry>
86
87    <varlistentry>
88     <term><literal>SET</literal>/<literal>DROP NOT NULL</literal></term>
89     <listitem>
90      <para>
91       Mark a column as allowing, or not allowing, null values.
92      </para>
93     </listitem>
94    </varlistentry>
95
96    <varlistentry>
97     <term><literal>OWNER</literal></term>
98     <listitem>
99      <para>
100       This form changes the owner of the foreign table to the
101       specified user.
102      </para>
103     </listitem>
104    </varlistentry>
105
106    <varlistentry>
107     <term><literal>RENAME</literal></term>
108     <listitem>
109      <para>
110       The <literal>RENAME</literal> forms change the name of a foreign table
111       or the name of an individual column in a foreign table.
112      </para>
113     </listitem>
114    </varlistentry>
115
116    <varlistentry>
117     <term><literal>SET SCHEMA</literal></term>
118     <listitem>
119      <para>
120       This form moves the foreign table into another schema.
121      </para>
122     </listitem>
123    </varlistentry>
124
125    <varlistentry>
126     <term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term>
127     <listitem>
128      <para>
129       Change options for the foreign table or one of its columns.
130       <literal>ADD</>, <literal>SET</>, and <literal>DROP</>
131       specify the action to be performed.  <literal>ADD</> is assumed
132       if no operation is explicitly specified.  Duplicate option names are not
133       allowed (although it's OK for a table option and a column option to have
134       the same name).  Option names and values are also validated using the
135       foreign data wrapper library.
136      </para>
137     </listitem>
138    </varlistentry>
139
140   </variablelist>
141   </para>
142
143   <para>
144    All the actions except <literal>RENAME</literal> and <literal>SET SCHEMA</>
145    can be combined into
146    a list of multiple alterations to apply in parallel.  For example, it
147    is possible to add several columns and/or alter the type of several
148    columns in a single command.
149   </para>
150
151   <para>
152    You must own the table to use <command>ALTER FOREIGN TABLE</>.
153    To change the schema of a foreign table, you must also have
154    <literal>CREATE</literal> privilege on the new schema.
155    To alter the owner, you must also be a direct or indirect member of the new
156    owning role, and that role must have <literal>CREATE</literal> privilege on
157    the table's schema.  (These restrictions enforce that altering the owner
158    doesn't do anything you couldn't do by dropping and recreating the table.
159    However, a superuser can alter ownership of any table anyway.)
160   </para>
161  </refsect1>
162
163  <refsect1>
164   <title>Parameters</title>
165
166     <variablelist>
167
168      <varlistentry>
169       <term><replaceable class="PARAMETER">name</replaceable></term>
170       <listitem>
171        <para>
172         The name (possibly schema-qualified) of an existing foreign table to
173         alter.
174        </para>
175       </listitem>
176      </varlistentry>
177
178      <varlistentry>
179       <term><replaceable class="PARAMETER">column</replaceable></term>
180       <listitem>
181        <para>
182         Name of a new or existing column.
183        </para>
184       </listitem>
185      </varlistentry>
186
187      <varlistentry>
188       <term><replaceable class="PARAMETER">new_column</replaceable></term>
189       <listitem>
190        <para>
191         New name for an existing column.
192        </para>
193       </listitem>
194      </varlistentry>
195
196      <varlistentry>
197       <term><replaceable class="PARAMETER">new_name</replaceable></term>
198       <listitem>
199        <para>
200         New name for the table.
201        </para>
202       </listitem>
203      </varlistentry>
204
205      <varlistentry>
206       <term><replaceable class="PARAMETER">type</replaceable></term>
207       <listitem>
208        <para>
209         Data type of the new column, or new data type for an existing
210         column.
211        </para>
212       </listitem>
213      </varlistentry>
214
215      <varlistentry>
216       <term><literal>CASCADE</literal></term>
217       <listitem>
218        <para>
219         Automatically drop objects that depend on the dropped column
220         (for example, views referencing the column).
221        </para>
222       </listitem>
223      </varlistentry>
224
225      <varlistentry>
226       <term><literal>RESTRICT</literal></term>
227       <listitem>
228        <para>
229         Refuse to drop the column if there are any dependent
230         objects. This is the default behavior.
231        </para>
232       </listitem>
233      </varlistentry>
234
235      <varlistentry>
236       <term><replaceable class="PARAMETER">new_owner</replaceable></term>
237       <listitem>
238        <para>
239         The user name of the new owner of the table.
240        </para>
241       </listitem>
242      </varlistentry>
243
244      <varlistentry>
245       <term><replaceable class="PARAMETER">new_schema</replaceable></term>
246       <listitem>
247        <para>
248         The name of the schema to which the table will be moved.
249        </para>
250       </listitem>
251      </varlistentry>
252     </variablelist>
253  </refsect1>
254
255  <refsect1>
256   <title>Notes</title>
257
258    <para>
259     The key word <literal>COLUMN</literal> is noise and can be omitted.
260    </para>
261
262    <para>
263     Consistency with the foreign server is not checked when a column is added
264     or removed with <literal>ADD COLUMN</literal> or
265     <literal>DROP COLUMN</literal>, a <literal>NOT NULL</> constraint is
266     added, or a column type is changed with <literal>SET DATA TYPE</>.  It is
267     the user's responsibility to ensure that the table definition matches the
268     remote side.
269    </para>
270
271    <para>
272     Refer to <xref linkend="sql-createforeigntable"> for a further description of valid
273     parameters.
274    </para>
275  </refsect1>
276
277  <refsect1>
278   <title>Examples</title>
279
280   <para>
281    To mark a column as not-null:
282 <programlisting>
283 ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;
284 </programlisting>
285   </para>
286
287   <para>
288    To change options of a foreign table:
289 <programlisting>
290 ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2, 'value2', DROP opt3 'value3');
291 </programlisting></para>
292
293  </refsect1>
294
295  <refsect1>
296   <title>Compatibility</title>
297
298   <para>
299    The forms <literal>ADD</literal>, <literal>DROP</>,
300    and <literal>SET DATA TYPE</literal>
301    conform with the SQL standard.  The other forms are
302    <productname>PostgreSQL</productname> extensions of the SQL standard.
303    Also, the ability to specify more than one manipulation in a single
304    <command>ALTER FOREIGN TABLE</> command is an extension.
305   </para>
306
307   <para>
308    <command>ALTER FOREIGN TABLE DROP COLUMN</> can be used to drop the only
309    column of a foreign table, leaving a zero-column table.  This is an
310    extension of SQL, which disallows zero-column foreign tables.
311   </para>
312  </refsect1>
313 </refentry>