Creates a foreign table for collaborative analysis in the current database. 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:
When this parameter is set, encoding indicates the actual encoding of data in the remote cluster, and dataencoding indicates the actual encoding of data in the local cluster.
Assume that the database in the local cluster is latin1_local_db and that in the remote cluster is latin1_remote_db, and latin1_remote_db stores GBK data. When migrating GBK data from latin1_remote_db to latin1_local_db in UTF8 encoding, you need to set the foreign table parameters dataencoding to UTF8 and encoding to GBK in the local cluster.
To reduce the network transmission bandwidth, GDS interconnection provides this parameter for compression. Currently, this parameter can only be set to snappy. By default, data is not compressed. This parameter is supported by version 8.2.0 or later clusters.
Before using this function, ensure that the versions of the local cluster, remote cluster, and GDS are the same.
gds_compress is used together with file_type. If the value of file_type is interconn, GDS must be upgraded to 8.2.0 or later. Otherwise, the error message "ERROR: un-support format" is displayed.
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 | 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 2 3 4 5 6 7 8 9 10 11 12 13 14 | \d+ region Foreign table "public.region" Column | Type | Modifiers | FDW Options | Storage | Stats target | Description -------------+---------+-----------+-------------+----------+--------------+------------- r_regionkey | integer | | | plain | | r_name | text | | | extended | | r_comment | text | | | extended | | Server: server_remote FDW Options: (schema_name 'test', table_name 'region', encoding 'gbk') FDW permission: read only Has OIDs: no Distribute By: ROUND ROBIN Location Nodes: ALL DATANODES |