You can execute the ALTER FOREIGN TABLE statement to modify a foreign table. This topic describes how to execute the ALTER FOREIGN TABLE statement to rename a foreign table, add columns to a foreign table, or remove columns from a foreign table.

Limits

Hologres allows you to execute the ALTER FOREIGN TABLE statement only to rename a foreign table, add columns to a foreign table, or remove columns from a foreign table.

Rename a foreign table

You can use the following syntax to rename a foreign table:
ALTER FOREIGN TABLE [ IF EXISTS ] name RENAME TO new_name;    
For example, you can execute the following SQL statement:
ALTER FOREIGN TABLE test RENAME TO new_test_table; 

Add a column to a foreign table

Hologres does not automatically update the schema of a created foreign table after columns are added to the mapping MaxCompute table. To query values of the added columns through the foreign table, you must manually add the columns to the foreign table.
Note
  • You cannot execute the following statement to add columns to multiple foreign tables in a schema at a time. For more information about how to add columns to multiple foreign tables in a schema at a time, see IMPORT FOREIGN SCHEMA.
  • Hologres V0.10, V1.1.59, and later allow you to add multiple columns to a foreign table at a time by executing the ADD COLUMN statement.
You can use the following syntax to add a column to a foreign table:
ALTER FOREIGN TABLE IF EXISTS table_name ADD COLUMN new_column_name data_type;
For example, you can execute the following SQL statement:
ALTER FOREIGN TABLE bank
 ADD COLUMN  cons_conf_idx float8,
 ADD COLUMN  euribor3m float8;

Remove a column from a foreign table

You can use the following syntax to remove a column from a foreign table:
ALTER FOREIGN TABLE IF EXISTS table_name DROP COLUMN column_name;
For example, you can execute the following SQL statement:
ALTER FOREIGN TABLE bank
 DROP COLUMN  cons_conf_idx,
 DROP COLUMN  euribor3m;