Changes the definition of a foreign table.
ALTER FOREIGN TABLE [ IF EXISTS ] [ONLY] <name> [ * ]
<action> [, ... ]
ALTER FOREIGN TABLE [ IF EXISTS ] [ONLY] <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> [ COLLATE <collation> ] [ <column_constraint> [ ... ] ]
DROP [ COLUMN ] [ IF EXISTS ] <column_name> [ RESTRICT | CASCADE ]
ALTER [ COLUMN ] <column_name> [ SET DATA ] TYPE <data_type> [ COLLATE <collation> ]
ALTER [ COLUMN ] <column_name> SET DEFAULT <expression>
ALTER [ COLUMN ] <column_name> DROP DEFAULT
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> SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
ALTER [ COLUMN ] <column_name> OPTIONS ( [ ADD | SET | DROP ] <option> ['<value>'] [, ... ])
ADD <table_constraint> [ NOT VALID ]
VALIDATE CONSTRAINT <constraint_name>
DROP CONSTRAINT [ IF EXISTS ] <constraint_name> [ RESTRICT | CASCADE ]
DISABLE TRIGGER [ <trigger_name> | ALL | USER ]
ENABLE TRIGGER [ <trigger_name> | ALL | USER ]
ENABLE REPLICA TRIGGER <trigger_name>
ENABLE ALWAYS TRIGGER <trigger_name>
SET WITHOUT OIDS
INHERIT <parent_table>
NO INHERIT <parent_table>
OWNER TO { <new_owner> | CURRENT_USER | SESSION_USER }
OPTIONS ( [ ADD | SET | DROP ] <option> ['<value>'] [, ... ] )
ALTER FOREIGN TABLE
changes the definition of an existing foreign table. There are several subforms of the command:
CASCADE
if any objects outside of the table depend on the column; for example, views. If you specify
IF EXISTS
and the column does not exist, no error is thrown. In this case, Greenplum Database issues a notice instead.
IF EXISTS
and the foreign table does not exist, no error is thrown. Greenplum Database issues a notice instead.
INSERT
or
UPDATE
commands; they do not cause rows already in the table to change.
ANALYZE
operations. See the similar form of
ALTER TABLE for more details.
CHECK
constraints are supported.
NOT VALID
, then it isn't assumed to hold, but is only recorded for possible future use.
NOT VALID
. No action is taken to verify the constraint, but future queries will assume that it holds.
IF EXISTS
is specified and the constraint does not exist, no error is thrown. In this case a notice is issued instead.
RENAME
forms change the name of a foreign table or the name of an individual column in a foreign table.
ADD
,
SET
, and
DROP
specify the action to perform. If no operation is explicitly specified, the default operation is
ADD
. Option names must be unique (although it's OK for a table option and a column option to have the same name). Greenplum Database also validates names and values using the server's foreign-data wrapper.
You can combine all of the actions except RENAME
and SET SCHEMA
into a list of multiple alterations for Greenplum Database 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.
If the command is written as ALTER FOREIGN TABLE IF EXISTS ...
and the foreign table does not exist, no error is thrown. A notice is issued in this case.
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 to alter a column type, you must also have USAGE
privilege on the data type.
ONLY
is specified before the table name, only that table is altered. If
ONLY
is not specified, the table and all its descendant tables (if any) are altered. Optionally,
*
can be specified after the table name to explicitly indicate that descendant tables are included.
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
or CHECK
constraint is added, or a column type is changed with SET DATA TYPE
. It is your responsibility to ensure that the table definition matches the remote side.
Refer to CREATE FOREIGN TABLE for a further description of valid parameters.
To mark a column as not-null:
ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;
To change the options of a foreign table:
ALTER FOREIGN TABLE myschema.distributors
OPTIONS (ADD opt1 'value', SET opt2 'value2', DROP opt3 'value3');
The forms ADD
, DROP
, and SET DATA TYPE
conform with the SQL standard. The other forms are Greenplum Database extensions of the SQL standard. The ability to specify more than one manipulation in a single ALTER FOREIGN TABLE
command is also a Greenplum Database extension.
You can use ALTER FOREIGN TABLE ... DROP COLUMN
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.
ALTER TABLE, CREATE FOREIGN TABLE, DROP FOREIGN TABLE
Parent topic: SQL Commands