Foreign data wrappers

A foreign data wrapper is a library that you can use to access and interact with an external data (foreign data) source. They allow you to query foreign objects from remote servers as if they were local objects.

To access foreign data, you first create a foreign data wrapper. Then, you create a foreign server, which specifies how to connect to the external data source. You may also need to create a user mapping to map a specific user to authorization credentials in the foreign server. Finally, you create foreign tables, which represent the structure of the data on the external source.

Create a foreign data wrapper

Use the CREATE FOREIGN DATA WRAPPER command to create foreign data wrappers.

Example:

yugabyte=# CREATE FOREIGN DATA WRAPPER mywrapper HANDLER myhandler OPTIONS (dummy 'true');

Create a foreign server

You use foreign servers to specify connection information for an external data source. Create foreign servers using the CREATE FOREIGN SERVER command.

Example:

yugabyte=# CREATE SERVER myserver FOREIGN DATA WRAPPER mywrapper OPTIONS (host '197.0.2.1');

Create user mappings

User mappings associate a user with authorization credentials in the foreign server. You can create a user mapping with the CREATE USER MAPPING command.

Example:

yugabyte=# CREATE USER MAPPING FOR myuser SERVER myserver OPTIONS (user 'john', password 'password');

Create foreign tables

Use the CREATE FOREIGN TABLE command to create foreign tables.

yugabyte=# CREATE FOREIGN TABLE mytable (col1 int, col2 int)
           SERVER myserver
           OPTIONS (schema 'external_schema', table 'external_table');

The following foreign data wrappers are bundled with YugabyteDB: