2 .\" Title: ALTER FOREIGN TABLE
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ALTER FOREIGN TABLE" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ALTER_FOREIGN_TABLE \- change the definition of a foreign table
35 ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] \fIname\fR [ * ]
36 \fIaction\fR [, \&.\&.\&. ]
37 ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] \fIname\fR [ * ]
38 RENAME [ COLUMN ] \fIcolumn_name\fR TO \fInew_column_name\fR
39 ALTER FOREIGN TABLE [ IF EXISTS ] \fIname\fR
40 RENAME TO \fInew_name\fR
41 ALTER FOREIGN TABLE [ IF EXISTS ] \fIname\fR
42 SET SCHEMA \fInew_schema\fR
44 where \fIaction\fR is one of:
46 ADD [ COLUMN ] \fIcolumn_name\fR \fIdata_type\fR [ COLLATE \fIcollation\fR ] [ \fIcolumn_constraint\fR [ \&.\&.\&. ] ]
47 DROP [ COLUMN ] [ IF EXISTS ] \fIcolumn_name\fR [ RESTRICT | CASCADE ]
48 ALTER [ COLUMN ] \fIcolumn_name\fR [ SET DATA ] TYPE \fIdata_type\fR [ COLLATE \fIcollation\fR ]
49 ALTER [ COLUMN ] \fIcolumn_name\fR SET DEFAULT \fIexpression\fR
50 ALTER [ COLUMN ] \fIcolumn_name\fR DROP DEFAULT
51 ALTER [ COLUMN ] \fIcolumn_name\fR { SET | DROP } NOT NULL
52 ALTER [ COLUMN ] \fIcolumn_name\fR SET STATISTICS \fIinteger\fR
53 ALTER [ COLUMN ] \fIcolumn_name\fR SET ( \fIattribute_option\fR = \fIvalue\fR [, \&.\&.\&. ] )
54 ALTER [ COLUMN ] \fIcolumn_name\fR RESET ( \fIattribute_option\fR [, \&.\&.\&. ] )
55 ALTER [ COLUMN ] \fIcolumn_name\fR SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }
56 ALTER [ COLUMN ] \fIcolumn_name\fR OPTIONS ( [ ADD | SET | DROP ] \fIoption\fR [\*(Aq\fIvalue\fR\*(Aq] [, \&.\&.\&. ])
57 ADD \fItable_constraint\fR [ NOT VALID ]
58 VALIDATE CONSTRAINT \fIconstraint_name\fR
59 DROP CONSTRAINT [ IF EXISTS ] \fIconstraint_name\fR [ RESTRICT | CASCADE ]
60 DISABLE TRIGGER [ \fItrigger_name\fR | ALL | USER ]
61 ENABLE TRIGGER [ \fItrigger_name\fR | ALL | USER ]
62 ENABLE REPLICA TRIGGER \fItrigger_name\fR
63 ENABLE ALWAYS TRIGGER \fItrigger_name\fR
65 INHERIT \fIparent_table\fR
66 NO INHERIT \fIparent_table\fR
67 OWNER TO { \fInew_owner\fR | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
68 OPTIONS ( [ ADD | SET | DROP ] \fIoption\fR [\*(Aq\fIvalue\fR\*(Aq] [, \&.\&.\&. ])
72 \fBALTER FOREIGN TABLE\fR
73 changes the definition of an existing foreign table\&. There are several subforms:
77 This form adds a new column to the foreign table, using the same syntax as
78 \fBCREATE FOREIGN TABLE\fR\&. Unlike the case when adding a column to a regular table, nothing happens to the underlying storage: this action simply declares that some new column is now accessible through the foreign table\&.
81 DROP COLUMN [ IF EXISTS ]
83 This form drops a column from a foreign table\&. You will need to say
85 if anything outside the table depends on the column; for example, views\&. If
87 is specified and the column does not exist, no error is thrown\&. In this case a notice is issued instead\&.
92 This form changes the type of a column of a foreign table\&. Again, this has no effect on any underlying storage: this action simply changes the type that
94 believes the column to have\&.
99 These forms set or remove the default value for a column\&. Default values only apply in subsequent
103 commands; they do not cause rows already in the table to change\&.
108 Mark a column as allowing, or not allowing, null values\&.
113 This form sets the per\-column statistics\-gathering target for subsequent
115 operations\&. See the similar form of
120 SET ( \fIattribute_option\fR = \fIvalue\fR [, \&.\&.\&. ] )
122 RESET ( \fIattribute_option\fR [, \&.\&.\&. ] )
124 This form sets or resets per\-attribute options\&. See the similar form of
131 This form sets the storage mode for a column\&. See the similar form of
133 for more details\&. Note that the storage mode has no effect unless the table\*(Aqs foreign\-data wrapper chooses to pay attention to it\&.
136 ADD \fItable_constraint\fR [ NOT VALID ]
138 This form adds a new constraint to a foreign table, using the same syntax as
139 \fBCREATE FOREIGN TABLE\fR\&. Currently only
143 constraints are supported\&.
145 Unlike the case when adding a constraint to a regular table, nothing is done to verify the constraint is correct; rather, this action simply declares that some new condition should be assumed to hold for all rows in the foreign table\&. (See the discussion in
146 \fBCREATE FOREIGN TABLE\fR\&.) If the constraint is marked
148 (allowed only for the
150 case), then it isn\*(Aqt assumed to hold, but is only recorded for possible future use\&.
155 This form marks as valid a constraint that was previously marked as
156 NOT VALID\&. No action is taken to verify the constraint, but future queries will assume that it holds\&.
159 DROP CONSTRAINT [ IF EXISTS ]
161 This form drops the specified constraint on a foreign table\&. If
163 is specified and the constraint does not exist, no error is thrown\&. In this case a notice is issued instead\&.
166 DISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER
168 These forms configure the firing of trigger(s) belonging to the foreign table\&. See the similar form of
175 Backward compatibility syntax for removing the
179 system columns cannot be added anymore, this never has an effect\&.
182 INHERIT \fIparent_table\fR
184 This form adds the target foreign table as a new child of the specified parent table\&. See the similar form of
189 NO INHERIT \fIparent_table\fR
191 This form removes the target foreign table from the list of children of the specified parent table\&.
196 This form changes the owner of the foreign table to the specified user\&.
199 OPTIONS ( [ ADD | SET | DROP ] \fIoption\fR [\*(Aq\fIvalue\fR\*(Aq] [, \&.\&.\&. ] )
201 Change options for the foreign table or one of its columns\&.
205 specify the action to be performed\&.
207 is assumed if no operation is explicitly specified\&. Duplicate option names are not allowed (although it\*(Aqs OK for a table option and a column option to have the same name)\&. Option names and values are also validated using the foreign data wrapper library\&.
214 forms change the name of a foreign table or the name of an individual column in a foreign table\&.
219 This form moves the foreign table into another schema\&.
222 All the actions except
226 can be combined into a list of multiple alterations to apply in parallel\&. For example, it is possible to add several columns and/or alter the type of several columns in a single command\&.
228 If the command is written as
229 ALTER FOREIGN TABLE IF EXISTS \&.\&.\&.
230 and the foreign table does not exist, no error is thrown\&. A notice is issued in this case\&.
232 You must own the table to use
233 \fBALTER FOREIGN TABLE\fR\&. To change the schema of a foreign table, you must also have
235 privilege on the new schema\&. To alter the owner, you must be able to
237 to the new owning role, and that role must have
239 privilege on the table\*(Aqs schema\&. (These restrictions enforce that altering the owner doesn\*(Aqt do anything you couldn\*(Aqt do by dropping and recreating the table\&. However, a superuser can alter ownership of any table anyway\&.) To add a column or alter a column type, you must also have
241 privilege on the data type\&.
246 The name (possibly schema\-qualified) of an existing foreign table to alter\&. If
248 is specified before the table name, only that table is altered\&. If
250 is not specified, the table and all its descendant tables (if any) are altered\&. Optionally,
252 can be specified after the table name to explicitly indicate that descendant tables are included\&.
257 Name of a new or existing column\&.
260 \fInew_column_name\fR
262 New name for an existing column\&.
267 New name for the table\&.
272 Data type of the new column, or new data type for an existing column\&.
275 \fItable_constraint\fR
277 New table constraint for the foreign table\&.
280 \fIconstraint_name\fR
282 Name of an existing constraint to drop\&.
287 Automatically drop objects that depend on the dropped column or constraint (for example, views referencing the column), and in turn all objects that depend on those objects (see
293 Refuse to drop the column or constraint if there are any dependent objects\&. This is the default behavior\&.
298 Name of a single trigger to disable or enable\&.
303 Disable or enable all triggers belonging to the foreign table\&. (This requires superuser privilege if any of the triggers are internally generated triggers\&. The core system does not add such triggers to foreign tables, but add\-on code could do so\&.)
308 Disable or enable all triggers belonging to the foreign table except for internally generated triggers\&.
313 A parent table to associate or de\-associate with this foreign table\&.
318 The user name of the new owner of the table\&.
323 The name of the schema to which the table will be moved\&.
329 is noise and can be omitted\&.
331 Consistency with the foreign server is not checked when a column is added or removed with
338 constraint is added, or a column type is changed with
339 SET DATA TYPE\&. It is the user\*(Aqs responsibility to ensure that the table definition matches the remote side\&.
342 \fBCREATE FOREIGN TABLE\fR
343 for a further description of valid parameters\&.
346 To mark a column as not\-null:
352 ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;
358 To change options of a foreign table:
364 ALTER FOREIGN TABLE myschema\&.distributors OPTIONS (ADD opt1 \*(Aqvalue\*(Aq, SET opt2 \*(Aqvalue2\*(Aq, DROP opt3);
375 conform with the SQL standard\&. The other forms are
377 extensions of the SQL standard\&. Also, the ability to specify more than one manipulation in a single
378 \fBALTER FOREIGN TABLE\fR
379 command is an extension\&.
381 \fBALTER FOREIGN TABLE DROP COLUMN\fR
382 can be used to drop the only column of a foreign table, leaving a zero\-column table\&. This is an extension of SQL, which disallows zero\-column foreign tables\&.
384 CREATE FOREIGN TABLE (\fBCREATE_FOREIGN_TABLE\fR(7)), DROP FOREIGN TABLE (\fBDROP_FOREIGN_TABLE\fR(7))