{
    "mode": "man",
    "parameter": "IMPORT_FOREIGN_SCHEMA",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/IMPORT_FOREIGN_SCHEMA/7/json",
    "generated": "2026-06-15T21:12:00Z",
    "synopsis": "IMPORT FOREIGN SCHEMA remoteschema\n[ { LIMIT TO | EXCEPT } ( tablename [, ...] ) ]\nFROM SERVER servername\nINTO localschema\n[ OPTIONS ( option 'value' [, ... ] ) ]",
    "sections": {
        "NAME": {
            "content": "IMPORTFOREIGNSCHEMA - import table definitions from a foreign server\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "IMPORT FOREIGN SCHEMA remoteschema\n[ { LIMIT TO | EXCEPT } ( tablename [, ...] ) ]\nFROM SERVER servername\nINTO localschema\n[ OPTIONS ( option 'value' [, ... ] ) ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "IMPORT FOREIGN SCHEMA creates foreign tables that represent tables existing on a foreign\nserver. The new foreign tables will be owned by the user issuing the command and are created\nwith the correct column definitions and options to match the remote tables.\n\nBy default, all tables and views existing in a particular schema on the foreign server are\nimported. Optionally, the list of tables can be limited to a specified subset, or specific\ntables can be excluded. The new foreign tables are all created in the target schema, which\nmust already exist.\n\nTo use IMPORT FOREIGN SCHEMA, the user must have USAGE privilege on the foreign server, as\nwell as CREATE privilege on the target schema.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "remoteschema\nThe remote schema to import from. The specific meaning of a remote schema depends on the\nforeign data wrapper in use.\n\nLIMIT TO ( tablename [, ...] )\nImport only foreign tables matching one of the given table names. Other tables existing\nin the foreign schema will be ignored.\n\nEXCEPT ( tablename [, ...] )\nExclude specified foreign tables from the import. All tables existing in the foreign\nschema will be imported except the ones listed here.\n\nservername\nThe foreign server to import from.\n\nlocalschema\nThe schema in which the imported foreign tables will be created.\n\nOPTIONS ( option 'value' [, ...] )\nOptions to be used during the import. The allowed option names and values are specific to\neach foreign data wrapper.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Import table definitions from a remote schema foreignfilms on server filmserver, creating\nthe foreign tables in local schema films:\n\nIMPORT FOREIGN SCHEMA foreignfilms\nFROM SERVER filmserver INTO films;\n\nAs above, but import only the two tables actors and directors (if they exist):\n\nIMPORT FOREIGN SCHEMA foreignfilms LIMIT TO (actors, directors)\nFROM SERVER filmserver INTO films;\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "The IMPORT FOREIGN SCHEMA command conforms to the SQL standard, except that the OPTIONS\nclause is a PostgreSQL extension.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CREATE FOREIGN TABLE (CREATEFOREIGNTABLE(7)), CREATE SERVER (CREATESERVER(7))\n\n\n\nPostgreSQL 14.23                                2026                        IMPORT FOREIGN SCHEMA(7)",
            "subsections": []
        }
    },
    "summary": "IMPORTFOREIGNSCHEMA - import table definitions from a foreign server",
    "flags": [],
    "examples": [
        "Import table definitions from a remote schema foreignfilms on server filmserver, creating",
        "the foreign tables in local schema films:",
        "IMPORT FOREIGN SCHEMA foreignfilms",
        "FROM SERVER filmserver INTO films;",
        "As above, but import only the two tables actors and directors (if they exist):",
        "IMPORT FOREIGN SCHEMA foreignfilms LIMIT TO (actors, directors)",
        "FROM SERVER filmserver INTO films;"
    ],
    "see_also": [
        {
            "name": "CREATEFOREIGNTABLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEFOREIGNTABLE/7/json"
        },
        {
            "name": "CREATESERVER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATESERVER/7/json"
        },
        {
            "name": "SCHEMA",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/SCHEMA/7/json"
        }
    ]
}