From 59efda3e50ca4de6a9d5aa4491464e22b6329b1e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 10 Jul 2014 15:01:31 -0400 Subject: Implement IMPORT FOREIGN SCHEMA. This command provides an automated way to create foreign table definitions that match remote tables, thereby reducing tedium and chances for error. In this patch, we provide the necessary core-server infrastructure and implement the feature fully in the postgres_fdw foreign-data wrapper. Other wrappers will throw a "feature not supported" error until/unless they are updated. Ronan Dunklau and Michael Paquier, additional work by me --- doc/src/sgml/postgres-fdw.sgml | 75 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) (limited to 'doc/src/sgml/postgres-fdw.sgml') diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml index e6f6e205815..43adb61455d 100644 --- a/doc/src/sgml/postgres-fdw.sgml +++ b/doc/src/sgml/postgres-fdw.sgml @@ -49,7 +49,8 @@ - Create a foreign table, using , + Create a foreign table, using + or , for each remote table you want to access. The columns of the foreign table must match the referenced remote table. You can, however, use table and/or column names different from the remote table's, if you @@ -99,7 +100,7 @@ user and password (specify these - for a user mapping, instead) + in a user mapping, instead) @@ -291,6 +292,72 @@ + + + Importing Options + + + postgres_fdw is able to import foreign table definitions + using . This command creates + foreign table definitions on the local server that match tables or + views present on the remote server. If the remote tables to be imported + have columns of user-defined data types, the local server must have types + of the same names. + + + + Importing behavior can be customized with the following options + (given in the IMPORT FOREIGN SCHEMA command): + + + + + import_collate + + + This option controls whether column COLLATE options + are included in the definitions of foreign tables imported + from a foreign server. The default is true. You might + need to turn this off if the remote server has a different set of + collation names than the local server does, which is likely to be the + case if it's running on a different operating system. + + + + + import_default + + + This option controls whether column DEFAULT expressions + are included in the definitions of foreign tables imported + from a foreign server. The default is false. If you + enable this option, be wary of defaults that might get computed + differently on the local server than they would be on the remote + server; nextval() is a common source of problems. + The IMPORT will fail altogether if an imported default + expression uses a function or operator that does not exist locally. + + + + + import_not_null + + + This option controls whether column NOT NULL + constraints are included in the definitions of foreign tables imported + from a foreign server. The default is true. + + + + + + + Note that constraints other than NOT NULL will never be + imported from the remote tables, since PostgreSQL + does not support any other type of constraint on a foreign table. + Checking other types of constraints is always left to the remote server. + + @@ -422,7 +489,7 @@ CREATE USER MAPPING FOR local_user CREATE FOREIGN TABLE foreign_table ( - id serial NOT NULL, + id integer NOT NULL, data text ) SERVER foreign_server @@ -434,6 +501,8 @@ CREATE FOREIGN TABLE foreign_table ( Column names must match as well, unless you attach column_name options to the individual columns to show how they are named in the remote table. + In many cases, use of is + preferable to constructing foreign table definitions manually. -- cgit v1.2.3