{
    "mode": "man",
    "parameter": "CREATE_FOREIGN_DATA_WRAPPER",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/CREATE_FOREIGN_DATA_WRAPPER/7/json",
    "generated": "2026-05-30T05:14:57Z",
    "synopsis": "CREATE FOREIGN DATA WRAPPER name\n[ HANDLER handlerfunction | NO HANDLER ]\n[ VALIDATOR validatorfunction | NO VALIDATOR ]\n[ OPTIONS ( option 'value' [, ... ] ) ]",
    "sections": {
        "NAME": {
            "content": "CREATEFOREIGNDATAWRAPPER - define a new foreign-data wrapper\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "CREATE FOREIGN DATA WRAPPER name\n[ HANDLER handlerfunction | NO HANDLER ]\n[ VALIDATOR validatorfunction | NO VALIDATOR ]\n[ OPTIONS ( option 'value' [, ... ] ) ]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. The user who defines a\nforeign-data wrapper becomes its owner.\n\nThe foreign-data wrapper name must be unique within the database.\n\nOnly superusers can create foreign-data wrappers.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name of the foreign-data wrapper to be created.\n\nHANDLER handlerfunction\nhandlerfunction is the name of a previously registered function that will be called to\nretrieve the execution functions for foreign tables. The handler function must take no\narguments, and its return type must be fdwhandler.\n\nIt is possible to create a foreign-data wrapper with no handler function, but foreign\ntables using such a wrapper can only be declared, not accessed.\n\nVALIDATOR validatorfunction\nvalidatorfunction is the name of a previously registered function that will be called to\ncheck the generic options given to the foreign-data wrapper, as well as options for\nforeign servers, user mappings and foreign tables using the foreign-data wrapper. If no\nvalidator function or NO VALIDATOR is specified, then options will not be checked at\ncreation time. (Foreign-data wrappers will possibly ignore or reject invalid option\nspecifications at run time, depending on the implementation.) The validator function must\ntake two arguments: one of type text[], which will contain the array of options as stored\nin the system catalogs, and one of type oid, which will be the OID of the system catalog\ncontaining the options. The return type is ignored; the function should report invalid\noptions using the ereport(ERROR) function.\n\nOPTIONS ( option 'value' [, ... ] )\nThis clause specifies options for the new foreign-data wrapper. The allowed option names\nand values are specific to each foreign data wrapper and are validated using the\nforeign-data wrapper's validator function. Option names must be unique.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "PostgreSQL's foreign-data functionality is still under active development. Optimization of\nqueries is primitive (and mostly left to the wrapper, too). Thus, there is considerable room\nfor future performance improvements.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Create a useless foreign-data wrapper dummy:\n\nCREATE FOREIGN DATA WRAPPER dummy;\n\nCreate a foreign-data wrapper file with handler function filefdwhandler:\n\nCREATE FOREIGN DATA WRAPPER file HANDLER filefdwhandler;\n\nCreate a foreign-data wrapper mywrapper with some options:\n\nCREATE FOREIGN DATA WRAPPER mywrapper\nOPTIONS (debug 'true');\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "CREATE FOREIGN DATA WRAPPER conforms to ISO/IEC 9075-9 (SQL/MED), with the exception that the\nHANDLER and VALIDATOR clauses are extensions and the standard clauses LIBRARY and LANGUAGE\nare not implemented in PostgreSQL.\n\nNote, however, that the SQL/MED functionality as a whole is not yet conforming.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ALTER FOREIGN DATA WRAPPER (ALTERFOREIGNDATAWRAPPER(7)), DROP FOREIGN DATA WRAPPER\n(DROPFOREIGNDATAWRAPPER(7)), CREATE SERVER (CREATESERVER(7)), CREATE USER MAPPING\n(CREATEUSERMAPPING(7)), CREATE FOREIGN TABLE (CREATEFOREIGNTABLE(7))\n\n\n\nPostgreSQL 14.23                                2026                  CREATE FOREIGN DATA WRAPPER(7)",
            "subsections": []
        }
    },
    "summary": "CREATEFOREIGNDATAWRAPPER - define a new foreign-data wrapper",
    "flags": [],
    "examples": [
        "Create a useless foreign-data wrapper dummy:",
        "CREATE FOREIGN DATA WRAPPER dummy;",
        "Create a foreign-data wrapper file with handler function filefdwhandler:",
        "CREATE FOREIGN DATA WRAPPER file HANDLER filefdwhandler;",
        "Create a foreign-data wrapper mywrapper with some options:",
        "CREATE FOREIGN DATA WRAPPER mywrapper",
        "OPTIONS (debug 'true');"
    ],
    "see_also": [
        {
            "name": "ALTERFOREIGNDATAWRAPPER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ALTERFOREIGNDATAWRAPPER/7/json"
        },
        {
            "name": "DROPFOREIGNDATAWRAPPER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPFOREIGNDATAWRAPPER/7/json"
        },
        {
            "name": "CREATESERVER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATESERVER/7/json"
        },
        {
            "name": "CREATEUSERMAPPING",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEUSERMAPPING/7/json"
        },
        {
            "name": "CREATEFOREIGNTABLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEFOREIGNTABLE/7/json"
        },
        {
            "name": "WRAPPER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/WRAPPER/7/json"
        }
    ]
}