table of contents
ALTER FOREIGN TABLE(7) | PostgreSQL 9.2.24 Documentation | ALTER FOREIGN TABLE(7) |
NAME¶
ALTER_FOREIGN_TABLE - change the definition of a foreign table
SYNOPSIS¶
ALTER FOREIGN TABLE [ IF EXISTS ] name
action [, ... ] ALTER FOREIGN TABLE [ IF EXISTS ] name
RENAME [ COLUMN ] column_name TO new_column_name ALTER FOREIGN TABLE [ IF EXISTS ] name
RENAME TO new_name ALTER FOREIGN TABLE [ IF EXISTS ] name
SET SCHEMA new_schema where action is one of:
ADD [ COLUMN ] column_name data_type [ NULL | NOT NULL ]
DROP [ COLUMN ] [ IF EXISTS ] column_name [ RESTRICT | CASCADE ]
ALTER [ COLUMN ] column_name [ SET DATA ] TYPE data_type
ALTER [ COLUMN ] column_name { SET | DROP } NOT NULL
ALTER [ COLUMN ] column_name SET STATISTICS integer
ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] )
ALTER [ COLUMN ] column_name RESET ( attribute_option [, ... ] )
ALTER [ COLUMN ] column_name OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])
OWNER TO new_owner
OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])
DESCRIPTION¶
ALTER FOREIGN TABLE changes the definition of an existing foreign table. There are several subforms:
ADD COLUMN
DROP COLUMN [ IF EXISTS ]
IF EXISTS
SET DATA TYPE
SET/DROP NOT NULL
SET STATISTICS
SET ( attribute_option = value [, ... ] ), RESET ( attribute_option [, ... ] )
OWNER
RENAME
SET SCHEMA
OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] )
All the actions except RENAME and SET SCHEMA 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.
You must own the table to use ALTER FOREIGN TABLE. To change the schema of a foreign table, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the table's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't 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 USAGE privilege on the data type.
PARAMETERS¶
name
column_name
new_column_name
new_name
data_type
CASCADE
RESTRICT
new_owner
new_schema
NOTES¶
The key word COLUMN is noise and can be omitted.
Consistency with the foreign server is not checked when a column is added or removed with ADD COLUMN or DROP COLUMN, a NOT NULL constraint is added, or a column type is changed with SET DATA TYPE. It is the user's responsibility to ensure that the table definition matches the remote side.
Refer to CREATE FOREIGN TABLE (CREATE_FOREIGN_TABLE(7)) for a further description of valid parameters.
EXAMPLES¶
To mark a column as not-null:
ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;
To change options of a foreign table:
ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2, 'value2', DROP opt3 'value3');
COMPATIBILITY¶
The forms ADD, DROP, and SET DATA TYPE conform with the SQL standard. The other forms are PostgreSQL extensions of the SQL standard. Also, the ability to specify more than one manipulation in a single ALTER FOREIGN TABLE command is an extension.
ALTER FOREIGN TABLE DROP COLUMN 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.
2017-11-06 | PostgreSQL 9.2.24 |