Postgresql 中文操作指南

IMPORT FOREIGN SCHEMA

IMPORT FOREIGN SCHEMA——从外来服务器中导入表格信息

IMPORT FOREIGN SCHEMA — import table definitions from a foreign server

Synopsis

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

Description

IMPORT FOREIGN SCHEMA 会创建外来表格,这些表格代表外来服务器中的现有表格。所有者将是负责发布此命令的用户,创建时拥有与远程表格相匹配的正确列定义和选项。

IMPORT FOREIGN SCHEMA creates foreign tables that represent tables existing on a foreign server. The new foreign tables will be owned by the user issuing the command and are created with the correct column definitions and options to match the remote tables.

默认情况下,将从外来服务器中的特定架构处导入所有现有表格和视图。或者,可以将表格列表限制为特定子集,或排除特定表格。所有新外来表格都将在目标架构中创建,目标架构必须已存在。

By default, all tables and views existing in a particular schema on the foreign server are imported. Optionally, the list of tables can be limited to a specified subset, or specific tables can be excluded. The new foreign tables are all created in the target schema, which must already exist.

为了使用 IMPORT FOREIGN SCHEMA ,该用户必须拥有外来服务器上的 USAGE 权限,以及目标架构上的 CREATE 权限。

To use IMPORT FOREIGN SCHEMA, the user must have USAGE privilege on the foreign server, as well as CREATE privilege on the target schema.

Parameters

  • remote_schema

    • The remote schema to import from. The specific meaning of a remote schema depends on the foreign data wrapper in use.

  • LIMIT TO ( _table_name [, …​] )_

    • Import only foreign tables matching one of the given table names. Other tables existing in the foreign schema will be ignored.

  • EXCEPT ( _table_name [, …​] )_

    • Exclude specified foreign tables from the import. All tables existing in the foreign schema will be imported except the ones listed here.

  • server_name

    • The foreign server to import from.

  • local_schema

    • The schema in which the imported foreign tables will be created.

  • OPTIONS ( _option 'value' [, …​] )_

    • Options to be used during the import. The allowed option names and values are specific to each foreign data wrapper.

Examples

从服务器 film_server 中的远程架构 foreign_films 中导入表定义,在本地架构 films 中创建外来表格:

Import table definitions from a remote schema foreign_films on server film_server, creating the foreign tables in local schema films:

IMPORT FOREIGN SCHEMA foreign_films
    FROM SERVER film_server INTO films;

如上,但仅仅导入两个表格 actorsdirectors (如果存在):

As above, but import only the two tables actors and directors (if they exist):

IMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)
    FROM SERVER film_server INTO films;

Compatibility

IMPORT FOREIGN SCHEMA 命令符合 SQL 标准, OPTIONS 条款为 PostgreSQL 扩展。

The IMPORT FOREIGN SCHEMA command conforms to the SQL standard, except that the OPTIONS clause is a PostgreSQL extension.