</entry>
</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 foreign-data wrapper routines.
+ Zero if no handler is provided.
+ </entry>
+ </row>
+
<row>
<entry><structfield>fdwacl</structfield></entry>
<entry><type>aclitem[]</type></entry>
<synopsis>
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
[ VALIDATOR <replaceable class="parameter">valfunction</replaceable> | NO VALIDATOR ]
+ [ HANDLER <replaceable class="parameter">handler</replaceable> | NO HANDLER ]
[ 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>
</synopsis>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><literal>HANDLER <replaceable class="parameter">handler</replaceable></literal></term>
+ <listitem>
+ <para>
+ Specifies a new foreign-data wrapper handler function.
+ </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 which uses a foreign-data wrapper with no
+ handler can't be used in a SELECT statement.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term>
<listitem>
<para>
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
9075-9 (SQL/MED). The standard does not specify the <literal>
- VALIDATOR</literal> and <literal>OWNER TO</> variants of the
- command.
+ VALIDATOR</literal>, <literal>HANDLER</> and <literal>OWNER TO</>
+ variants of the command.
</para>
</refsect1>
<synopsis>
CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
[ VALIDATOR <replaceable class="parameter">valfunction</replaceable> | NO VALIDATOR ]
+ [ HANDLER <replaceable class="parameter">handler</replaceable> | NO HANDLER ]
[ OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] ) ]
</synopsis>
</refsynopsisdiv>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><literal>HANDLER <replaceable class="parameter">handler</replaceable></literal></term>
+ <listitem>
+ <para>
+ <replaceable class="parameter">handler</replaceable> is the
+ name of a previously registered function that will be called to
+ retrieve a set of functions for foreign tables.
+ The handler function must take no arguments.
+ The return type must be <type>fdw_handler</type>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><literal>OPTIONS ( <replaceable class="PARAMETER">option</replaceable> '<replaceable class="PARAMETER">value</replaceable>' [, ... ] )</literal></term>
<listitem>
<para>
<command>CREATE FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
- 9075-9 (SQL/MED), with the exception that
- the <literal>VALIDATOR</literal> clause is an extension and the
+ 9075-9 (SQL/MED), with the exception that the <literal>VALIDATOR</literal>
+ and <literal>HANDLER</literal> clauses are extensions and the
clauses <literal>LIBRARY</literal> and <literal>LANGUAGE</literal>
are not yet implemented in PostgreSQL.
</para>
* Convert a validator function name passed from the parser to an Oid.
*/
static Oid
-lookup_fdw_validator_func(List *validator)
+lookup_fdw_validator_func(DefElem *validator)
{
Oid funcargtypes[2];
+ if (validator == NULL || validator->arg == NULL)
+ return InvalidOid;
+
funcargtypes[0] = TEXTARRAYOID;
funcargtypes[1] = OIDOID;
- return LookupFuncName(validator, 2, funcargtypes, false);
+ return LookupFuncName((List *) validator->arg, 2, funcargtypes, false);
/* return value is ignored, so we don't check the type */
}
+static Oid
+lookup_fdw_handler_func(DefElem *handler)
+{
+ Oid handlerOid;
+
+ if (handler == NULL || handler->arg == NULL)
+ return InvalidOid;
+
+ /* check that handler have correct return type */
+ handlerOid = LookupFuncName((List *) handler->arg, 0, NULL, false);
+ 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;
+}
+
+static void
+parse_func_options(List *func_options, DefElem **validator, DefElem **handler)
+{
+ ListCell *cell;
+
+ *validator = NULL;
+ *handler = NULL;
+ foreach (cell, func_options)
+ {
+ DefElem *def = lfirst(cell);
+
+ if (pg_strcasecmp(def->defname, "validator") == 0)
+ {
+ if (*validator)
+ ereport(ERROR, (errmsg("duplicated VALIDATOR")));
+ *validator = def;
+ }
+ else if (pg_strcasecmp(def->defname, "handler") == 0)
+ {
+ if (*handler)
+ ereport(ERROR, (errmsg("duplicated HANDLER")));
+ *handler = def;
+ }
+ else
+ {
+ ereport(ERROR, (errmsg("invalid option")));
+ }
+ }
+}
/*
* Create a foreign-data wrapper
bool nulls[Natts_pg_foreign_data_wrapper];
HeapTuple tuple;
Oid fdwId;
+ DefElem *defvalidator;
+ DefElem *defhandler;
Oid fdwvalidator;
+ Oid fdwhandler;
Datum fdwoptions;
Oid ownerId;
DirectFunctionCall1(namein, CStringGetDatum(stmt->fdwname));
values[Anum_pg_foreign_data_wrapper_fdwowner - 1] = ObjectIdGetDatum(ownerId);
- if (stmt->validator)
- fdwvalidator = lookup_fdw_validator_func(stmt->validator);
- else
- fdwvalidator = InvalidOid;
+ /* determine which validator to be used (or not used at all) */
+ parse_func_options(stmt->func_options, &defvalidator, &defhandler);
+ fdwvalidator = lookup_fdw_validator_func(defvalidator);
+ fdwhandler = lookup_fdw_handler_func(defhandler);
values[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = fdwvalidator;
+ values[Anum_pg_foreign_data_wrapper_fdwhandler - 1] = fdwhandler;
nulls[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
+ if (fdwhandler != InvalidOid)
+ {
+ ObjectAddress myself;
+ ObjectAddress referenced;
+
+ myself.classId = ForeignDataWrapperRelationId;
+ myself.objectId = fdwId;
+ myself.objectSubId = 0;
+
+ referenced.classId = ProcedureRelationId;
+ referenced.objectId = fdwhandler;
+ referenced.objectSubId = 0;
+ recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
+ }
+
recordDependencyOnOwner(ForeignDataWrapperRelationId, fdwId, ownerId);
/* Post creation hook for new foreign data wrapper */
Oid fdwId;
bool isnull;
Datum datum;
+ DefElem *defvalidator;
+ DefElem *defhandler;
Oid fdwvalidator;
+ Oid fdwhandler;
/* Must be super user */
if (!superuser())
memset(repl_null, false, sizeof(repl_null));
memset(repl_repl, false, sizeof(repl_repl));
- if (stmt->change_validator)
+ parse_func_options(stmt->func_options, &defvalidator, &defhandler);
+
+ if (defvalidator)
{
- fdwvalidator = stmt->validator ? lookup_fdw_validator_func(stmt->validator) : InvalidOid;
+ fdwvalidator = lookup_fdw_validator_func(defvalidator);
repl_val[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = ObjectIdGetDatum(fdwvalidator);
repl_repl[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] = true;
* It could be that the options for the FDW, SERVER and USER MAPPING
* are no longer valid with the new validator. Warn about this.
*/
- if (stmt->validator)
+ if (defvalidator->arg)
ereport(WARNING,
(errmsg("changing the foreign-data wrapper validator can cause "
"the options for dependent objects to become invalid")));
fdwvalidator = DatumGetObjectId(datum);
}
+ if (defhandler)
+ {
+ fdwhandler = lookup_fdw_handler_func(defhandler);
+ 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.
+ */
+ if (defhandler->arg)
+ ereport(WARNING,
+ (errmsg("changing the foreign-data wrapper handler would change "
+ "the behavior of accessing foreign tables")));
+ }
+ else
+ {
+ /*
+ * Validator is not changed, but we need it for validating options.
+ */
+ datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID,
+ tp,
+ Anum_pg_foreign_data_wrapper_fdwhandler,
+ &isnull);
+ Assert(!isnull);
+ fdwhandler = DatumGetObjectId(datum);
+ }
+
/*
* Options specified, validate and update.
*/
fdw->owner = fdwform->fdwowner;
fdw->fdwname = pstrdup(NameStr(fdwform->fdwname));
fdw->fdwvalidator = fdwform->fdwvalidator;
+ fdw->fdwhandler = fdwform->fdwhandler;
/* Extract the options */
datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID,
CreateFdwStmt *newnode = makeNode(CreateFdwStmt);
COPY_STRING_FIELD(fdwname);
- COPY_NODE_FIELD(validator);
+ COPY_NODE_FIELD(func_options);
COPY_NODE_FIELD(options);
return newnode;
AlterFdwStmt *newnode = makeNode(AlterFdwStmt);
COPY_STRING_FIELD(fdwname);
- COPY_NODE_FIELD(validator);
- COPY_SCALAR_FIELD(change_validator);
+ COPY_NODE_FIELD(func_options);
COPY_NODE_FIELD(options);
return newnode;
_equalCreateFdwStmt(CreateFdwStmt *a, CreateFdwStmt *b)
{
COMPARE_STRING_FIELD(fdwname);
- COMPARE_NODE_FIELD(validator);
+ COMPARE_NODE_FIELD(func_options);
COMPARE_NODE_FIELD(options);
return true;
_equalAlterFdwStmt(AlterFdwStmt *a, AlterFdwStmt *b)
{
COMPARE_STRING_FIELD(fdwname);
- COMPARE_NODE_FIELD(validator);
- COMPARE_SCALAR_FIELD(change_validator);
+ COMPARE_NODE_FIELD(func_options);
COMPARE_NODE_FIELD(options);
return true;
create_generic_options alter_generic_options
relation_expr_list dostmt_opt_list
+%type <list> opt_func_options func_options
+%type <defelt> fdw_option
+
%type <range> OptTempTableName
%type <into> into_clause create_as_target
*
*****************************************************************************/
-CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_validator create_generic_options
+CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_func_options create_generic_options
{
CreateFdwStmt *n = makeNode(CreateFdwStmt);
n->fdwname = $5;
- n->validator = $6;
+ n->func_options = $6;
n->options = $7;
$$ = (Node *) n;
}
;
+fdw_option:
+ VALIDATOR handler_name { $$ = makeDefElem("validator", (Node *)$2); }
+ | NO VALIDATOR { $$ = makeDefElem("validator", NULL); }
+ | HANDLER handler_name { $$ = makeDefElem("handler", (Node *)$2); }
+ | NO HANDLER { $$ = makeDefElem("handler", NULL); }
+ ;
+
+func_options:
+ fdw_option { $$ = list_make1($1); }
+ | func_options fdw_option { $$ = lappend($1, $2); }
+ ;
+
+opt_func_options:
+ func_options { $$ = $1; }
+ | /*EMPTY*/ { $$ = NIL; }
+ ;
+
/*****************************************************************************
*
* QUERY :
*
****************************************************************************/
-AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name validator_clause alter_generic_options
+AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_func_options alter_generic_options
{
AlterFdwStmt *n = makeNode(AlterFdwStmt);
n->fdwname = $5;
- n->validator = $6;
- n->change_validator = true;
+ n->func_options = $6;
n->options = $7;
$$ = (Node *) n;
}
- | ALTER FOREIGN DATA_P WRAPPER name validator_clause
+ | ALTER FOREIGN DATA_P WRAPPER name func_options
{
AlterFdwStmt *n = makeNode(AlterFdwStmt);
n->fdwname = $5;
- n->validator = $6;
- n->change_validator = true;
- $$ = (Node *) n;
- }
- | ALTER FOREIGN DATA_P WRAPPER name alter_generic_options
- {
- AlterFdwStmt *n = makeNode(AlterFdwStmt);
- n->fdwname = $5;
- n->options = $6;
+ n->func_options = $6;
+ n->options = NIL;
$$ = (Node *) n;
}
;
{
return textsend(fcinfo);
}
+
+/*
+ * 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 */
+}
int i_fdwname;
int i_rolname;
int i_fdwvalidator;
+ int i_fdwhandler;
int i_fdwacl;
int i_fdwoptions;
/* Make sure we are in proper schema */
selectSourceSchema("pg_catalog");
- appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
- "(%s fdwowner) AS rolname, 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);
+ if (g_fout->remoteVersion >= 90100)
+ {
+ appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
+ "(%s fdwowner) AS rolname, fdwvalidator::pg_catalog.regproc, "
+ "fdwhandler::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);
+ }
+ else
+ {
+ appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
+ "(%s fdwowner) AS rolname, 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);
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
i_fdwname = PQfnumber(res, "fdwname");
i_rolname = PQfnumber(res, "rolname");
i_fdwvalidator = PQfnumber(res, "fdwvalidator");
+ if (g_fout->remoteVersion >= 90100)
+ i_fdwhandler = PQfnumber(res, "fdwhandler");
i_fdwacl = PQfnumber(res, "fdwacl");
i_fdwoptions = PQfnumber(res, "fdwoptions");
fdwinfo[i].dobj.namespace = NULL;
fdwinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
fdwinfo[i].fdwvalidator = strdup(PQgetvalue(res, i, i_fdwvalidator));
+ if (g_fout->remoteVersion >= 90100)
+ fdwinfo[i].fdwhandler = strdup(PQgetvalue(res, i, i_fdwhandler));
+ else
+ fdwinfo[i].fdwhandler = NULL;
fdwinfo[i].fdwoptions = strdup(PQgetvalue(res, i, i_fdwoptions));
fdwinfo[i].fdwacl = strdup(PQgetvalue(res, i, i_fdwacl));
appendPQExpBuffer(q, " VALIDATOR %s",
fdwinfo->fdwvalidator);
+ if (g_fout->remoteVersion >= 90100 && fdwinfo->fdwhandler &&
+ strcmp(fdwinfo->fdwhandler, "-") != 0)
+ appendPQExpBuffer(q, " HANDLER %s",
+ fdwinfo->fdwhandler);
+
if (fdwinfo->fdwoptions && strlen(fdwinfo->fdwoptions) > 0)
appendPQExpBuffer(q, " OPTIONS (%s)", fdwinfo->fdwoptions);
DumpableObject dobj;
char *rolname;
char *fdwvalidator;
+ char *fdwhandler;
char *fdwoptions;
char *fdwacl;
} FdwInfo;
printfPQExpBuffer(&buf,
"SELECT fdwname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(fdwowner) AS \"%s\",\n"
+ " fdwhandler::pg_catalog.regproc AS \"%s\",\n"
" fdwvalidator::pg_catalog.regproc AS \"%s\"",
gettext_noop("Name"),
gettext_noop("Owner"),
+ gettext_noop("Handler"),
gettext_noop("Validator"));
if (verbose)
NameData fdwname; /* foreign-data wrapper name */
Oid fdwowner; /* FDW owner */
Oid fdwvalidator; /* optional validation function */
+ Oid fdwhandler; /* foreign-data routines function */
/* VARIABLE LENGTH FIELDS start here. */
* ----------------
*/
-#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_fdwowner 2
#define Anum_pg_foreign_data_wrapper_fdwvalidator 3
-#define Anum_pg_foreign_data_wrapper_fdwacl 4
-#define Anum_pg_foreign_data_wrapper_fdwoptions 5
+#define Anum_pg_foreign_data_wrapper_fdwhandler 4
+#define Anum_pg_foreign_data_wrapper_fdwacl 5
+#define Anum_pg_foreign_data_wrapper_fdwoptions 6
#endif /* PG_FOREIGN_DATA_WRAPPER_H */
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_ ));
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 */
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_ ));
#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 _null_ _null_ ));
#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 _null_ _null_ ));
+#define FDW_HANDLEROID 3115
/*
Oid owner; /* FDW owner user Oid */
char *fdwname; /* Name of the FDW */
Oid fdwvalidator;
+ Oid fdwhandler;
List *options; /* fdwoptions as DefElem list */
} ForeignDataWrapper;
{
NodeTag type;
char *fdwname; /* foreign-data wrapper name */
- List *validator; /* optional validator function (qual. name) */
+ List *func_options; /* VALIDATOR/HANDLER conbination */
List *options; /* generic options to FDW */
} CreateFdwStmt;
{
NodeTag type;
char *fdwname; /* foreign-data wrapper name */
- List *validator; /* optional validator function (qual. name) */
- bool change_validator;
+ List *func_options; /* VALIDATOR/HANDLER conbination */
List *options; /* generic options to FDW */
} AlterFdwStmt;
extern Datum pg_node_tree_out(PG_FUNCTION_ARGS);
extern Datum pg_node_tree_recv(PG_FUNCTION_ARGS);
extern Datum pg_node_tree_send(PG_FUNCTION_ARGS);
+extern Datum fdw_handler_in(PG_FUNCTION_ARGS);
+extern Datum fdw_handler_out(PG_FUNCTION_ARGS);
/* regexp.c */
extern Datum nameregexeq(PG_FUNCTION_ARGS);
CREATE FOREIGN DATA WRAPPER dummy;
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
-- 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;
- fdwname | fdwvalidator | fdwoptions
-------------+--------------------------+------------
- dummy | - |
- postgresql | postgresql_fdw_validator |
+SELECT fdwname, fdwvalidator::regproc, fdwhandler::regproc, fdwoptions FROM pg_foreign_data_wrapper ORDER BY 1, 2, 3;
+ fdwname | fdwvalidator | fdwhandler | fdwoptions
+------------+--------------------------+------------+------------
+ dummy | - | - |
+ postgresql | postgresql_fdw_validator | - |
(2 rows)
SELECT srvname, srvoptions FROM pg_foreign_server;
ERROR: function bar(text[], oid) does not exist
CREATE FOREIGN DATA WRAPPER foo;
\dew
- List of foreign-data wrappers
- Name | Owner | Validator
-------------+-------------------+--------------------------
- dummy | foreign_data_user | -
- foo | foreign_data_user | -
- postgresql | foreign_data_user | postgresql_fdw_validator
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator
+------------+-------------------+---------+--------------------------
+ dummy | foreign_data_user | - | -
+ foo | foreign_data_user | - | -
+ postgresql | foreign_data_user | - | postgresql_fdw_validator
(3 rows)
CREATE FOREIGN DATA WRAPPER foo; -- duplicate
DROP FOREIGN DATA WRAPPER foo;
CREATE FOREIGN DATA WRAPPER foo OPTIONS (testing '1');
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+-------------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | | {testing=1}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+-------------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | | {testing=1}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
DROP FOREIGN DATA WRAPPER foo;
ERROR: option "testing" provided more than once
CREATE FOREIGN DATA WRAPPER foo OPTIONS (testing '1', another '2');
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+-----------------------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | | {testing=1,another=2}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+-----------------------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | | {testing=1,another=2}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
DROP FOREIGN DATA WRAPPER foo;
RESET ROLE;
CREATE FOREIGN DATA WRAPPER foo VALIDATOR postgresql_fdw_validator;
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+---------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | postgresql_fdw_validator | |
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+---------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | postgresql_fdw_validator | |
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
-- ALTER FOREIGN DATA WRAPPER
ERROR: function bar(text[], oid) does not exist
ALTER FOREIGN DATA WRAPPER foo NO VALIDATOR;
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+---------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | |
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+---------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | |
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '1', b '2');
ERROR: option "c" not found
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD x '1', DROP x);
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+-----------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | | {a=1,b=2}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+-----------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | | {a=1,b=2}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
ALTER FOREIGN DATA WRAPPER foo OPTIONS (DROP a, SET b '3', ADD c '4');
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+-----------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | | {b=3,c=4}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+-----------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | | {b=3,c=4}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
ALTER FOREIGN DATA WRAPPER foo OPTIONS (a '2');
ALTER FOREIGN DATA WRAPPER foo OPTIONS (b '4'); -- ERROR
ERROR: option "b" provided more than once
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+---------------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | | {b=3,c=4,a=2}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+---------------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | | {b=3,c=4,a=2}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
SET ROLE regress_test_role;
SET ROLE regress_test_role_super;
ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD d '5');
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+-------------------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | | {b=3,c=4,a=2,d=5}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+-------------------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | | {b=3,c=4,a=2,d=5}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
ALTER FOREIGN DATA WRAPPER foo OWNER TO regress_test_role; -- ERROR
HINT: Must be superuser to alter a foreign-data wrapper.
RESET ROLE;
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------------+--------------------------+-------------------+-------------------
- dummy | foreign_data_user | - | |
- foo | regress_test_role_super | - | | {b=3,c=4,a=2,d=5}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------------+---------+--------------------------+-------------------+-------------------
+ dummy | foreign_data_user | - | - | |
+ foo | regress_test_role_super | - | - | | {b=3,c=4,a=2,d=5}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
-- DROP FOREIGN DATA WRAPPER
DROP FOREIGN DATA WRAPPER IF EXISTS nonexistent;
NOTICE: foreign-data wrapper "nonexistent" does not exist, skipping
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------------+--------------------------+-------------------+-------------------
- dummy | foreign_data_user | - | |
- foo | regress_test_role_super | - | | {b=3,c=4,a=2,d=5}
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------------+---------+--------------------------+-------------------+-------------------
+ dummy | foreign_data_user | - | - | |
+ foo | regress_test_role_super | - | - | | {b=3,c=4,a=2,d=5}
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
DROP ROLE regress_test_role_super; -- ERROR
DROP FOREIGN DATA WRAPPER foo;
DROP ROLE regress_test_role_super;
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+---------
- dummy | foreign_data_user | - | |
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+---------
+ dummy | foreign_data_user | - | - | |
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(2 rows)
CREATE FOREIGN DATA WRAPPER foo;
CREATE SERVER s1 FOREIGN DATA WRAPPER foo;
CREATE USER MAPPING FOR current_user SERVER s1;
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+---------
- dummy | foreign_data_user | - | |
- foo | foreign_data_user | - | |
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+---------
+ dummy | foreign_data_user | - | - | |
+ foo | foreign_data_user | - | - | |
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(3 rows)
\des+
DETAIL: drop cascades to server s1
drop cascades to user mapping for foreign_data_user
\dew+
- List of foreign-data wrappers
- Name | Owner | Validator | Access privileges | Options
-------------+-------------------+--------------------------+-------------------+---------
- dummy | foreign_data_user | - | |
- postgresql | foreign_data_user | postgresql_fdw_validator | |
+ List of foreign-data wrappers
+ Name | Owner | Handler | Validator | Access privileges | Options
+------------+-------------------+---------+--------------------------+-------------------+---------
+ dummy | foreign_data_user | - | - | |
+ postgresql | foreign_data_user | - | postgresql_fdw_validator | |
(2 rows)
\des+
\c
DROP ROLE foreign_data_user;
-- At this point we should have no wrappers, no servers, and no mappings.
-SELECT fdwname, fdwvalidator, fdwoptions FROM pg_foreign_data_wrapper;
- fdwname | fdwvalidator | fdwoptions
----------+--------------+------------
+SELECT fdwname, fdwvalidator, fdwhandler, fdwoptions FROM pg_foreign_data_wrapper;
+ fdwname | fdwvalidator | fdwhandler | fdwoptions
+---------+--------------+------------+------------
(0 rows)
SELECT srvname, srvoptions FROM pg_foreign_server;
CREATE FOREIGN DATA WRAPPER postgresql VALIDATOR postgresql_fdw_validator;
-- 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, fdwvalidator::regproc, fdwhandler::regproc, fdwoptions FROM pg_foreign_data_wrapper ORDER BY 1, 2, 3;
SELECT srvname, srvoptions FROM pg_foreign_server;
SELECT * FROM pg_user_mapping;
DROP ROLE foreign_data_user;
-- At this point we should have no wrappers, no servers, and no mappings.
-SELECT fdwname, fdwvalidator, fdwoptions FROM pg_foreign_data_wrapper;
+SELECT fdwname, fdwvalidator, fdwhandler, fdwoptions FROM pg_foreign_data_wrapper;
SELECT srvname, srvoptions FROM pg_foreign_server;
SELECT * FROM pg_user_mapping;