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 <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>
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> 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>'] [, ... ])
46 <title>Description</title>
49 <command>ALTER FOREIGN TABLE</command> changes the definition of an
50 existing foreign table. There are several subforms:
54 <term><literal>ADD COLUMN</literal></term>
57 This form adds a new column to the foreign table, using the same syntax as
58 <xref linkend="SQL-CREATEFOREIGNTABLE">.
64 <term><literal>DROP COLUMN [ IF EXISTS ]</literal></term>
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,
71 If <literal>IF EXISTS</literal> is specified and the column
72 does not exist, no error is thrown. In this case a notice
79 <term><literal>SET DATA TYPE</literal></term>
82 This form changes the type of a column of a foreign table.
88 <term><literal>SET</literal>/<literal>DROP NOT NULL</literal></term>
91 Mark a column as allowing, or not allowing, null values.
97 <term><literal>OWNER</literal></term>
100 This form changes the owner of the foreign table to the
107 <term><literal>RENAME</literal></term>
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.
117 <term><literal>SET SCHEMA</literal></term>
120 This form moves the foreign table into another schema.
126 <term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term>
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.
144 All the actions except <literal>RENAME</literal> and <literal>SET SCHEMA</>
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.
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.)
164 <title>Parameters</title>
169 <term><replaceable class="PARAMETER">name</replaceable></term>
172 The name (possibly schema-qualified) of an existing foreign table to
179 <term><replaceable class="PARAMETER">column</replaceable></term>
182 Name of a new or existing column.
188 <term><replaceable class="PARAMETER">new_column</replaceable></term>
191 New name for an existing column.
197 <term><replaceable class="PARAMETER">new_name</replaceable></term>
200 New name for the table.
206 <term><replaceable class="PARAMETER">type</replaceable></term>
209 Data type of the new column, or new data type for an existing
216 <term><literal>CASCADE</literal></term>
219 Automatically drop objects that depend on the dropped column
220 (for example, views referencing the column).
226 <term><literal>RESTRICT</literal></term>
229 Refuse to drop the column if there are any dependent
230 objects. This is the default behavior.
236 <term><replaceable class="PARAMETER">new_owner</replaceable></term>
239 The user name of the new owner of the table.
245 <term><replaceable class="PARAMETER">new_schema</replaceable></term>
248 The name of the schema to which the table will be moved.
259 The key word <literal>COLUMN</literal> is noise and can be omitted.
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
272 Refer to <xref linkend="sql-createforeigntable"> for a further description of valid
278 <title>Examples</title>
281 To mark a column as not-null:
283 ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;
288 To change options of a foreign table:
290 ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2, 'value2', DROP opt3 'value3');
291 </programlisting></para>
296 <title>Compatibility</title>
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.
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.