summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/ref/import_foreign_schema.sgml
blob: f07f757ac6fce6f4c1af47a3da2e876e0f13a183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!--
doc/src/sgml/ref/import_foreign_schema.sgml
PostgreSQL documentation
-->

<refentry id="sql-importforeignschema">
 <indexterm zone="sql-importforeignschema">
  <primary>IMPORT FOREIGN SCHEMA</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>IMPORT FOREIGN SCHEMA</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>IMPORT FOREIGN SCHEMA</refname>
  <refpurpose>import table definitions from a foreign server</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
IMPORT FOREIGN SCHEMA <replaceable class="parameter">remote_schema</replaceable>
    [ { LIMIT TO | EXCEPT } ( <replaceable class="parameter">table_name</replaceable> [, ...] ) ]
    FROM SERVER <replaceable class="parameter">server_name</replaceable>
    INTO <replaceable class="parameter">local_schema</replaceable>
    [ OPTIONS ( <replaceable class="parameter">option</replaceable> '<replaceable class="parameter">value</replaceable>' [, ... ] ) ]
</synopsis>
 </refsynopsisdiv>

 <refsect1 id="sql-importforeignschema-description">
  <title>Description</title>

  <para>
   <command>IMPORT FOREIGN SCHEMA</command> creates foreign tables that
   represent tables existing on a foreign server.  The new foreign tables
   will be owned by the user issuing the command and are created with
   the correct column definitions and options to match the remote tables.
  </para>

  <para>
   By default, all tables and views existing in a particular schema on the
   foreign server are imported.  Optionally, the list of tables can be limited
   to a specified subset, or specific tables can be excluded.  The new foreign
   tables are all created in the target schema, which must already exist.
  </para>

  <para>
   To use <command>IMPORT FOREIGN SCHEMA</command>, the user must have
   <literal>USAGE</literal> privilege on the foreign server, as well as
   <literal>CREATE</literal> privilege on the target schema.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>

   <varlistentry>
    <term><replaceable class="parameter">remote_schema</replaceable></term>
    <listitem>
     <para>
      The remote schema to import from. The specific meaning of a remote schema
      depends on the foreign data wrapper in use.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>LIMIT TO ( <replaceable class="parameter">table_name</replaceable> [, ...] )</literal></term>
    <listitem>
     <para>
      Import only foreign tables matching one of the given table names.
      Other tables existing in the foreign schema will be ignored.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>EXCEPT ( <replaceable class="parameter">table_name</replaceable> [, ...] )</literal></term>
    <listitem>
     <para>
      Exclude specified foreign tables from the import.  All tables
      existing in the foreign schema will be imported except the
      ones listed here.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">server_name</replaceable></term>
    <listitem>
     <para>
      The foreign server to import from.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">local_schema</replaceable></term>
    <listitem>
     <para>
      The schema in which the imported foreign tables will be created.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>OPTIONS ( <replaceable class="parameter">option</replaceable> '<replaceable class="parameter">value</replaceable>' [, ...] )</literal></term>
    <listitem>
     <para>
      Options to be used during the import.
      The allowed option names and values are specific to each foreign
      data wrapper.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1 id="sql-importforeignschema-examples">
  <title>Examples</title>

  <para>
   Import table definitions from a remote schema <structname>foreign_films</structname>
   on server <structname>film_server</structname>, creating the foreign tables in
   local schema <structname>films</structname>:

<programlisting>
IMPORT FOREIGN SCHEMA foreign_films
    FROM SERVER film_server INTO films;
</programlisting>
   </para>

  <para>
   As above, but import only the two tables <structname>actors</structname> and
   <literal>directors</literal> (if they exist):

<programlisting>
IMPORT FOREIGN SCHEMA foreign_films LIMIT TO (actors, directors)
    FROM SERVER film_server INTO films;
</programlisting></para>
 </refsect1>

 <refsect1 id="sql-importforeignschema-compatibility">
  <title>Compatibility</title>

  <para>
   The <command>IMPORT FOREIGN SCHEMA</command> command conforms to the
   <acronym>SQL</acronym> standard, except that the <literal>OPTIONS</literal>
   clause is a <productname>PostgreSQL</productname> extension.
  </para>

 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-createforeigntable"/></member>
   <member><xref linkend="sql-createserver"/></member>
  </simplelist>
 </refsect1>
</refentry>