Skip to content

Commit 0d692a0

Browse files
committed
Basic foreign table support.
Foreign tables are a core component of SQL/MED. This commit does not provide a working SQL/MED infrastructure, because foreign tables cannot yet be queried. Support for foreign table scans will need to be added in a future patch. However, this patch creates the necessary system catalog structure, syntax support, and support for ancillary operations such as COMMENT and SECURITY LABEL. Shigeru Hanada, heavily revised by Robert Haas
1 parent 6600d5e commit 0d692a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2275
-211
lines changed

contrib/pageinspect/rawpage.c

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
119119
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
120120
errmsg("cannot get raw page from composite type \"%s\"",
121121
RelationGetRelationName(rel))));
122+
if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
123+
ereport(ERROR,
124+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
125+
errmsg("cannot get raw page from foreign table \"%s\"",
126+
RelationGetRelationName(rel))));
122127

123128
/*
124129
* Reject attempts to read non-local temporary relations; we would be

contrib/pgstattuple/pgstattuple.c

+3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
242242
case RELKIND_COMPOSITE_TYPE:
243243
err = "composite type";
244244
break;
245+
case RELKIND_FOREIGN_TABLE:
246+
err = "foreign table";
247+
break;
245248
default:
246249
err = "unknown";
247250
break;

doc/src/sgml/catalogs.sgml

+62-2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
<entry>foreign server definitions</entry>
149149
</row>
150150

151+
<row>
152+
<entry><link linkend="catalog-pg-foreign-table"><structname>pg_foreign_table</structname></link></entry>
153+
<entry>additional foreign table information</entry>
154+
</row>
155+
151156
<row>
152157
<entry><link linkend="catalog-pg-index"><structname>pg_index</structname></link></entry>
153158
<entry>additional index information</entry>
@@ -1656,8 +1661,8 @@
16561661
<entry>
16571662
<literal>r</> = ordinary table, <literal>i</> = index,
16581663
<literal>S</> = sequence, <literal>v</> = view, <literal>c</> =
1659-
composite type, <literal>t</> = TOAST
1660-
table
1664+
composite type, <literal>t</> = TOAST table,
1665+
<literal>f</> = foreign table
16611666
</entry>
16621667
</row>
16631668

@@ -2932,6 +2937,61 @@
29322937
</sect1>
29332938

29342939

2940+
<sect1 id="catalog-pg-foreign-table">
2941+
<title><structname>pg_foreign_table</structname></title>
2942+
2943+
<indexterm zone="catalog-pg-foreign-table">
2944+
<primary>pg_foreign_table</primary>
2945+
</indexterm>
2946+
2947+
<para>
2948+
The catalog <structname>pg_foreign_table</structname> contains part
2949+
of the information about foreign tables.
2950+
The rest is mostly in <structname>pg_class</structname>.
2951+
</para>
2952+
2953+
<table>
2954+
<title><structname>pg_foreign_table</> Columns</title>
2955+
2956+
<tgroup cols="4">
2957+
<thead>
2958+
<row>
2959+
<entry>Name</entry>
2960+
<entry>Type</entry>
2961+
<entry>References</entry>
2962+
<entry>Description</entry>
2963+
</row>
2964+
</thead>
2965+
2966+
<tbody>
2967+
<row>
2968+
<entry><structfield>ftrelid</structfield></entry>
2969+
<entry><type>oid</type></entry>
2970+
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
2971+
<entry>The OID of the <structname>pg_class</> entry for this foreign table</entry>
2972+
</row>
2973+
2974+
<row>
2975+
<entry><structfield>ftserver</structfield></entry>
2976+
<entry><type>oid</type></entry>
2977+
<entry><literal><link linkend="catalog-pg-foreign-server"><structname>pg_foreign_server</structname></link>.oid</literal></entry>
2978+
<entry>The OID of the foreign server for this foreign table</entry>
2979+
</row>
2980+
2981+
<row>
2982+
<entry><structfield>ftoptions</structfield></entry>
2983+
<entry><type>text[]</type></entry>
2984+
<entry></entry>
2985+
<entry>
2986+
Foreign table options, as <quote>keyword=value</> strings.
2987+
</entry>
2988+
</row>
2989+
</tbody>
2990+
</tgroup>
2991+
</table>
2992+
</sect1>
2993+
2994+
29352995
<sect1 id="catalog-pg-index">
29362996
<title><structname>pg_index</structname></title>
29372997

doc/src/sgml/information_schema.sgml

+129-2
Original file line numberDiff line numberDiff line change
@@ -2384,6 +2384,132 @@ ORDER BY c.ordinal_position;
23842384
</table>
23852385
</sect1>
23862386

2387+
<sect1 id="infoschema-foreign-table-options">
2388+
<title><literal>foreign_table_options</literal></title>
2389+
2390+
<para>
2391+
The view <literal>foreign_table_options</literal> contains all the
2392+
options defined for foreign tables in the current database. Only
2393+
those foreign tables are shown that the current user has access to
2394+
(by way of being the owner or having some privilege).
2395+
</para>
2396+
2397+
<table>
2398+
<title><literal>foreign_table_options</literal> Columns</title>
2399+
2400+
<tgroup cols="3">
2401+
<thead>
2402+
<row>
2403+
<entry>Name</entry>
2404+
<entry>Data Type</entry>
2405+
<entry>Description</entry>
2406+
</row>
2407+
</thead>
2408+
2409+
<tbody>
2410+
<row>
2411+
<entry><literal>foreign_table_catalog</literal></entry>
2412+
<entry><type>sql_identifier</type></entry>
2413+
<entry>Name of the database that contains the foreign table (always the current database)</entry>
2414+
</row>
2415+
2416+
<row>
2417+
<entry><literal>foreign_table_schema</literal></entry>
2418+
<entry><type>sql_identifier</type></entry>
2419+
<entry>Name of the schema that contains the foreign table</entry>
2420+
</row>
2421+
2422+
<row>
2423+
<entry><literal>foreign_table_name</literal></entry>
2424+
<entry><type>sql_identifier</type></entry>
2425+
<entry>Name of the foreign table</entry>
2426+
</row>
2427+
2428+
<row>
2429+
<entry><literal>foreign_server_catalog</literal></entry>
2430+
<entry><type>sql_identifier</type></entry>
2431+
<entry>Name of the database that the foreign server is defined in (always the current database)</entry>
2432+
</row>
2433+
2434+
<row>
2435+
<entry><literal>foreign_server_name</literal></entry>
2436+
<entry><type>sql_identifier</type></entry>
2437+
<entry>Name of the foreign server</entry>
2438+
</row>
2439+
2440+
<row>
2441+
<entry><literal>option_name</literal></entry>
2442+
<entry><type>sql_identifier</type></entry>
2443+
<entry>Name of an option</entry>
2444+
</row>
2445+
2446+
<row>
2447+
<entry><literal>option_value</literal></entry>
2448+
<entry><type>character_data</type></entry>
2449+
<entry>Value of the option</entry>
2450+
</row>
2451+
</tbody>
2452+
</tgroup>
2453+
</table>
2454+
</sect1>
2455+
2456+
<sect1 id="infoschema-foreign-tables">
2457+
<title><literal>foreign_tables</literal></title>
2458+
2459+
<para>
2460+
The view <literal>foreign_tables</literal> contains all foreign
2461+
tables defined in the current database. Only those foreign
2462+
tables are shown that the current user has access to (by way of
2463+
being the owner or having some privilege).
2464+
</para>
2465+
2466+
<table>
2467+
<title><literal>foreign_tables</literal> Columns</title>
2468+
2469+
<tgroup cols="3">
2470+
<thead>
2471+
<row>
2472+
<entry>Name</entry>
2473+
<entry>Data Type</entry>
2474+
<entry>Description</entry>
2475+
</row>
2476+
</thead>
2477+
2478+
<tbody>
2479+
<row>
2480+
<entry><literal>foreign_table_catalog</literal></entry>
2481+
<entry><type>sql_identifier</type></entry>
2482+
<entry>Name of the database that the foreign table is defined in (always the current database)</entry>
2483+
</row>
2484+
2485+
<row>
2486+
<entry><literal>foreign_table_schema</literal></entry>
2487+
<entry><type>sql_identifier</type></entry>
2488+
<entry>Name of the schema that contains the foreign table</entry>
2489+
</row>
2490+
2491+
<row>
2492+
<entry><literal>foreign_table_name</literal></entry>
2493+
<entry><type>sql_identifier</type></entry>
2494+
<entry>Name of the foreign table</entry>
2495+
</row>
2496+
2497+
<row>
2498+
<entry><literal>foreign_server_catalog</literal></entry>
2499+
<entry><type>sql_identifier</type></entry>
2500+
<entry>Name of the database that the foreign server is defined in (always the current database)</entry>
2501+
</row>
2502+
2503+
<row>
2504+
<entry><literal>foreign_server_name</literal></entry>
2505+
<entry><type>sql_identifier</type></entry>
2506+
<entry>Name of the foreign server</entry>
2507+
</row>
2508+
</tbody>
2509+
</tgroup>
2510+
</table>
2511+
</sect1>
2512+
23872513
<sect1 id="infoschema-key-column-usage">
23882514
<title><literal>key_column_usage</literal></title>
23892515

@@ -4730,8 +4856,9 @@ ORDER BY c.ordinal_position;
47304856
<entry>
47314857
Type of the table: <literal>BASE TABLE</literal> for a
47324858
persistent base table (the normal table type),
4733-
<literal>VIEW</literal> for a view, or <literal>LOCAL
4734-
TEMPORARY</literal> for a temporary table
4859+
<literal>VIEW</literal> for a view, <literal>FOREIGN TABLE</literal>
4860+
for a foreign table, or
4861+
<literal>LOCAL TEMPORARY</literal> for a temporary table
47354862
</entry>
47364863
</row>
47374864

doc/src/sgml/ref/allfiles.sgml

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Complete list of usable sgml source files in this directory.
1212
<!entity alterDefaultPrivileges system "alter_default_privileges.sgml">
1313
<!entity alterDomain system "alter_domain.sgml">
1414
<!entity alterForeignDataWrapper system "alter_foreign_data_wrapper.sgml">
15+
<!entity alterForeignTable system "alter_foreign_table.sgml">
1516
<!entity alterFunction system "alter_function.sgml">
1617
<!entity alterGroup system "alter_group.sgml">
1718
<!entity alterIndex system "alter_index.sgml">
@@ -50,6 +51,7 @@ Complete list of usable sgml source files in this directory.
5051
<!entity createDatabase system "create_database.sgml">
5152
<!entity createDomain system "create_domain.sgml">
5253
<!entity createForeignDataWrapper system "create_foreign_data_wrapper.sgml">
54+
<!entity createForeignTable system "create_foreign_table.sgml">
5355
<!entity createFunction system "create_function.sgml">
5456
<!entity createGroup system "create_group.sgml">
5557
<!entity createIndex system "create_index.sgml">
@@ -85,6 +87,7 @@ Complete list of usable sgml source files in this directory.
8587
<!entity dropDatabase system "drop_database.sgml">
8688
<!entity dropDomain system "drop_domain.sgml">
8789
<!entity dropForeignDataWrapper system "drop_foreign_data_wrapper.sgml">
90+
<!entity dropForeignTable system "drop_foreign_table.sgml">
8891
<!entity dropFunction system "drop_function.sgml">
8992
<!entity dropGroup system "drop_group.sgml">
9093
<!entity dropIndex system "drop_index.sgml">

doc/src/sgml/ref/alter_default_privileges.sgml

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ REVOKE [ GRANT OPTION FOR ]
7171
<command>ALTER DEFAULT PRIVILEGES</> allows you to set the privileges
7272
that will be applied to objects created in the future. (It does not
7373
affect privileges assigned to already-existing objects.) Currently,
74-
only the privileges for tables (including views), sequences, and
75-
functions can be altered.
74+
only the privileges for tables (including views and foreign tables),
75+
sequences, and functions can be altered.
7676
</para>
7777

7878
<para>

0 commit comments

Comments
 (0)