All Products
Search
Document Center

Hologres:IMPORT FOREIGN SCHEMA

Last Updated:Dec 31, 2025

The IMPORT FOREIGN SCHEMA statement creates multiple foreign tables at a time. This topic describes the syntax and limits of the IMPORT FOREIGN SCHEMA statement.

Feature details

IMPORT FOREIGN SCHEMA is a feature that lets you create multiple foreign tables at a time. It automatically maps the table schemas from a remote data source to Hologres foreign tables. This saves you from creating each table manually. This feature supports the following two types of data sources:

  • MaxCompute tables: Import foreign tables in a batch from MaxCompute projects that use the two-layer or three-layer model.

  • Paimon tables in DLF: Create Hologres foreign tables in a batch from Paimon tables in Alibaba Cloud Data Lake Formation (DLF).

Limits

  • You must use the IMPORT FOREIGN SCHEMA statement with the LIMIT TO clause and enclose the table names in parentheses. If you do not include this clause, the system creates foreign tables in Hologres for all tables in the target MaxCompute workspace.

  • Only Hologres V1.1.26 and later allow you to add prefixes or suffixes to the names of foreign tables created using the IMPORT FOREIGN SCHEMA statement. If your instance is a version earlier than V1.1.26, see Common errors that occur when you prepare for an upgrade or join the Hologres DingTalk group for feedback. For more information, see How can I get more online support?.

  • Only Hologres V1.3 and later support MaxCompute projects that use the three-layer model. This model lets you create schemas in MaxCompute projects and use these schemas to classify objects such as tables. For more information, see Schema operations. If you want to create a foreign table in a Hologres instance to map a table in a MaxCompute project that uses the three-layer model and your Hologres version is earlier than V1.3, see Common errors that occur when you prepare for an upgrade or join the Hologres DingTalk group for feedback. For more information, see How can I get more online support?.

Syntax

Use the following syntax to create multiple foreign tables at a time in Hologres.

IMPORT FOREIGN SCHEMA remote_schema
    [ { LIMIT TO | EXCEPT } ( table_name [, ...] ) ]
    FROM SERVER odps_server
    INTO local_schema 
    [ OPTIONS ( option 'value' [, ... ] ) ]

Parameters

The following table describes the parameters.

Parameter

Description

remote_schema

  • MaxCompute

    • Two-layer model: The name of the MaxCompute project where the source tables are located.

    • Three-layer model: The name of the MaxCompute project and the name of the schema where the source tables are located, in the format of odps_project_name#odps_schema_name. If your MaxCompute project uses the three-layer model but you specify only the project name, an error is returned. An example error is shown below.

      failed to import foreign schema:Table not found - table_xxx
  • DLF: The name of the metadatabase created in DLF.

table_name

  • MaxCompute: The name of the MaxCompute table to import.

  • DLF: The name of the DLF table to import.

server_name

  • The name of the foreign server where the MaxCompute tables are stored. The default value is odps_server. You can directly call the foreign table server named odps_server that is created at the underlying layer of Hologres. For more information, see Postgres FDW.

  • DLF: The name of the foreign server where the DLF tables are stored. For more information, see Access Paimon tables using DLF.

local_schema

The name of the schema where the Hologres foreign tables are located, such as public.

options

Hologres supports the following four options:

  • if_table_exist: Specifies the operation to perform if the table already exists at the time of import. Valid values:

    • error: The default value. An error is reported and the existing foreign table is not re-created.

    • ignore: Ignores the table with the same name and skips its import. This prevents duplicate tables.

    • update: Updates and re-imports the table.

  • if_unsupported_type: Specifies the operation to perform if the foreign table to be imported contains data types that Hologres does not support. Valid values:

    • error: Reports an error, fails the import, and indicates which tables contain unsupported types.

    • skip: The default value. Skips the import of tables that contain unsupported types and indicates which tables were skipped.

  • prefix: The prefix for the names of the Hologres foreign tables to be generated during import. This option is available only in Hologres V1.1.26 and later.

  • suffix: The suffix for the names of the Hologres foreign tables to be generated during import. This option is available only in Hologres V1.1.26 and later.

Note

Hologres supports creating foreign tables for MaxCompute tables only. The foreign table and the MaxCompute table must have the same name.

Examples

  • MaxCompute two-layer model

    In this example, foreign tables are created in Hologres in a batch for tables in the MaxCompute public dataset public_data.

    • Example 1: Create a new foreign table for the public schema. If the table exists, it is updated.

      IMPORT FOREIGN SCHEMA public_data LIMIT TO
      (customer) 
        FROM server odps_server INTO PUBLIC options(if_table_exist 'update');
    • Example 2: Create multiple foreign tables in a batch for the 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');
    • Example 3: Create a schema named testdemo and then create multiple foreign tables in a batch.

      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;
    • Example 4: Create multiple foreign tables in a batch in the public schema. If a foreign table already exists, an error is reported.

      IMPORT FOREIGN SCHEMA public_data LIMIT to
      (customer,
        customer_address) 
        FROM server odps_server INTO PUBLIC options(if_table_exist 'error');
    • Example 5: Create multiple foreign tables in a batch in the public schema. If a foreign table already exists, it is skipped.

      IMPORT FOREIGN SCHEMA public_data LIMIT to
      (customer,
        customer_address) 
        FROM server odps_server INTO PUBLIC options(if_table_exist 'ignore');
  • MaxCompute three-layer model

    Create a Hologres foreign table for the odps_region_10g table in the tpch_10g schema of the MaxCompute odps_hologres project.

    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');
  • DLF data source

    For a DLF data source, you can create Hologres foreign tables directly by specifying the data source name, such as github_events.

    • Example: Create a foreign table in the public schema. If the table already exists, it is updated. For more information, see Access Paimon tables using DLF.

      IMPORT FOREIGN SCHEMA github_events
      limit to (customer) 
      FROM SERVER paimon_server into public
      options (if_table_exist 'update');