Add some examples to the postgres_fdw documentation.
authorTom Lane
Fri, 31 Jan 2014 22:27:50 +0000 (17:27 -0500)
committerTom Lane
Fri, 31 Jan 2014 22:28:02 +0000 (17:28 -0500)
Michael Paquier

doc/src/sgml/postgres-fdw.sgml

index 35924f19f262172d82ac8beef128ae2fd95c3467..e6f6e205815cae003f3554d1b8df0f5885d28deb 100644 (file)
   
  
 
+  Examples
+
+  
+   Here is an example of creating a foreign table with
+   postgres_fdw. First install the extension:
+  
+
+
+CREATE EXTENSION postgres_fdw;
+
+
+  
+   Then create a foreign server using .
+   In this example we wish to connect to a PostgreSQL server
+   on host 192.83.123.89 listening on
+   port 5432.  The database to which the connection is made
+   is named foreign_db on the remote server:
+
+
+CREATE SERVER foreign_server
+        FOREIGN DATA WRAPPER postgres_fdw
+        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');
+
+  
+
+  
+   A user mapping, defined with , is
+   needed as well to identify the role that will be used on the remote
+   server:
+
+
+CREATE USER MAPPING FOR local_user
+        SERVER foreign_server
+        OPTIONS (user 'foreign_user', password 'password');
+
+  
+
+  
+   Now it is possible to create a foreign table with
+   .  In this example we
+   wish to access the table named some_schema.some_table
+   on the remote server.  The local name for it will
+   be foreign_table:
+
+
+CREATE FOREIGN TABLE foreign_table (
+        id serial NOT NULL,
+        data text
+)
+        SERVER foreign_server
+        OPTIONS (schema_name 'some_schema', table_name 'some_table');
+
+
+   It's essential that the data types and other properties of the columns
+   declared in CREATE FOREIGN TABLE match the actual remote 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.
+  
+
  
   Author