IMPORT FOREIGN SCHEMA語句用於大量建立外部表格。本文為您介紹IMPORT FOREIGN SCHEMA語句的用法和使用限制。
使用限制
使用
IMPORT FOREIGN SCHEMA語句時,建議您添加LIMIT TO限制,並使用括弧將需要添加限制的表名稱括起來。如果不添加該限制,系統則將目標MaxCompute工作空間中的所有表大量建立至Hologres中。僅Hologres V1.1.26及以上版本支援對使用
IMPORT FOREIGN SCHEMA建立的外部表格名稱增加首碼和尾碼,如果您的執行個體是V1.1.26以下版本,請您使用常見升級準備失敗報錯或加入HologresDingTalk交流群反饋,詳情請參見如何擷取更多的線上支援?。僅Hologres V1.3及以上版本支援MaxCompute的三層模型模式(即在原先的Project和Table之間增加了一層Schema的概念),更多描述請參見Schema操作。如果您想在Hologres中使用MaxCompute的三層模型的專案建立外部表格,且您的Hologres版本較低,請您使用常見升級準備失敗報錯或加入HologresDingTalk交流群反饋,詳情請參見如何擷取更多的線上支援?。
命令格式
在Hologres中大量建立外部表格的命令格式如下。
IMPORT FOREIGN SCHEMA remote_schema
[ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]
FROM SERVER odps_server
INTO local_schema
[ OPTIONS ( option 'value' [, ... ] ) ]參數說明
參數說明如下表所示。
參數 | 描述 |
remote_schema |
|
table_name | 需要匯入的MaxCompute表名稱。 |
server_name | MaxCompute表所在的外部伺服器名稱,預設為odps_server。 您可以直接調用Hologres底層已建立的名為odps_server的外部表格伺服器。詳細原理請參見Postgres FDW。 |
local_schema | Hologres外部表格所在的Schema名(如public)。 |
options | Hologres支援如下四個option:
|
Hologres僅支援建立MaxCompute外部表格。建立的外部表格名稱需要同MaxCompute表的名稱一致。
使用樣本
MaxCompute兩層模型。
樣本選取MaxCompute公用資料集public_data中的表,在Hologres中大量建立外部表格。
樣本1:為public Schema建立一張外部表格,若表存在則更新表。
IMPORT FOREIGN SCHEMA public_data LIMIT TO (customer) FROM server odps_server INTO PUBLIC options(if_table_exist 'update');樣本2:為public Schema批量建立外部表格。
IMPORT FOREIGN SCHEMA public_data LIMIT TO( customer, customer_address, customer_demographics, inventory,item, date_dim, warehouse) FROM server odps_server INTO PUBLIC options(if_table_exist 'update');樣本3:建立一個testdemo Schema並批量建立外部表格。
CREATE schema testdemo; IMPORT FOREIGN SCHEMA public_data LIMIT TO( customer, customer_address, customer_demographics, inventory,item, date_dim, warehouse) FROM server odps_server INTO testdemo options(if_table_exist 'update'); SET search_path TO testdemo;樣本4:在public Schema大量建立外部表格,已有外表則報錯。
IMPORT FOREIGN SCHEMA public_data LIMIT to (customer, customer_address) FROM server odps_server INTO PUBLIC options(if_table_exist 'error');樣本5:在public Schema中大量建立外部表格,已有外表則跳過該外部表格。
IMPORT FOREIGN SCHEMA public_data LIMIT to (customer, customer_address) FROM server odps_server INTO PUBLIC options(if_table_exist 'ignore');
MaxCompute三層模型。
基於MaxCompute
odps_hologres專案的tpch_10g這個Schema中的odps_region_10g表建立Hologres中的外部表格。IMPORT FOREIGN SCHEMA "odps_hologres#tpch_10g" LIMIT to ( odps_region_10g ) FROM SERVER odps_server INTO public OPTIONS(if_table_exist 'error',if_unsupported_type 'error');