In the current database, CREATE FOREIGN TABLE creates a foreign table for collaborative analysis. The foreign table is used to access tables stored in other databases for collaborative analysis.
The foreign table is read-only. It can only be queried using SELECT.
1 2 3 4 5 6 7 | CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name ( [ { column_name type_name | LIKE source_table } [, ...] ] ) SERVER server_name OPTIONS ( { option_name ' value ' } [, ...] ) [ READ ONLY ] [ DISTRIBUTE BY {ROUNDROBIN} ] [ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ]; |
Does not throw an error if a table with the same name exists. A notice is issued in this case.
Specifies the name of the foreign table to be created.
Value range: a string. It must comply with the naming convention.
Specifies the name of a column in the foreign table. Columns are separated by commas (,).
Value range: a string. It must comply with the naming convention.
Constraints or indexes cannot be created on columns.
Specifies the data type of the column.
Sequence and custom types are not allowed.
Specifies the server name, which is user-definable.
Value range: a string indicating an existing server. It must comply with the naming convention.
Specifies the following parameters for a foreign table:
Indicates that a table is a read-only foreign table.
Specifies ROUNDROBIN as the distribution mode for the foreign table.
Currently, TO GROUP cannot be used. TO NODE is used for internal scale-out tools.
1 | CREATE SERVER server_remote FOREIGN DATA WRAPPER GC_FDW OPTIONS (address '10.10.0.100:25000,10.10.0.101:25000',dbname 'test', username 'test', password '{Password}'); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | DROP FOREIGN TABLE IF EXISTS region; CREATE FOREIGN TABLE region ( R_REGIONKEY INT4, R_NAME TEXT, R_COMMENT TEXT ) SERVER server_remote OPTIONS ( schema_name 'test', table_name 'region', encoding 'gbk' ); |
1 | \d+ region |