数据仓库服务 GAUSSDB(DWS)-CREATE FOREIGN TABLE (SQL on other GaussDB(DWS)):示例

时间:2024-04-18 16:25:02

示例

  1. 创建名称为server_remote的外部服务器,对应的foreign data wrapper为GC_FDW。
    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}');
    
    • 在可选项options里面写入了关联集群CN对应的IP地址及端口号。这里推荐使用填写一个LVS的地址或者多个CN的地址。
  2. 创建名称为region的外表:
     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'
    );
    
  3. 查看创建的外表region:
     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
    
support.huaweicloud.com/sqlreference-830-dws/dws_06_0162.html