mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Create the catalog infrastructure for foreign-data-wrapper handlers.
Add a fdwhandler column to pg_foreign_data_wrapper, plus HANDLER options in the CREATE FOREIGN DATA WRAPPER and ALTER FOREIGN DATA WRAPPER commands, plus pg_dump support for same. Also invent a new pseudotype fdw_handler with properties similar to language_handler. This is split out of the "FDW API" patch for ease of review; it's all stuff we will certainly need, regardless of any other details of the FDW API. FDW handler functions will not actually get called yet. In passing, fix some omissions and infelicities in foreigncmds.c. Shigeru Hanada, Jan Urbanski, Heikki Linnakangas
This commit is contained in:
parent
4077980d67
commit
327e025071
@ -3031,16 +3031,27 @@
|
|||||||
<entry>Owner of the foreign-data wrapper</entry>
|
<entry>Owner of the foreign-data wrapper</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
|
<row>
|
||||||
|
<entry><structfield>fdwhandler</structfield></entry>
|
||||||
|
<entry><type>oid</type></entry>
|
||||||
|
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
|
||||||
|
<entry>
|
||||||
|
References a handler function that is responsible for
|
||||||
|
supplying execution routines for the foreign-data wrapper.
|
||||||
|
Zero if no handler is provided
|
||||||
|
</entry>
|
||||||
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>fdwvalidator</structfield></entry>
|
<entry><structfield>fdwvalidator</structfield></entry>
|
||||||
<entry><type>oid</type></entry>
|
<entry><type>oid</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
|
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
|
||||||
<entry>
|
<entry>
|
||||||
References a validator function that is responsible for
|
References a validator function that is responsible for
|
||||||
checking the validity of the generic options given to the
|
checking the validity of the options given to the
|
||||||
foreign-data wrapper, as well as to foreign servers and user
|
foreign-data wrapper, as well as options for foreign servers and user
|
||||||
mappings using the foreign-data wrapper. Zero if no validator
|
mappings using the foreign-data wrapper. Zero if no validator
|
||||||
is provided.
|
is provided
|
||||||
</entry>
|
</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
@ -3079,8 +3090,8 @@
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
The catalog <structname>pg_foreign_server</structname> stores
|
The catalog <structname>pg_foreign_server</structname> stores
|
||||||
foreign server definitions. A foreign server describes the
|
foreign server definitions. A foreign server describes a source
|
||||||
connection to a remote server, managing external data. Foreign
|
of external data, such as a remote server. Foreign
|
||||||
servers are accessed via foreign-data wrappers.
|
servers are accessed via foreign-data wrappers.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -3116,7 +3127,7 @@
|
|||||||
<entry><structfield>srvfdw</structfield></entry>
|
<entry><structfield>srvfdw</structfield></entry>
|
||||||
<entry><type>oid</type></entry>
|
<entry><type>oid</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-foreign-data-wrapper"><structname>pg_foreign_data_wrapper</structname></link>.oid</literal></entry>
|
<entry><literal><link linkend="catalog-pg-foreign-data-wrapper"><structname>pg_foreign_data_wrapper</structname></link>.oid</literal></entry>
|
||||||
<entry>The OID of the foreign-data wrapper of this foreign server</entry>
|
<entry>OID of the foreign-data wrapper of this foreign server</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
@ -3167,9 +3178,12 @@
|
|||||||
</indexterm>
|
</indexterm>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The catalog <structname>pg_foreign_table</structname> contains part
|
The catalog <structname>pg_foreign_table</structname> contains
|
||||||
of the information about foreign tables.
|
auxiliary information about foreign tables. A foreign table is
|
||||||
The rest is mostly in <structname>pg_class</structname>.
|
primarily represented by a <structname>pg_class</structname> entry,
|
||||||
|
just like a regular table. Its <structname>pg_foreign_table</structname>
|
||||||
|
entry contains the information that is pertinent only to foreign tables
|
||||||
|
and not any other kind of relation.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
@ -3190,14 +3204,14 @@
|
|||||||
<entry><structfield>ftrelid</structfield></entry>
|
<entry><structfield>ftrelid</structfield></entry>
|
||||||
<entry><type>oid</type></entry>
|
<entry><type>oid</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
|
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
|
||||||
<entry>The OID of the <structname>pg_class</> entry for this foreign table</entry>
|
<entry>OID of the <structname>pg_class</> entry for this foreign table</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>ftserver</structfield></entry>
|
<entry><structfield>ftserver</structfield></entry>
|
||||||
<entry><type>oid</type></entry>
|
<entry><type>oid</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-foreign-server"><structname>pg_foreign_server</structname></link>.oid</literal></entry>
|
<entry><literal><link linkend="catalog-pg-foreign-server"><structname>pg_foreign_server</structname></link>.oid</literal></entry>
|
||||||
<entry>The OID of the foreign server for this foreign table</entry>
|
<entry>OID of the foreign server for this foreign table</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
@ -3205,7 +3219,7 @@
|
|||||||
<entry><type>text[]</type></entry>
|
<entry><type>text[]</type></entry>
|
||||||
<entry></entry>
|
<entry></entry>
|
||||||
<entry>
|
<entry>
|
||||||
Foreign table options, as <quote>keyword=value</> strings.
|
Foreign table options, as <quote>keyword=value</> strings
|
||||||
</entry>
|
</entry>
|
||||||
</row>
|
</row>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -4431,6 +4431,10 @@ SELECT * FROM pg_attribute
|
|||||||
<primary>language_handler</primary>
|
<primary>language_handler</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
|
|
||||||
|
<indexterm zone="datatype-pseudo">
|
||||||
|
<primary>fdw_handler</primary>
|
||||||
|
</indexterm>
|
||||||
|
|
||||||
<indexterm zone="datatype-pseudo">
|
<indexterm zone="datatype-pseudo">
|
||||||
<primary>cstring</primary>
|
<primary>cstring</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
@ -4513,6 +4517,11 @@ SELECT * FROM pg_attribute
|
|||||||
<entry>A procedural language call handler is declared to return <type>language_handler</>.</entry>
|
<entry>A procedural language call handler is declared to return <type>language_handler</>.</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
|
<row>
|
||||||
|
<entry><type>fdw_handler</></entry>
|
||||||
|
<entry>A foreign-data wrapper handler is declared to return <type>fdw_handler</>.</entry>
|
||||||
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><type>record</></entry>
|
<entry><type>record</></entry>
|
||||||
<entry>Identifies a function returning an unspecified row type.</entry>
|
<entry>Identifies a function returning an unspecified row type.</entry>
|
||||||
|
@ -22,7 +22,8 @@ PostgreSQL documentation
|
|||||||
<refsynopsisdiv>
|
<refsynopsisdiv>
|
||||||
<synopsis>
|
<synopsis>
|
||||||
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
||||||
[ VALIDATOR <replaceable class="parameter">valfunction</replaceable> | NO VALIDATOR ]
|
[ HANDLER <replaceable class="parameter">handler_function</replaceable> | NO HANDLER ]
|
||||||
|
[ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
|
||||||
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) ]
|
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) ]
|
||||||
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
|
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
|
||||||
</synopsis>
|
</synopsis>
|
||||||
@ -34,7 +35,7 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWN
|
|||||||
<para>
|
<para>
|
||||||
<command>ALTER FOREIGN DATA WRAPPER</command> changes the
|
<command>ALTER FOREIGN DATA WRAPPER</command> changes the
|
||||||
definition of a foreign-data wrapper. The first form of the
|
definition of a foreign-data wrapper. The first form of the
|
||||||
command changes the library or the generic options of the
|
command changes the support functions or the generic options of the
|
||||||
foreign-data wrapper (at least one clause is required). The second
|
foreign-data wrapper (at least one clause is required). The second
|
||||||
form changes the owner of the foreign-data wrapper.
|
form changes the owner of the foreign-data wrapper.
|
||||||
</para>
|
</para>
|
||||||
@ -59,10 +60,33 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWN
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>VALIDATOR <replaceable class="parameter">valfunction</replaceable></literal></term>
|
<term><literal>HANDLER <replaceable class="parameter">handler_function</replaceable></literal></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies a new foreign-data wrapper validator function.
|
Specifies a new handler function for the foreign-data wrapper.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>NO HANDLER</literal></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
This is used to specify that the foreign-data wrapper should no
|
||||||
|
longer have a handler function.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
Note that foreign tables that use a foreign-data wrapper with no
|
||||||
|
handler cannot be accessed.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>VALIDATOR <replaceable class="parameter">validator_function</replaceable></literal></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Specifies a new validator function for the foreign-data wrapper.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@ -94,7 +118,7 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWN
|
|||||||
specify the action to be performed. <literal>ADD</> is assumed
|
specify the action to be performed. <literal>ADD</> is assumed
|
||||||
if no operation is explicitly specified. Option names must be
|
if no operation is explicitly specified. Option names must be
|
||||||
unique; names and values are also validated using the foreign
|
unique; names and values are also validated using the foreign
|
||||||
data wrapper library.
|
data wrapper's validator function, if any.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -126,9 +150,8 @@ ALTER FOREIGN DATA WRAPPER dbi VALIDATOR bob.myvalidator;
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
|
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
|
||||||
9075-9 (SQL/MED). The standard does not specify the <literal>
|
9075-9 (SQL/MED), except that the <literal>HANDLER</literal>,
|
||||||
VALIDATOR</literal> and <literal>OWNER TO</> variants of the
|
<literal>VALIDATOR</> and <literal>OWNER TO</> clauses are extensions.
|
||||||
command.
|
|
||||||
</para>
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ PostgreSQL documentation
|
|||||||
<refsynopsisdiv>
|
<refsynopsisdiv>
|
||||||
<synopsis>
|
<synopsis>
|
||||||
CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
||||||
[ VALIDATOR <replaceable class="parameter">valfunction</replaceable> | NO VALIDATOR ]
|
[ HANDLER <replaceable class="parameter">handler_function</replaceable> | NO HANDLER ]
|
||||||
|
[ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
|
||||||
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
|
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
|
||||||
</synopsis>
|
</synopsis>
|
||||||
</refsynopsisdiv>
|
</refsynopsisdiv>
|
||||||
@ -59,13 +60,32 @@ CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
|||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>VALIDATOR <replaceable class="parameter">valfunction</replaceable></literal></term>
|
<term><literal>HANDLER <replaceable class="parameter">handler_function</replaceable></literal></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<replaceable class="parameter">valfunction</replaceable> is the
|
<replaceable class="parameter">handler_function</replaceable> is the
|
||||||
|
name of a previously registered function that will be called to
|
||||||
|
retrieve the execution functions for foreign tables.
|
||||||
|
The handler function must take no arguments, and
|
||||||
|
its return type must be <type>fdw_handler</type>.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
It is possible to create a foreign-data wrapper with no handler
|
||||||
|
function, but foreign tables using such a wrapper can only be declared,
|
||||||
|
not accessed.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>VALIDATOR <replaceable class="parameter">validator_function</replaceable></literal></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
<replaceable class="parameter">validator_function</replaceable> is the
|
||||||
name of a previously registered function that will be called to
|
name of a previously registered function that will be called to
|
||||||
check the generic options given to the foreign-data wrapper, as
|
check the generic options given to the foreign-data wrapper, as
|
||||||
well as to foreign servers and user mappings using the
|
well as options for foreign servers and user mappings using the
|
||||||
foreign-data wrapper. If no validator function or <literal>NO
|
foreign-data wrapper. If no validator function or <literal>NO
|
||||||
VALIDATOR</literal> is specified, then options will not be
|
VALIDATOR</literal> is specified, then options will not be
|
||||||
checked at creation time. (Foreign-data wrappers will possibly
|
checked at creation time. (Foreign-data wrappers will possibly
|
||||||
@ -75,8 +95,8 @@ CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
|||||||
contain the array of options as stored in the system catalogs,
|
contain the array of options as stored in the system catalogs,
|
||||||
and one of type <type>oid</type>, which will be the OID of the
|
and one of type <type>oid</type>, which will be the OID of the
|
||||||
system catalog containing the options. The return type is ignored;
|
system catalog containing the options. The return type is ignored;
|
||||||
the function should indicate invalid options using the
|
the function should report invalid options using the
|
||||||
<function>ereport()</function> function.
|
<function>ereport(ERROR)</function> function.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -87,8 +107,8 @@ CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
|||||||
<para>
|
<para>
|
||||||
This clause specifies options for the new foreign-data wrapper.
|
This clause specifies options for the new foreign-data wrapper.
|
||||||
The allowed option names and values are specific to each foreign
|
The allowed option names and values are specific to each foreign
|
||||||
data wrapper and are validated using the foreign-data wrapper
|
data wrapper and are validated using the foreign-data wrapper's
|
||||||
library. Option names must be unique.
|
validator function. Option names must be unique.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@ -122,17 +142,17 @@ CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
|
|||||||
<title>Examples</title>
|
<title>Examples</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Create a foreign-data wrapper <literal>dummy</>:
|
Create a useless foreign-data wrapper <literal>dummy</>:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FOREIGN DATA WRAPPER dummy;
|
CREATE FOREIGN DATA WRAPPER dummy;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Create a foreign-data wrapper <literal>postgresql</> with
|
Create a foreign-data wrapper <literal>file</> with
|
||||||
validator function <literal>postgresql_fdw_validator</>:
|
handler function <literal>file_fdw_handler</>:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
|
CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -151,10 +171,10 @@ CREATE FOREIGN DATA WRAPPER mywrapper
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
<command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
|
<command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
|
||||||
9075-9 (SQL/MED), with the exception that
|
9075-9 (SQL/MED), with the exception that the <literal>HANDLER</literal>
|
||||||
the <literal>VALIDATOR</literal> clause is an extension and the
|
and <literal>VALIDATOR</literal> clauses are extensions and the standard
|
||||||
clauses <literal>LIBRARY</literal> and <literal>LANGUAGE</literal>
|
clauses <literal>LIBRARY</literal> and <literal>LANGUAGE</literal>
|
||||||
are not yet implemented in PostgreSQL.
|
are not implemented in PostgreSQL.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -165,7 +165,7 @@ transformGenericOptions(Oid catalogId,
|
|||||||
|
|
||||||
result = optionListToArray(resultOptions);
|
result = optionListToArray(resultOptions);
|
||||||
|
|
||||||
if (fdwvalidator)
|
if (OidIsValid(fdwvalidator) && DatumGetPointer(result) != NULL)
|
||||||
OidFunctionCall2(fdwvalidator, result, ObjectIdGetDatum(catalogId));
|
OidFunctionCall2(fdwvalidator, result, ObjectIdGetDatum(catalogId));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -246,8 +246,9 @@ AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
|
|||||||
newOwnerId);
|
newOwnerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
heap_close(rel, NoLock);
|
|
||||||
heap_freetuple(tup);
|
heap_freetuple(tup);
|
||||||
|
|
||||||
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -308,25 +309,98 @@ AlterForeignServerOwner(const char *name, Oid newOwnerId)
|
|||||||
newOwnerId);
|
newOwnerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
heap_close(rel, NoLock);
|
|
||||||
heap_freetuple(tup);
|
heap_freetuple(tup);
|
||||||
|
|
||||||
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a handler function name passed from the parser to an Oid.
|
||||||
|
*/
|
||||||
|
static Oid
|
||||||
|
lookup_fdw_handler_func(DefElem *handler)
|
||||||
|
{
|
||||||
|
Oid handlerOid;
|
||||||
|
|
||||||
|
if (handler == NULL || handler->arg == NULL)
|
||||||
|
return InvalidOid;
|
||||||
|
|
||||||
|
/* handlers have no arguments */
|
||||||
|
handlerOid = LookupFuncName((List *) handler->arg, 0, NULL, false);
|
||||||
|
|
||||||
|
/* check that handler has correct return type */
|
||||||
|
if (get_func_rettype(handlerOid) != FDW_HANDLEROID)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||||
|
errmsg("function %s must return type \"fdw_handler\"",
|
||||||
|
NameListToString((List *) handler->arg))));
|
||||||
|
|
||||||
|
return handlerOid;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert a validator function name passed from the parser to an Oid.
|
* Convert a validator function name passed from the parser to an Oid.
|
||||||
*/
|
*/
|
||||||
static Oid
|
static Oid
|
||||||
lookup_fdw_validator_func(List *validator)
|
lookup_fdw_validator_func(DefElem *validator)
|
||||||
{
|
{
|
||||||
Oid funcargtypes[2];
|
Oid funcargtypes[2];
|
||||||
|
|
||||||
|
if (validator == NULL || validator->arg == NULL)
|
||||||
|
return InvalidOid;
|
||||||
|
|
||||||
|
/* validators take text[], oid */
|
||||||
funcargtypes[0] = TEXTARRAYOID;
|
funcargtypes[0] = TEXTARRAYOID;
|
||||||
funcargtypes[1] = OIDOID;
|
funcargtypes[1] = OIDOID;
|
||||||
return LookupFuncName(validator, 2, funcargtypes, false);
|
|
||||||
/* return value is ignored, so we don't check the type */
|
return LookupFuncName((List *) validator->arg, 2, funcargtypes, false);
|
||||||
|
/* validator's return value is ignored, so we don't check the type */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Process function options of CREATE/ALTER FDW
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
parse_func_options(List *func_options,
|
||||||
|
bool *handler_given, Oid *fdwhandler,
|
||||||
|
bool *validator_given, Oid *fdwvalidator)
|
||||||
|
{
|
||||||
|
ListCell *cell;
|
||||||
|
|
||||||
|
*handler_given = false;
|
||||||
|
*validator_given = false;
|
||||||
|
/* return InvalidOid if not given */
|
||||||
|
*fdwhandler = InvalidOid;
|
||||||
|
*fdwvalidator = InvalidOid;
|
||||||
|
|
||||||
|
foreach(cell, func_options)
|
||||||
|
{
|
||||||
|
DefElem *def = (DefElem *) lfirst(cell);
|
||||||
|
|
||||||
|
if (strcmp(def->defname, "handler") == 0)
|
||||||
|
{
|
||||||
|
if (*handler_given)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
|
errmsg("conflicting or redundant options")));
|
||||||
|
*handler_given = true;
|
||||||
|
*fdwhandler = lookup_fdw_handler_func(def);
|
||||||
|
}
|
||||||
|
else if (strcmp(def->defname, "validator") == 0)
|
||||||
|
{
|
||||||
|
if (*validator_given)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
|
errmsg("conflicting or redundant options")));
|
||||||
|
*validator_given = true;
|
||||||
|
*fdwvalidator = lookup_fdw_validator_func(def);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
elog(ERROR, "option \"%s\" not recognized",
|
||||||
|
def->defname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a foreign-data wrapper
|
* Create a foreign-data wrapper
|
||||||
@ -339,6 +413,9 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
|
|||||||
bool nulls[Natts_pg_foreign_data_wrapper];
|
bool nulls[Natts_pg_foreign_data_wrapper];
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
Oid fdwId;
|
Oid fdwId;
|
||||||
|
bool handler_given;
|
||||||
|
bool validator_given;
|
||||||
|
Oid fdwhandler;
|
||||||
Oid fdwvalidator;
|
Oid fdwvalidator;
|
||||||
Datum fdwoptions;
|
Datum fdwoptions;
|
||||||
Oid ownerId;
|
Oid ownerId;
|
||||||
@ -377,12 +454,13 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
|
|||||||
DirectFunctionCall1(namein, CStringGetDatum(stmt->fdwname));
|
DirectFunctionCall1(namein, CStringGetDatum(stmt->fdwname));
|
||||||
values[Anum_pg_foreign_data_wrapper_fdwowner - 1] = ObjectIdGetDatum(ownerId);
|
values[Anum_pg_foreign_data_wrapper_fdwowner - 1] = ObjectIdGetDatum(ownerId);
|
||||||
|
|
||||||
if (stmt->validator)
|
/* Lookup handler and validator functions, if given */
|
||||||
fdwvalidator = lookup_fdw_validator_func(stmt->validator);
|
parse_func_options(stmt->func_options,
|
||||||
else
|
&handler_given, &fdwhandler,
|
||||||
fdwvalidator = InvalidOid;
|
&validator_given, &fdwvalidator);
|
||||||
|
|
||||||
values[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = fdwvalidator;
|
values[Anum_pg_foreign_data_wrapper_fdwhandler - 1] = ObjectIdGetDatum(fdwhandler);
|
||||||
|
values[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = ObjectIdGetDatum(fdwvalidator);
|
||||||
|
|
||||||
nulls[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
|
nulls[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
|
||||||
|
|
||||||
@ -408,7 +486,15 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
|
|||||||
myself.objectId = fdwId;
|
myself.objectId = fdwId;
|
||||||
myself.objectSubId = 0;
|
myself.objectSubId = 0;
|
||||||
|
|
||||||
if (fdwvalidator)
|
if (OidIsValid(fdwhandler))
|
||||||
|
{
|
||||||
|
referenced.classId = ProcedureRelationId;
|
||||||
|
referenced.objectId = fdwhandler;
|
||||||
|
referenced.objectSubId = 0;
|
||||||
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OidIsValid(fdwvalidator))
|
||||||
{
|
{
|
||||||
referenced.classId = ProcedureRelationId;
|
referenced.classId = ProcedureRelationId;
|
||||||
referenced.objectId = fdwvalidator;
|
referenced.objectId = fdwvalidator;
|
||||||
@ -425,7 +511,7 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
|
|||||||
InvokeObjectAccessHook(OAT_POST_CREATE,
|
InvokeObjectAccessHook(OAT_POST_CREATE,
|
||||||
ForeignDataWrapperRelationId, fdwId, 0);
|
ForeignDataWrapperRelationId, fdwId, 0);
|
||||||
|
|
||||||
heap_close(rel, NoLock);
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -437,12 +523,16 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
|||||||
{
|
{
|
||||||
Relation rel;
|
Relation rel;
|
||||||
HeapTuple tp;
|
HeapTuple tp;
|
||||||
|
Form_pg_foreign_data_wrapper fdwForm;
|
||||||
Datum repl_val[Natts_pg_foreign_data_wrapper];
|
Datum repl_val[Natts_pg_foreign_data_wrapper];
|
||||||
bool repl_null[Natts_pg_foreign_data_wrapper];
|
bool repl_null[Natts_pg_foreign_data_wrapper];
|
||||||
bool repl_repl[Natts_pg_foreign_data_wrapper];
|
bool repl_repl[Natts_pg_foreign_data_wrapper];
|
||||||
Oid fdwId;
|
Oid fdwId;
|
||||||
bool isnull;
|
bool isnull;
|
||||||
Datum datum;
|
Datum datum;
|
||||||
|
bool handler_given;
|
||||||
|
bool validator_given;
|
||||||
|
Oid fdwhandler;
|
||||||
Oid fdwvalidator;
|
Oid fdwvalidator;
|
||||||
|
|
||||||
/* Must be super user */
|
/* Must be super user */
|
||||||
@ -461,15 +551,32 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
|||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
errmsg("foreign-data wrapper \"%s\" does not exist", stmt->fdwname)));
|
errmsg("foreign-data wrapper \"%s\" does not exist", stmt->fdwname)));
|
||||||
|
|
||||||
|
fdwForm = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);
|
||||||
fdwId = HeapTupleGetOid(tp);
|
fdwId = HeapTupleGetOid(tp);
|
||||||
|
|
||||||
memset(repl_val, 0, sizeof(repl_val));
|
memset(repl_val, 0, sizeof(repl_val));
|
||||||
memset(repl_null, false, sizeof(repl_null));
|
memset(repl_null, false, sizeof(repl_null));
|
||||||
memset(repl_repl, false, sizeof(repl_repl));
|
memset(repl_repl, false, sizeof(repl_repl));
|
||||||
|
|
||||||
if (stmt->change_validator)
|
parse_func_options(stmt->func_options,
|
||||||
|
&handler_given, &fdwhandler,
|
||||||
|
&validator_given, &fdwvalidator);
|
||||||
|
|
||||||
|
if (handler_given)
|
||||||
|
{
|
||||||
|
repl_val[Anum_pg_foreign_data_wrapper_fdwhandler - 1] = ObjectIdGetDatum(fdwhandler);
|
||||||
|
repl_repl[Anum_pg_foreign_data_wrapper_fdwhandler - 1] = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It could be that the behavior of accessing foreign table changes
|
||||||
|
* with the new handler. Warn about this.
|
||||||
|
*/
|
||||||
|
ereport(WARNING,
|
||||||
|
(errmsg("changing the foreign-data wrapper handler can change behavior of existing foreign tables")));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validator_given)
|
||||||
{
|
{
|
||||||
fdwvalidator = stmt->validator ? lookup_fdw_validator_func(stmt->validator) : InvalidOid;
|
|
||||||
repl_val[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = ObjectIdGetDatum(fdwvalidator);
|
repl_val[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = ObjectIdGetDatum(fdwvalidator);
|
||||||
repl_repl[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = true;
|
repl_repl[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = true;
|
||||||
|
|
||||||
@ -477,7 +584,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
|||||||
* It could be that the options for the FDW, SERVER and USER MAPPING
|
* It could be that the options for the FDW, SERVER and USER MAPPING
|
||||||
* are no longer valid with the new validator. Warn about this.
|
* are no longer valid with the new validator. Warn about this.
|
||||||
*/
|
*/
|
||||||
if (stmt->validator)
|
if (OidIsValid(fdwvalidator))
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errmsg("changing the foreign-data wrapper validator can cause "
|
(errmsg("changing the foreign-data wrapper validator can cause "
|
||||||
"the options for dependent objects to become invalid")));
|
"the options for dependent objects to become invalid")));
|
||||||
@ -487,16 +594,11 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
|||||||
/*
|
/*
|
||||||
* Validator is not changed, but we need it for validating options.
|
* Validator is not changed, but we need it for validating options.
|
||||||
*/
|
*/
|
||||||
datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID,
|
fdwvalidator = fdwForm->fdwvalidator;
|
||||||
tp,
|
|
||||||
Anum_pg_foreign_data_wrapper_fdwvalidator,
|
|
||||||
&isnull);
|
|
||||||
Assert(!isnull);
|
|
||||||
fdwvalidator = DatumGetObjectId(datum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Options specified, validate and update.
|
* If options specified, validate and update.
|
||||||
*/
|
*/
|
||||||
if (stmt->options)
|
if (stmt->options)
|
||||||
{
|
{
|
||||||
@ -532,8 +634,46 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
|
|||||||
simple_heap_update(rel, &tp->t_self, tp);
|
simple_heap_update(rel, &tp->t_self, tp);
|
||||||
CatalogUpdateIndexes(rel, tp);
|
CatalogUpdateIndexes(rel, tp);
|
||||||
|
|
||||||
heap_close(rel, RowExclusiveLock);
|
|
||||||
heap_freetuple(tp);
|
heap_freetuple(tp);
|
||||||
|
|
||||||
|
/* Update function dependencies if we changed them */
|
||||||
|
if (handler_given || validator_given)
|
||||||
|
{
|
||||||
|
ObjectAddress myself;
|
||||||
|
ObjectAddress referenced;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Flush all existing dependency records of this FDW on functions;
|
||||||
|
* we assume there can be none other than the ones we are fixing.
|
||||||
|
*/
|
||||||
|
deleteDependencyRecordsForClass(ForeignDataWrapperRelationId,
|
||||||
|
fdwId,
|
||||||
|
ProcedureRelationId,
|
||||||
|
DEPENDENCY_NORMAL);
|
||||||
|
|
||||||
|
/* And build new ones. */
|
||||||
|
myself.classId = ForeignDataWrapperRelationId;
|
||||||
|
myself.objectId = fdwId;
|
||||||
|
myself.objectSubId = 0;
|
||||||
|
|
||||||
|
if (OidIsValid(fdwhandler))
|
||||||
|
{
|
||||||
|
referenced.classId = ProcedureRelationId;
|
||||||
|
referenced.objectId = fdwhandler;
|
||||||
|
referenced.objectSubId = 0;
|
||||||
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OidIsValid(fdwvalidator))
|
||||||
|
{
|
||||||
|
referenced.classId = ProcedureRelationId;
|
||||||
|
referenced.objectId = fdwvalidator;
|
||||||
|
referenced.objectSubId = 0;
|
||||||
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -712,7 +852,7 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
|
|||||||
/* Post creation hook for new foreign server */
|
/* Post creation hook for new foreign server */
|
||||||
InvokeObjectAccessHook(OAT_POST_CREATE, ForeignServerRelationId, srvId, 0);
|
InvokeObjectAccessHook(OAT_POST_CREATE, ForeignServerRelationId, srvId, 0);
|
||||||
|
|
||||||
heap_close(rel, NoLock);
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -804,8 +944,9 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
|
|||||||
simple_heap_update(rel, &tp->t_self, tp);
|
simple_heap_update(rel, &tp->t_self, tp);
|
||||||
CatalogUpdateIndexes(rel, tp);
|
CatalogUpdateIndexes(rel, tp);
|
||||||
|
|
||||||
heap_close(rel, RowExclusiveLock);
|
|
||||||
heap_freetuple(tp);
|
heap_freetuple(tp);
|
||||||
|
|
||||||
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -991,7 +1132,7 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
|
|||||||
/* Post creation hook for new user mapping */
|
/* Post creation hook for new user mapping */
|
||||||
InvokeObjectAccessHook(OAT_POST_CREATE, UserMappingRelationId, umId, 0);
|
InvokeObjectAccessHook(OAT_POST_CREATE, UserMappingRelationId, umId, 0);
|
||||||
|
|
||||||
heap_close(rel, NoLock);
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1076,8 +1217,9 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
|
|||||||
simple_heap_update(rel, &tp->t_self, tp);
|
simple_heap_update(rel, &tp->t_self, tp);
|
||||||
CatalogUpdateIndexes(rel, tp);
|
CatalogUpdateIndexes(rel, tp);
|
||||||
|
|
||||||
heap_close(rel, RowExclusiveLock);
|
|
||||||
heap_freetuple(tp);
|
heap_freetuple(tp);
|
||||||
|
|
||||||
|
heap_close(rel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1184,7 +1326,6 @@ CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
|
|||||||
Datum values[Natts_pg_foreign_table];
|
Datum values[Natts_pg_foreign_table];
|
||||||
bool nulls[Natts_pg_foreign_table];
|
bool nulls[Natts_pg_foreign_table];
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
Oid ftId;
|
|
||||||
AclResult aclresult;
|
AclResult aclresult;
|
||||||
ObjectAddress myself;
|
ObjectAddress myself;
|
||||||
ObjectAddress referenced;
|
ObjectAddress referenced;
|
||||||
@ -1237,9 +1378,7 @@ CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
|
|||||||
|
|
||||||
tuple = heap_form_tuple(ftrel->rd_att, values, nulls);
|
tuple = heap_form_tuple(ftrel->rd_att, values, nulls);
|
||||||
|
|
||||||
/* pg_foreign_table don't have OID */
|
simple_heap_insert(ftrel, tuple);
|
||||||
ftId = simple_heap_insert(ftrel, tuple);
|
|
||||||
|
|
||||||
CatalogUpdateIndexes(ftrel, tuple);
|
CatalogUpdateIndexes(ftrel, tuple);
|
||||||
|
|
||||||
heap_freetuple(tuple);
|
heap_freetuple(tuple);
|
||||||
@ -1254,5 +1393,5 @@ CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
|
|||||||
referenced.objectSubId = 0;
|
referenced.objectSubId = 0;
|
||||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||||
|
|
||||||
heap_close(ftrel, NoLock);
|
heap_close(ftrel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ GetForeignDataWrapper(Oid fdwid)
|
|||||||
fdw->fdwid = fdwid;
|
fdw->fdwid = fdwid;
|
||||||
fdw->owner = fdwform->fdwowner;
|
fdw->owner = fdwform->fdwowner;
|
||||||
fdw->fdwname = pstrdup(NameStr(fdwform->fdwname));
|
fdw->fdwname = pstrdup(NameStr(fdwform->fdwname));
|
||||||
|
fdw->fdwhandler = fdwform->fdwhandler;
|
||||||
fdw->fdwvalidator = fdwform->fdwvalidator;
|
fdw->fdwvalidator = fdwform->fdwvalidator;
|
||||||
|
|
||||||
/* Extract the options */
|
/* Extract the options */
|
||||||
|
@ -3282,7 +3282,7 @@ _copyCreateFdwStmt(CreateFdwStmt *from)
|
|||||||
CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
|
CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
|
||||||
|
|
||||||
COPY_STRING_FIELD(fdwname);
|
COPY_STRING_FIELD(fdwname);
|
||||||
COPY_NODE_FIELD(validator);
|
COPY_NODE_FIELD(func_options);
|
||||||
COPY_NODE_FIELD(options);
|
COPY_NODE_FIELD(options);
|
||||||
|
|
||||||
return newnode;
|
return newnode;
|
||||||
@ -3294,8 +3294,7 @@ _copyAlterFdwStmt(AlterFdwStmt *from)
|
|||||||
AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
|
AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
|
||||||
|
|
||||||
COPY_STRING_FIELD(fdwname);
|
COPY_STRING_FIELD(fdwname);
|
||||||
COPY_NODE_FIELD(validator);
|
COPY_NODE_FIELD(func_options);
|
||||||
COPY_SCALAR_FIELD(change_validator);
|
|
||||||
COPY_NODE_FIELD(options);
|
COPY_NODE_FIELD(options);
|
||||||
|
|
||||||
return newnode;
|
return newnode;
|
||||||
|
@ -1679,7 +1679,7 @@ static bool
|
|||||||
_equalCreateFdwStmt(CreateFdwStmt *a, CreateFdwStmt *b)
|
_equalCreateFdwStmt(CreateFdwStmt *a, CreateFdwStmt *b)
|
||||||
{
|
{
|
||||||
COMPARE_STRING_FIELD(fdwname);
|
COMPARE_STRING_FIELD(fdwname);
|
||||||
COMPARE_NODE_FIELD(validator);
|
COMPARE_NODE_FIELD(func_options);
|
||||||
COMPARE_NODE_FIELD(options);
|
COMPARE_NODE_FIELD(options);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1689,8 +1689,7 @@ static bool
|
|||||||
_equalAlterFdwStmt(AlterFdwStmt *a, AlterFdwStmt *b)
|
_equalAlterFdwStmt(AlterFdwStmt *a, AlterFdwStmt *b)
|
||||||
{
|
{
|
||||||
COMPARE_STRING_FIELD(fdwname);
|
COMPARE_STRING_FIELD(fdwname);
|
||||||
COMPARE_NODE_FIELD(validator);
|
COMPARE_NODE_FIELD(func_options);
|
||||||
COMPARE_SCALAR_FIELD(change_validator);
|
|
||||||
COMPARE_NODE_FIELD(options);
|
COMPARE_NODE_FIELD(options);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -309,6 +309,9 @@ static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_
|
|||||||
create_generic_options alter_generic_options
|
create_generic_options alter_generic_options
|
||||||
relation_expr_list dostmt_opt_list
|
relation_expr_list dostmt_opt_list
|
||||||
|
|
||||||
|
%type <list> opt_fdw_options fdw_options
|
||||||
|
%type <defelt> fdw_option
|
||||||
|
|
||||||
%type <range> OptTempTableName
|
%type <range> OptTempTableName
|
||||||
%type <into> into_clause create_as_target
|
%type <into> into_clause create_as_target
|
||||||
|
|
||||||
@ -3505,20 +3508,37 @@ AlterExtensionContentsStmt:
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* QUERY:
|
* QUERY:
|
||||||
* CREATE FOREIGN DATA WRAPPER name [ VALIDATOR name ]
|
* CREATE FOREIGN DATA WRAPPER name options
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
|
CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
|
||||||
{
|
{
|
||||||
CreateFdwStmt *n = makeNode(CreateFdwStmt);
|
CreateFdwStmt *n = makeNode(CreateFdwStmt);
|
||||||
n->fdwname = $5;
|
n->fdwname = $5;
|
||||||
n->validator = $6;
|
n->func_options = $6;
|
||||||
n->options = $7;
|
n->options = $7;
|
||||||
$$ = (Node *) n;
|
$$ = (Node *) n;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
fdw_option:
|
||||||
|
HANDLER handler_name { $$ = makeDefElem("handler", (Node *)$2); }
|
||||||
|
| NO HANDLER { $$ = makeDefElem("handler", NULL); }
|
||||||
|
| VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *)$2); }
|
||||||
|
| NO VALIDATOR { $$ = makeDefElem("validator", NULL); }
|
||||||
|
;
|
||||||
|
|
||||||
|
fdw_options:
|
||||||
|
fdw_option { $$ = list_make1($1); }
|
||||||
|
| fdw_options fdw_option { $$ = lappend($1, $2); }
|
||||||
|
;
|
||||||
|
|
||||||
|
opt_fdw_options:
|
||||||
|
fdw_options { $$ = $1; }
|
||||||
|
| /*EMPTY*/ { $$ = NIL; }
|
||||||
|
;
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* QUERY :
|
* QUERY :
|
||||||
@ -3547,32 +3567,24 @@ DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* QUERY :
|
* QUERY :
|
||||||
* ALTER FOREIGN DATA WRAPPER name
|
* ALTER FOREIGN DATA WRAPPER name options
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
|
AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
|
||||||
{
|
{
|
||||||
AlterFdwStmt *n = makeNode(AlterFdwStmt);
|
AlterFdwStmt *n = makeNode(AlterFdwStmt);
|
||||||
n->fdwname = $5;
|
n->fdwname = $5;
|
||||||
n->validator = $6;
|
n->func_options = $6;
|
||||||
n->change_validator = true;
|
|
||||||
n->options = $7;
|
n->options = $7;
|
||||||
$$ = (Node *) n;
|
$$ = (Node *) n;
|
||||||
}
|
}
|
||||||
| ALTER FOREIGN DATA_P WRAPPER name validator_clause
|
| ALTER FOREIGN DATA_P WRAPPER name fdw_options
|
||||||
{
|
{
|
||||||
AlterFdwStmt *n = makeNode(AlterFdwStmt);
|
AlterFdwStmt *n = makeNode(AlterFdwStmt);
|
||||||
n->fdwname = $5;
|
n->fdwname = $5;
|
||||||
n->validator = $6;
|
n->func_options = $6;
|
||||||
n->change_validator = true;
|
n->options = NIL;
|
||||||
$$ = (Node *) n;
|
|
||||||
}
|
|
||||||
| ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
|
|
||||||
{
|
|
||||||
AlterFdwStmt *n = makeNode(AlterFdwStmt);
|
|
||||||
n->fdwname = $5;
|
|
||||||
n->options = $6;
|
|
||||||
$$ = (Node *) n;
|
$$ = (Node *) n;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -267,6 +267,33 @@ language_handler_out(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fdw_handler_in - input routine for pseudo-type FDW_HANDLER.
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
fdw_handler_in(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot accept a value of type fdw_handler")));
|
||||||
|
|
||||||
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fdw_handler_out - output routine for pseudo-type FDW_HANDLER.
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
fdw_handler_out(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot display a value of type fdw_handler")));
|
||||||
|
|
||||||
|
PG_RETURN_VOID(); /* keep compiler quiet */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* internal_in - input routine for pseudo-type INTERNAL.
|
* internal_in - input routine for pseudo-type INTERNAL.
|
||||||
*/
|
*/
|
||||||
|
@ -6260,6 +6260,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
|||||||
int i_oid;
|
int i_oid;
|
||||||
int i_fdwname;
|
int i_fdwname;
|
||||||
int i_rolname;
|
int i_rolname;
|
||||||
|
int i_fdwhandler;
|
||||||
int i_fdwvalidator;
|
int i_fdwvalidator;
|
||||||
int i_fdwacl;
|
int i_fdwacl;
|
||||||
int i_fdwoptions;
|
int i_fdwoptions;
|
||||||
@ -6274,13 +6275,30 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
|||||||
/* Make sure we are in proper schema */
|
/* Make sure we are in proper schema */
|
||||||
selectSourceSchema("pg_catalog");
|
selectSourceSchema("pg_catalog");
|
||||||
|
|
||||||
|
if (g_fout->remoteVersion >= 90100)
|
||||||
|
{
|
||||||
appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
|
appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
|
||||||
"(%s fdwowner) AS rolname, fdwvalidator::pg_catalog.regproc, fdwacl,"
|
"(%s fdwowner) AS rolname, "
|
||||||
|
"fdwhandler::pg_catalog.regproc, "
|
||||||
|
"fdwvalidator::pg_catalog.regproc, fdwacl, "
|
||||||
"array_to_string(ARRAY("
|
"array_to_string(ARRAY("
|
||||||
" SELECT option_name || ' ' || quote_literal(option_value) "
|
" SELECT option_name || ' ' || quote_literal(option_value) "
|
||||||
" FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
|
" FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
|
||||||
"FROM pg_foreign_data_wrapper",
|
"FROM pg_foreign_data_wrapper",
|
||||||
username_subquery);
|
username_subquery);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
|
||||||
|
"(%s fdwowner) AS rolname, "
|
||||||
|
"'-' AS fdwhandler, "
|
||||||
|
"fdwvalidator::pg_catalog.regproc, fdwacl, "
|
||||||
|
"array_to_string(ARRAY("
|
||||||
|
" SELECT option_name || ' ' || quote_literal(option_value) "
|
||||||
|
" FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
|
||||||
|
"FROM pg_foreign_data_wrapper",
|
||||||
|
username_subquery);
|
||||||
|
}
|
||||||
|
|
||||||
res = PQexec(g_conn, query->data);
|
res = PQexec(g_conn, query->data);
|
||||||
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
|
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
|
||||||
@ -6294,6 +6312,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
|||||||
i_oid = PQfnumber(res, "oid");
|
i_oid = PQfnumber(res, "oid");
|
||||||
i_fdwname = PQfnumber(res, "fdwname");
|
i_fdwname = PQfnumber(res, "fdwname");
|
||||||
i_rolname = PQfnumber(res, "rolname");
|
i_rolname = PQfnumber(res, "rolname");
|
||||||
|
i_fdwhandler = PQfnumber(res, "fdwhandler");
|
||||||
i_fdwvalidator = PQfnumber(res, "fdwvalidator");
|
i_fdwvalidator = PQfnumber(res, "fdwvalidator");
|
||||||
i_fdwacl = PQfnumber(res, "fdwacl");
|
i_fdwacl = PQfnumber(res, "fdwacl");
|
||||||
i_fdwoptions = PQfnumber(res, "fdwoptions");
|
i_fdwoptions = PQfnumber(res, "fdwoptions");
|
||||||
@ -6307,11 +6326,11 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
|||||||
fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname));
|
fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname));
|
||||||
fdwinfo[i].dobj.namespace = NULL;
|
fdwinfo[i].dobj.namespace = NULL;
|
||||||
fdwinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
|
fdwinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
|
||||||
|
fdwinfo[i].fdwhandler = strdup(PQgetvalue(res, i, i_fdwhandler));
|
||||||
fdwinfo[i].fdwvalidator = strdup(PQgetvalue(res, i, i_fdwvalidator));
|
fdwinfo[i].fdwvalidator = strdup(PQgetvalue(res, i, i_fdwvalidator));
|
||||||
fdwinfo[i].fdwoptions = strdup(PQgetvalue(res, i, i_fdwoptions));
|
fdwinfo[i].fdwoptions = strdup(PQgetvalue(res, i, i_fdwoptions));
|
||||||
fdwinfo[i].fdwacl = strdup(PQgetvalue(res, i, i_fdwacl));
|
fdwinfo[i].fdwacl = strdup(PQgetvalue(res, i, i_fdwacl));
|
||||||
|
|
||||||
|
|
||||||
/* Decide whether we want to dump it */
|
/* Decide whether we want to dump it */
|
||||||
selectDumpableObject(&(fdwinfo[i].dobj));
|
selectDumpableObject(&(fdwinfo[i].dobj));
|
||||||
}
|
}
|
||||||
@ -10929,11 +10948,13 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
|
|||||||
appendPQExpBuffer(q, "CREATE FOREIGN DATA WRAPPER %s",
|
appendPQExpBuffer(q, "CREATE FOREIGN DATA WRAPPER %s",
|
||||||
qfdwname);
|
qfdwname);
|
||||||
|
|
||||||
if (fdwinfo->fdwvalidator && strcmp(fdwinfo->fdwvalidator, "-") != 0)
|
if (strcmp(fdwinfo->fdwhandler, "-") != 0)
|
||||||
appendPQExpBuffer(q, " VALIDATOR %s",
|
appendPQExpBuffer(q, " HANDLER %s", fdwinfo->fdwhandler);
|
||||||
fdwinfo->fdwvalidator);
|
|
||||||
|
|
||||||
if (fdwinfo->fdwoptions && strlen(fdwinfo->fdwoptions) > 0)
|
if (strcmp(fdwinfo->fdwvalidator, "-") != 0)
|
||||||
|
appendPQExpBuffer(q, " VALIDATOR %s", fdwinfo->fdwvalidator);
|
||||||
|
|
||||||
|
if (strlen(fdwinfo->fdwoptions) > 0)
|
||||||
appendPQExpBuffer(q, " OPTIONS (%s)", fdwinfo->fdwoptions);
|
appendPQExpBuffer(q, " OPTIONS (%s)", fdwinfo->fdwoptions);
|
||||||
|
|
||||||
appendPQExpBuffer(q, ";\n");
|
appendPQExpBuffer(q, ";\n");
|
||||||
|
@ -440,6 +440,7 @@ typedef struct _fdwInfo
|
|||||||
{
|
{
|
||||||
DumpableObject dobj;
|
DumpableObject dobj;
|
||||||
char *rolname;
|
char *rolname;
|
||||||
|
char *fdwhandler;
|
||||||
char *fdwvalidator;
|
char *fdwvalidator;
|
||||||
char *fdwoptions;
|
char *fdwoptions;
|
||||||
char *fdwacl;
|
char *fdwacl;
|
||||||
|
@ -3562,10 +3562,15 @@ listForeignDataWrappers(const char *pattern, bool verbose)
|
|||||||
initPQExpBuffer(&buf);
|
initPQExpBuffer(&buf);
|
||||||
printfPQExpBuffer(&buf,
|
printfPQExpBuffer(&buf,
|
||||||
"SELECT fdwname AS \"%s\",\n"
|
"SELECT fdwname AS \"%s\",\n"
|
||||||
" pg_catalog.pg_get_userbyid(fdwowner) AS \"%s\",\n"
|
" pg_catalog.pg_get_userbyid(fdwowner) AS \"%s\",\n",
|
||||||
" fdwvalidator::pg_catalog.regproc AS \"%s\"",
|
|
||||||
gettext_noop("Name"),
|
gettext_noop("Name"),
|
||||||
gettext_noop("Owner"),
|
gettext_noop("Owner"));
|
||||||
|
if (pset.sversion >= 90100)
|
||||||
|
appendPQExpBuffer(&buf,
|
||||||
|
" fdwhandler::pg_catalog.regproc AS \"%s\",\n",
|
||||||
|
gettext_noop("Handler"));
|
||||||
|
appendPQExpBuffer(&buf,
|
||||||
|
" fdwvalidator::pg_catalog.regproc AS \"%s\"",
|
||||||
gettext_noop("Validator"));
|
gettext_noop("Validator"));
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 201102181
|
#define CATALOG_VERSION_NO 201102191
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,7 +32,8 @@ CATALOG(pg_foreign_data_wrapper,2328)
|
|||||||
{
|
{
|
||||||
NameData fdwname; /* foreign-data wrapper name */
|
NameData fdwname; /* foreign-data wrapper name */
|
||||||
Oid fdwowner; /* FDW owner */
|
Oid fdwowner; /* FDW owner */
|
||||||
Oid fdwvalidator; /* optional validation function */
|
Oid fdwhandler; /* handler function, or 0 if none */
|
||||||
|
Oid fdwvalidator; /* option validation function, or 0 if none */
|
||||||
|
|
||||||
/* VARIABLE LENGTH FIELDS start here. */
|
/* VARIABLE LENGTH FIELDS start here. */
|
||||||
|
|
||||||
@ -52,11 +53,12 @@ typedef FormData_pg_foreign_data_wrapper *Form_pg_foreign_data_wrapper;
|
|||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Natts_pg_foreign_data_wrapper 5
|
#define Natts_pg_foreign_data_wrapper 6
|
||||||
#define Anum_pg_foreign_data_wrapper_fdwname 1
|
#define Anum_pg_foreign_data_wrapper_fdwname 1
|
||||||
#define Anum_pg_foreign_data_wrapper_fdwowner 2
|
#define Anum_pg_foreign_data_wrapper_fdwowner 2
|
||||||
#define Anum_pg_foreign_data_wrapper_fdwvalidator 3
|
#define Anum_pg_foreign_data_wrapper_fdwhandler 3
|
||||||
#define Anum_pg_foreign_data_wrapper_fdwacl 4
|
#define Anum_pg_foreign_data_wrapper_fdwvalidator 4
|
||||||
#define Anum_pg_foreign_data_wrapper_fdwoptions 5
|
#define Anum_pg_foreign_data_wrapper_fdwacl 5
|
||||||
|
#define Anum_pg_foreign_data_wrapper_fdwoptions 6
|
||||||
|
|
||||||
#endif /* PG_FOREIGN_DATA_WRAPPER_H */
|
#endif /* PG_FOREIGN_DATA_WRAPPER_H */
|
||||||
|
@ -3913,6 +3913,10 @@ DATA(insert OID = 2777 ( anynonarray_in PGNSP PGUID 12 1 0 0 f f f t f i 1 0 27
|
|||||||
DESCR("I/O");
|
DESCR("I/O");
|
||||||
DATA(insert OID = 2778 ( anynonarray_out PGNSP PGUID 12 1 0 0 f f f t f i 1 0 2275 "2776" _null_ _null_ _null_ _null_ anynonarray_out _null_ _null_ _null_ ));
|
DATA(insert OID = 2778 ( anynonarray_out PGNSP PGUID 12 1 0 0 f f f t f i 1 0 2275 "2776" _null_ _null_ _null_ _null_ anynonarray_out _null_ _null_ _null_ ));
|
||||||
DESCR("I/O");
|
DESCR("I/O");
|
||||||
|
DATA(insert OID = 3116 ( fdw_handler_in PGNSP PGUID 12 1 0 0 f f f f f i 1 0 3115 "2275" _null_ _null_ _null_ _null_ fdw_handler_in _null_ _null_ _null_ ));
|
||||||
|
DESCR("I/O");
|
||||||
|
DATA(insert OID = 3117 ( fdw_handler_out PGNSP PGUID 12 1 0 0 f f f t f i 1 0 2275 "3115" _null_ _null_ _null_ _null_ fdw_handler_out _null_ _null_ _null_ ));
|
||||||
|
DESCR("I/O");
|
||||||
|
|
||||||
/* cryptographic */
|
/* cryptographic */
|
||||||
DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 1 0 0 f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ md5_text _null_ _null_ _null_ ));
|
DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 1 0 0 f f f t f i 1 0 25 "25" _null_ _null_ _null_ _null_ md5_text _null_ _null_ _null_ ));
|
||||||
|
@ -631,6 +631,8 @@ DATA(insert OID = 2776 ( anynonarray PGNSP PGUID 4 t p P f t \054 0 0 0 anynona
|
|||||||
#define ANYNONARRAYOID 2776
|
#define ANYNONARRAYOID 2776
|
||||||
DATA(insert OID = 3500 ( anyenum PGNSP PGUID 4 t p P f t \054 0 0 0 anyenum_in anyenum_out - - - - - i p f 0 -1 0 0 _null_ _null_ ));
|
DATA(insert OID = 3500 ( anyenum PGNSP PGUID 4 t p P f t \054 0 0 0 anyenum_in anyenum_out - - - - - i p f 0 -1 0 0 _null_ _null_ ));
|
||||||
#define ANYENUMOID 3500
|
#define ANYENUMOID 3500
|
||||||
|
DATA(insert OID = 3115 ( fdw_handler PGNSP PGUID 4 t p P f t \054 0 0 0 fdw_handler_in fdw_handler_out - - - - - i p f 0 -1 0 0 _null_ _null_ ));
|
||||||
|
#define FDW_HANDLEROID 3115
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -37,7 +37,8 @@ typedef struct ForeignDataWrapper
|
|||||||
Oid fdwid; /* FDW Oid */
|
Oid fdwid; /* FDW Oid */
|
||||||
Oid owner; /* FDW owner user Oid */
|
Oid owner; /* FDW owner user Oid */
|
||||||
char *fdwname; /* Name of the FDW */
|
char *fdwname; /* Name of the FDW */
|
||||||
Oid fdwvalidator;
|
Oid fdwhandler; /* Oid of handler function, or 0 */
|
||||||
|
Oid fdwvalidator; /* Oid of validator function, or 0 */
|
||||||
List *options; /* fdwoptions as DefElem list */
|
List *options; /* fdwoptions as DefElem list */
|
||||||
} ForeignDataWrapper;
|
} ForeignDataWrapper;
|
||||||
|
|
||||||
|
@ -1574,7 +1574,7 @@ typedef struct CreateFdwStmt
|
|||||||
{
|
{
|
||||||
NodeTag type;
|
NodeTag type;
|
||||||
char *fdwname; /* foreign-data wrapper name */
|
char *fdwname; /* foreign-data wrapper name */
|
||||||
List *validator; /* optional validator function (qual. name) */
|
List *func_options; /* HANDLER/VALIDATOR options */
|
||||||
List *options; /* generic options to FDW */
|
List *options; /* generic options to FDW */
|
||||||
} CreateFdwStmt;
|
} CreateFdwStmt;
|
||||||
|
|
||||||
@ -1582,8 +1582,7 @@ typedef struct AlterFdwStmt
|
|||||||
{
|
{
|
||||||
NodeTag type;
|
NodeTag type;
|
||||||
char *fdwname; /* foreign-data wrapper name */
|
char *fdwname; /* foreign-data wrapper name */
|
||||||
List *validator; /* optional validator function (qual. name) */
|
List *func_options; /* HANDLER/VALIDATOR options */
|
||||||
bool change_validator;
|
|
||||||
List *options; /* generic options to FDW */
|
List *options; /* generic options to FDW */
|
||||||
} AlterFdwStmt;
|
} AlterFdwStmt;
|
||||||
|
|
||||||
|
@ -508,6 +508,8 @@ extern Datum trigger_in(PG_FUNCTION_ARGS);
|
|||||||
extern Datum trigger_out(PG_FUNCTION_ARGS);
|
extern Datum trigger_out(PG_FUNCTION_ARGS);
|
||||||
extern Datum language_handler_in(PG_FUNCTION_ARGS);
|
extern Datum language_handler_in(PG_FUNCTION_ARGS);
|
||||||
extern Datum language_handler_out(PG_FUNCTION_ARGS);
|
extern Datum language_handler_out(PG_FUNCTION_ARGS);
|
||||||
|
extern Datum fdw_handler_in(PG_FUNCTION_ARGS);
|
||||||
|
extern Datum fdw_handler_out(PG_FUNCTION_ARGS);
|
||||||
extern Datum internal_in(PG_FUNCTION_ARGS);
|
extern Datum internal_in(PG_FUNCTION_ARGS);
|
||||||
extern Datum internal_out(PG_FUNCTION_ARGS);
|
extern Datum internal_out(PG_FUNCTION_ARGS);
|
||||||
extern Datum opaque_in(PG_FUNCTION_ARGS);
|
extern Datum opaque_in(PG_FUNCTION_ARGS);
|
||||||
|
@ -16,11 +16,11 @@ CREATE ROLE unprivileged_role;
|
|||||||
CREATE FOREIGN DATA WRAPPER dummy;
|
CREATE FOREIGN DATA WRAPPER dummy;
|
||||||
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
|
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
|
||||||
-- At this point we should have 2 built-in wrappers and no servers.
|
-- At this point we should have 2 built-in wrappers and no servers.
|
||||||
SELECT fdwname, fdwvalidator::regproc, fdwoptions FROM pg_foreign_data_wrapper ORDER BY 1, 2, 3;
|
SELECT fdwname, fdwhandler::regproc, fdwvalidator::regproc, fdwoptions FROM pg_foreign_data_wrapper ORDER BY 1, 2, 3;
|
||||||
fdwname | fdwvalidator | fdwoptions
|
fdwname | fdwhandler | fdwvalidator | fdwoptions
|
||||||
------------+--------------------------+------------
|
------------+------------+--------------------------+------------
|
||||||
dummy | - |
|
dummy | - | - |
|
||||||
postgresql | postgresql_fdw_validator |
|
postgresql | - | postgresql_fdw_validator |
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
SELECT srvname, srvoptions FROM pg_foreign_server;
|
SELECT srvname, srvoptions FROM pg_foreign_server;
|
||||||
@ -39,11 +39,11 @@ ERROR: function bar(text[], oid) does not exist
|
|||||||
CREATE FOREIGN DATA WRAPPER foo;
|
CREATE FOREIGN DATA WRAPPER foo;
|
||||||
\dew
|
\dew
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator
|
Name | Owner | Handler | Validator
|
||||||
------------+-------------------+--------------------------
|
------------+-------------------+---------+--------------------------
|
||||||
dummy | foreign_data_user | -
|
dummy | foreign_data_user | - | -
|
||||||
foo | foreign_data_user | -
|
foo | foreign_data_user | - | -
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator
|
postgresql | foreign_data_user | - | postgresql_fdw_validator
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
CREATE FOREIGN DATA WRAPPER foo; -- duplicate
|
CREATE FOREIGN DATA WRAPPER foo; -- duplicate
|
||||||
@ -52,11 +52,11 @@ DROP FOREIGN DATA WRAPPER foo;
|
|||||||
CREATE FOREIGN DATA WRAPPER foo OPTIONS (testing '1');
|
CREATE FOREIGN DATA WRAPPER foo OPTIONS (testing '1');
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+-------------
|
------------+-------------------+---------+--------------------------+-------------------+-------------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | | {testing=1}
|
foo | foreign_data_user | - | - | | {testing=1}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
DROP FOREIGN DATA WRAPPER foo;
|
DROP FOREIGN DATA WRAPPER foo;
|
||||||
@ -65,11 +65,11 @@ ERROR: option "testing" provided more than once
|
|||||||
CREATE FOREIGN DATA WRAPPER foo OPTIONS (testing '1', another '2');
|
CREATE FOREIGN DATA WRAPPER foo OPTIONS (testing '1', another '2');
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+-----------------------
|
------------+-------------------+---------+--------------------------+-------------------+-----------------------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | | {testing=1,another=2}
|
foo | foreign_data_user | - | - | | {testing=1,another=2}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
DROP FOREIGN DATA WRAPPER foo;
|
DROP FOREIGN DATA WRAPPER foo;
|
||||||
@ -81,11 +81,11 @@ RESET ROLE;
|
|||||||
CREATE FOREIGN DATA WRAPPER foo VALIDATOR postgresql_fdw_validator;
|
CREATE FOREIGN DATA WRAPPER foo VALIDATOR postgresql_fdw_validator;
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+---------
|
------------+-------------------+---------+--------------------------+-------------------+---------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | postgresql_fdw_validator | |
|
foo | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- ALTER FOREIGN DATA WRAPPER
|
-- ALTER FOREIGN DATA WRAPPER
|
||||||
@ -98,11 +98,11 @@ ERROR: function bar(text[], oid) does not exist
|
|||||||
ALTER FOREIGN DATA WRAPPER foo NO VALIDATOR;
|
ALTER FOREIGN DATA WRAPPER foo NO VALIDATOR;
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+---------
|
------------+-------------------+---------+--------------------------+-------------------+---------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | |
|
foo | foreign_data_user | - | - | |
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '1', b '2');
|
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '1', b '2');
|
||||||
@ -113,21 +113,21 @@ ERROR: option "c" not found
|
|||||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD x '1', DROP x);
|
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD x '1', DROP x);
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+-----------
|
------------+-------------------+---------+--------------------------+-------------------+-----------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | | {a=1,b=2}
|
foo | foreign_data_user | - | - | | {a=1,b=2}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (DROP a, SET b '3', ADD c '4');
|
ALTER FOREIGN DATA WRAPPER foo OPTIONS (DROP a, SET b '3', ADD c '4');
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+-----------
|
------------+-------------------+---------+--------------------------+-------------------+-----------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | | {b=3,c=4}
|
foo | foreign_data_user | - | - | | {b=3,c=4}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '2');
|
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '2');
|
||||||
@ -135,11 +135,11 @@ ALTER FOREIGN DATA WRAPPER foo OPTIONS (b '4'); -- ERROR
|
|||||||
ERROR: option "b" provided more than once
|
ERROR: option "b" provided more than once
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+---------------
|
------------+-------------------+---------+--------------------------+-------------------+---------------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | | {b=3,c=4,a=2}
|
foo | foreign_data_user | - | - | | {b=3,c=4,a=2}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
SET ROLE regress_test_role;
|
SET ROLE regress_test_role;
|
||||||
@ -150,11 +150,11 @@ SET ROLE regress_test_role_super;
|
|||||||
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD d '5');
|
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD d '5');
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+-------------------
|
------------+-------------------+---------+--------------------------+-------------------+-------------------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | | {b=3,c=4,a=2,d=5}
|
foo | foreign_data_user | - | - | | {b=3,c=4,a=2,d=5}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
ALTER FOREIGN DATA WRAPPER foo OWNER TO regress_test_role; -- ERROR
|
ALTER FOREIGN DATA WRAPPER foo OWNER TO regress_test_role; -- ERROR
|
||||||
@ -169,11 +169,11 @@ HINT: Must be superuser to alter a foreign-data wrapper.
|
|||||||
RESET ROLE;
|
RESET ROLE;
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------------+--------------------------+-------------------+-------------------
|
------------+-------------------------+---------+--------------------------+-------------------+-------------------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | regress_test_role_super | - | | {b=3,c=4,a=2,d=5}
|
foo | regress_test_role_super | - | - | | {b=3,c=4,a=2,d=5}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- DROP FOREIGN DATA WRAPPER
|
-- DROP FOREIGN DATA WRAPPER
|
||||||
@ -183,11 +183,11 @@ DROP FOREIGN DATA WRAPPER IF EXISTS nonexistent;
|
|||||||
NOTICE: foreign-data wrapper "nonexistent" does not exist, skipping
|
NOTICE: foreign-data wrapper "nonexistent" does not exist, skipping
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------------+--------------------------+-------------------+-------------------
|
------------+-------------------------+---------+--------------------------+-------------------+-------------------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | regress_test_role_super | - | | {b=3,c=4,a=2,d=5}
|
foo | regress_test_role_super | - | - | | {b=3,c=4,a=2,d=5}
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
DROP ROLE regress_test_role_super; -- ERROR
|
DROP ROLE regress_test_role_super; -- ERROR
|
||||||
@ -203,10 +203,10 @@ DROP FOREIGN DATA WRAPPER foo;
|
|||||||
DROP ROLE regress_test_role_super;
|
DROP ROLE regress_test_role_super;
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+---------
|
------------+-------------------+---------+--------------------------+-------------------+---------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
CREATE FOREIGN DATA WRAPPER foo;
|
CREATE FOREIGN DATA WRAPPER foo;
|
||||||
@ -214,11 +214,11 @@ CREATE SERVER s1 FOREIGN DATA WRAPPER foo;
|
|||||||
CREATE USER MAPPING FOR current_user SERVER s1;
|
CREATE USER MAPPING FOR current_user SERVER s1;
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+---------
|
------------+-------------------+---------+--------------------------+-------------------+---------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
foo | foreign_data_user | - | |
|
foo | foreign_data_user | - | - | |
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
\des+
|
\des+
|
||||||
@ -251,10 +251,10 @@ DETAIL: drop cascades to server s1
|
|||||||
drop cascades to user mapping for foreign_data_user
|
drop cascades to user mapping for foreign_data_user
|
||||||
\dew+
|
\dew+
|
||||||
List of foreign-data wrappers
|
List of foreign-data wrappers
|
||||||
Name | Owner | Validator | Access privileges | Options
|
Name | Owner | Handler | Validator | Access privileges | Options
|
||||||
------------+-------------------+--------------------------+-------------------+---------
|
------------+-------------------+---------+--------------------------+-------------------+---------
|
||||||
dummy | foreign_data_user | - | |
|
dummy | foreign_data_user | - | - | |
|
||||||
postgresql | foreign_data_user | postgresql_fdw_validator | |
|
postgresql | foreign_data_user | - | postgresql_fdw_validator | |
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
\des+
|
\des+
|
||||||
@ -669,6 +669,10 @@ Has OIDs: no
|
|||||||
|
|
||||||
CREATE INDEX id_ft1_c2 ON ft1 (c2); -- ERROR
|
CREATE INDEX id_ft1_c2 ON ft1 (c2); -- ERROR
|
||||||
ERROR: "ft1" is not a table
|
ERROR: "ft1" is not a table
|
||||||
|
SELECT * FROM ft1; -- ERROR
|
||||||
|
ERROR: foreign table scans are not yet supported
|
||||||
|
EXPLAIN SELECT * FROM ft1; -- ERROR
|
||||||
|
ERROR: foreign table scans are not yet supported
|
||||||
-- ALTER FOREIGN TABLE
|
-- ALTER FOREIGN TABLE
|
||||||
COMMENT ON FOREIGN TABLE ft1 IS 'foreign table';
|
COMMENT ON FOREIGN TABLE ft1 IS 'foreign table';
|
||||||
COMMENT ON FOREIGN TABLE ft1 IS NULL;
|
COMMENT ON FOREIGN TABLE ft1 IS NULL;
|
||||||
@ -1105,9 +1109,9 @@ NOTICE: drop cascades to server sc
|
|||||||
\c
|
\c
|
||||||
DROP ROLE foreign_data_user;
|
DROP ROLE foreign_data_user;
|
||||||
-- At this point we should have no wrappers, no servers, and no mappings.
|
-- At this point we should have no wrappers, no servers, and no mappings.
|
||||||
SELECT fdwname, fdwvalidator, fdwoptions FROM pg_foreign_data_wrapper;
|
SELECT fdwname, fdwhandler, fdwvalidator, fdwoptions FROM pg_foreign_data_wrapper;
|
||||||
fdwname | fdwvalidator | fdwoptions
|
fdwname | fdwhandler | fdwvalidator | fdwoptions
|
||||||
---------+--------------+------------
|
---------+------------+--------------+------------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
SELECT srvname, srvoptions FROM pg_foreign_server;
|
SELECT srvname, srvoptions FROM pg_foreign_server;
|
||||||
|
@ -24,7 +24,7 @@ CREATE FOREIGN DATA WRAPPER dummy;
|
|||||||
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
|
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
|
||||||
|
|
||||||
-- At this point we should have 2 built-in wrappers and no servers.
|
-- At this point we should have 2 built-in wrappers and no servers.
|
||||||
SELECT fdwname, fdwvalidator::regproc, fdwoptions FROM pg_foreign_data_wrapper ORDER BY 1, 2, 3;
|
SELECT fdwname, fdwhandler::regproc, fdwvalidator::regproc, fdwoptions FROM pg_foreign_data_wrapper ORDER BY 1, 2, 3;
|
||||||
SELECT srvname, srvoptions FROM pg_foreign_server;
|
SELECT srvname, srvoptions FROM pg_foreign_server;
|
||||||
SELECT * FROM pg_user_mapping;
|
SELECT * FROM pg_user_mapping;
|
||||||
|
|
||||||
@ -271,6 +271,8 @@ COMMENT ON COLUMN ft1.c1 IS 'ft1.c1';
|
|||||||
\d+ ft1
|
\d+ ft1
|
||||||
\det+
|
\det+
|
||||||
CREATE INDEX id_ft1_c2 ON ft1 (c2); -- ERROR
|
CREATE INDEX id_ft1_c2 ON ft1 (c2); -- ERROR
|
||||||
|
SELECT * FROM ft1; -- ERROR
|
||||||
|
EXPLAIN SELECT * FROM ft1; -- ERROR
|
||||||
|
|
||||||
-- ALTER FOREIGN TABLE
|
-- ALTER FOREIGN TABLE
|
||||||
COMMENT ON FOREIGN TABLE ft1 IS 'foreign table';
|
COMMENT ON FOREIGN TABLE ft1 IS 'foreign table';
|
||||||
@ -453,6 +455,6 @@ DROP FOREIGN DATA WRAPPER dummy CASCADE;
|
|||||||
DROP ROLE foreign_data_user;
|
DROP ROLE foreign_data_user;
|
||||||
|
|
||||||
-- At this point we should have no wrappers, no servers, and no mappings.
|
-- At this point we should have no wrappers, no servers, and no mappings.
|
||||||
SELECT fdwname, fdwvalidator, fdwoptions FROM pg_foreign_data_wrapper;
|
SELECT fdwname, fdwhandler, fdwvalidator, fdwoptions FROM pg_foreign_data_wrapper;
|
||||||
SELECT srvname, srvoptions FROM pg_foreign_server;
|
SELECT srvname, srvoptions FROM pg_foreign_server;
|
||||||
SELECT * FROM pg_user_mapping;
|
SELECT * FROM pg_user_mapping;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user