2 doc/src/sgml/rel/alter_foreign_table.sgml
3 PostgreSQL documentation
6 <refentry id="SQL-ALTERFOREIGNTABLE">
8 <refentrytitle>ALTER FOREIGN TABLE</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements</refmiscinfo>
14 <refname>ALTER FOREIGN TABLE</refname>
15 <refpurpose>change the definition of a foreign table</refpurpose>
18 <indexterm zone="sql-alterforeigntable">
19 <primary>ALTER FOREIGN TABLE</primary>
24 ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
25 <replaceable class="PARAMETER">action</replaceable> [, ... ]
26 ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
27 RENAME [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> TO <replaceable class="PARAMETER">new_column</replaceable>
28 ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
29 RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
30 ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
31 SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
33 <phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
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> SET STATISTICS <replaceable class="PARAMETER">integer</replaceable>
40 ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET ( <replaceable class="PARAMETER">attribute_option</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
41 ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> RESET ( <replaceable class="PARAMETER">attribute_option</replaceable> [, ... ] )
42 ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ])
43 OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
44 OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ])
49 <title>Description</title>
52 <command>ALTER FOREIGN TABLE</command> changes the definition of an
53 existing foreign table. There are several subforms:
57 <term><literal>ADD COLUMN</literal></term>
60 This form adds a new column to the foreign table, using the same syntax as
61 <xref linkend="SQL-CREATEFOREIGNTABLE">.
67 <term><literal>DROP COLUMN [ IF EXISTS ]</literal></term>
70 This form drops a column from a foreign table.
71 You will need to say <literal>CASCADE</> if
72 anything outside the table depends on the column; for example,
74 If <literal>IF EXISTS</literal> is specified and the column
75 does not exist, no error is thrown. In this case a notice
82 <term><literal>IF EXISTS</literal></term>
85 Do not throw an error if the foreign table does not exist. A notice is
92 <term><literal>SET DATA TYPE</literal></term>
95 This form changes the type of a column of a foreign table.
101 <term><literal>SET</literal>/<literal>DROP NOT NULL</literal></term>
104 Mark a column as allowing, or not allowing, null values.
110 <term><literal>SET STATISTICS</literal></term>
114 sets the per-column statistics-gathering target for subsequent
115 <xref linkend="sql-analyze"> operations.
116 See the similar form of <xref linkend="sql-altertable">
123 <term><literal>SET ( <replaceable class="PARAMETER">attribute_option</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )</literal></term>
124 <term><literal>RESET ( <replaceable class="PARAMETER">attribute_option</replaceable> [, ... ] )</literal></term>
127 This form sets or resets per-attribute options.
128 See the similar form of <xref linkend="sql-altertable">
135 <term><literal>OWNER</literal></term>
138 This form changes the owner of the foreign table to the
145 <term><literal>RENAME</literal></term>
148 The <literal>RENAME</literal> forms change the name of a foreign table
149 or the name of an individual column in a foreign table.
155 <term><literal>SET SCHEMA</literal></term>
158 This form moves the foreign table into another schema.
164 <term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term>
167 Change options for the foreign table or one of its columns.
168 <literal>ADD</>, <literal>SET</>, and <literal>DROP</>
169 specify the action to be performed. <literal>ADD</> is assumed
170 if no operation is explicitly specified. Duplicate option names are not
171 allowed (although it's OK for a table option and a column option to have
172 the same name). Option names and values are also validated using the
173 foreign data wrapper library.
182 All the actions except <literal>RENAME</literal> and <literal>SET SCHEMA</>
184 a list of multiple alterations to apply in parallel. For example, it
185 is possible to add several columns and/or alter the type of several
186 columns in a single command.
190 You must own the table to use <command>ALTER FOREIGN TABLE</>.
191 To change the schema of a foreign table, you must also have
192 <literal>CREATE</literal> privilege on the new schema.
193 To alter the owner, you must also be a direct or indirect member of the new
194 owning role, and that role must have <literal>CREATE</literal> privilege on
195 the table's schema. (These restrictions enforce that altering the owner
196 doesn't do anything you couldn't do by dropping and recreating the table.
197 However, a superuser can alter ownership of any table anyway.)
198 To add a column or alter a column type, you must also
199 have <literal>USAGE</literal> privilege on the data type.
204 <title>Parameters</title>
209 <term><replaceable class="PARAMETER">name</replaceable></term>
212 The name (possibly schema-qualified) of an existing foreign table to
219 <term><replaceable class="PARAMETER">column</replaceable></term>
222 Name of a new or existing column.
228 <term><replaceable class="PARAMETER">new_column</replaceable></term>
231 New name for an existing column.
237 <term><replaceable class="PARAMETER">new_name</replaceable></term>
240 New name for the table.
246 <term><replaceable class="PARAMETER">type</replaceable></term>
249 Data type of the new column, or new data type for an existing
256 <term><literal>CASCADE</literal></term>
259 Automatically drop objects that depend on the dropped column
260 (for example, views referencing the column).
266 <term><literal>RESTRICT</literal></term>
269 Refuse to drop the column if there are any dependent
270 objects. This is the default behavior.
276 <term><replaceable class="PARAMETER">new_owner</replaceable></term>
279 The user name of the new owner of the table.
285 <term><replaceable class="PARAMETER">new_schema</replaceable></term>
288 The name of the schema to which the table will be moved.
299 The key word <literal>COLUMN</literal> is noise and can be omitted.
303 Consistency with the foreign server is not checked when a column is added
304 or removed with <literal>ADD COLUMN</literal> or
305 <literal>DROP COLUMN</literal>, a <literal>NOT NULL</> constraint is
306 added, or a column type is changed with <literal>SET DATA TYPE</>. It is
307 the user's responsibility to ensure that the table definition matches the
312 Refer to <xref linkend="sql-createforeigntable"> for a further description of valid
318 <title>Examples</title>
321 To mark a column as not-null:
323 ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;
328 To change options of a foreign table:
330 ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2, 'value2', DROP opt3 'value3');
331 </programlisting></para>
336 <title>Compatibility</title>
339 The forms <literal>ADD</literal>, <literal>DROP</>,
340 and <literal>SET DATA TYPE</literal>
341 conform with the SQL standard. The other forms are
342 <productname>PostgreSQL</productname> extensions of the SQL standard.
343 Also, the ability to specify more than one manipulation in a single
344 <command>ALTER FOREIGN TABLE</> command is an extension.
348 <command>ALTER FOREIGN TABLE DROP COLUMN</> can be used to drop the only
349 column of a foreign table, leaving a zero-column table. This is an
350 extension of SQL, which disallows zero-column foreign tables.