128 foreach(cell, resultOptions)
147 (
errcode(ERRCODE_UNDEFINED_OBJECT),
148 errmsg(
"option \"%s\" not found",
156 (
errcode(ERRCODE_UNDEFINED_OBJECT),
157 errmsg(
"option \"%s\" not found",
167 errmsg(
"option \"%s\" provided more than once",
169 resultOptions =
lappend(resultOptions, od);
173 elog(
ERROR,
"unrecognized action %d on option \"%s\"",
183 Datum valarg = result;
208 Datum repl_val[Natts_pg_foreign_data_wrapper];
209 bool repl_null[Natts_pg_foreign_data_wrapper];
210 bool repl_repl[Natts_pg_foreign_data_wrapper];
220 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
221 errmsg(
"permission denied to change owner of foreign-data wrapper \"%s\"",
223 errhint(
"Must be superuser to change owner of a foreign-data wrapper.")));
228 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
229 errmsg(
"permission denied to change owner of foreign-data wrapper \"%s\"",
231 errhint(
"The owner of a foreign-data wrapper must be a superuser.")));
233 if (form->fdwowner != newOwnerId)
235 memset(repl_null,
false,
sizeof(repl_null));
236 memset(repl_repl,
false,
sizeof(repl_repl));
238 repl_repl[Anum_pg_foreign_data_wrapper_fdwowner - 1] =
true;
239 repl_val[Anum_pg_foreign_data_wrapper_fdwowner - 1] =
ObjectIdGetDatum(newOwnerId);
242 Anum_pg_foreign_data_wrapper_fdwacl,
249 form->fdwowner, newOwnerId);
250 repl_repl[Anum_pg_foreign_data_wrapper_fdwacl - 1] =
true;
251 repl_val[Anum_pg_foreign_data_wrapper_fdwacl - 1] =
PointerGetDatum(newAcl);
290 (
errcode(ERRCODE_UNDEFINED_OBJECT),
291 errmsg(
"foreign-data wrapper \"%s\" does not exist",
name)));
324 (
errcode(ERRCODE_UNDEFINED_OBJECT),
325 errmsg(
"foreign-data wrapper with OID %u does not exist", fwdId)));
341 Datum repl_val[Natts_pg_foreign_server];
342 bool repl_null[Natts_pg_foreign_server];
343 bool repl_repl[Natts_pg_foreign_server];
350 if (form->srvowner != newOwnerId)
378 memset(repl_null,
false,
sizeof(repl_null));
379 memset(repl_repl,
false,
sizeof(repl_repl));
381 repl_repl[Anum_pg_foreign_server_srvowner - 1] =
true;
382 repl_val[Anum_pg_foreign_server_srvowner - 1] =
ObjectIdGetDatum(newOwnerId);
385 Anum_pg_foreign_server_srvacl,
392 form->srvowner, newOwnerId);
393 repl_repl[Anum_pg_foreign_server_srvacl - 1] =
true;
429 (
errcode(ERRCODE_UNDEFINED_OBJECT),
430 errmsg(
"server \"%s\" does not exist",
name)));
461 (
errcode(ERRCODE_UNDEFINED_OBJECT),
462 errmsg(
"foreign server with OID %u does not exist", srvId)));
479 if (handler == NULL || handler->
arg == NULL)
488 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
489 errmsg(
"function %s must return type %s",
503 if (validator == NULL || validator->
arg == NULL)
507 funcargtypes[0] = TEXTARRAYOID;
508 funcargtypes[1] = OIDOID;
519 bool *handler_given,
Oid *fdwhandler,
520 bool *validator_given,
Oid *fdwvalidator)
524 *handler_given =
false;
525 *validator_given =
false;
530 foreach(cell, func_options)
534 if (strcmp(def->
defname,
"handler") == 0)
538 *handler_given =
true;
541 else if (strcmp(def->
defname,
"validator") == 0)
543 if (*validator_given)
545 *validator_given =
true;
549 elog(
ERROR,
"option \"%s\" not recognized",
562 bool nulls[Natts_pg_foreign_data_wrapper];
566 bool validator_given;
579 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
580 errmsg(
"permission denied to create foreign-data wrapper \"%s\"",
582 errhint(
"Must be superuser to create a foreign-data wrapper.")));
593 errmsg(
"foreign-data wrapper \"%s\" already exists",
600 memset(nulls,
false,
sizeof(nulls));
603 Anum_pg_foreign_data_wrapper_oid);
605 values[Anum_pg_foreign_data_wrapper_fdwname - 1] =
611 &handler_given, &fdwhandler,
612 &validator_given, &fdwvalidator);
617 nulls[Anum_pg_foreign_data_wrapper_fdwacl - 1] =
true;
625 values[Anum_pg_foreign_data_wrapper_fdwoptions - 1] = fdwoptions;
627 nulls[Anum_pg_foreign_data_wrapper_fdwoptions - 1] =
true;
636 myself.
classId = ForeignDataWrapperRelationId;
642 referenced.
classId = ProcedureRelationId;
650 referenced.
classId = ProcedureRelationId;
679 Datum repl_val[Natts_pg_foreign_data_wrapper];
680 bool repl_null[Natts_pg_foreign_data_wrapper];
681 bool repl_repl[Natts_pg_foreign_data_wrapper];
686 bool validator_given;
696 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
697 errmsg(
"permission denied to alter foreign-data wrapper \"%s\"",
699 errhint(
"Must be superuser to alter a foreign-data wrapper.")));
706 (
errcode(ERRCODE_UNDEFINED_OBJECT),
707 errmsg(
"foreign-data wrapper \"%s\" does not exist",
stmt->fdwname)));
710 fdwId = fdwForm->oid;
712 memset(repl_val, 0,
sizeof(repl_val));
713 memset(repl_null,
false,
sizeof(repl_null));
714 memset(repl_repl,
false,
sizeof(repl_repl));
717 &handler_given, &fdwhandler,
718 &validator_given, &fdwvalidator);
722 repl_val[Anum_pg_foreign_data_wrapper_fdwhandler - 1] =
ObjectIdGetDatum(fdwhandler);
723 repl_repl[Anum_pg_foreign_data_wrapper_fdwhandler - 1] =
true;
730 (
errmsg(
"changing the foreign-data wrapper handler can change behavior of existing foreign tables")));
735 repl_val[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] =
ObjectIdGetDatum(fdwvalidator);
736 repl_repl[Anum_pg_foreign_data_wrapper_fdwvalidator - 1] =
true;
745 (
errmsg(
"changing the foreign-data wrapper validator can cause "
746 "the options for dependent objects to become invalid")));
753 fdwvalidator = fdwForm->fdwvalidator;
764 Anum_pg_foreign_data_wrapper_fdwoptions,
776 repl_val[Anum_pg_foreign_data_wrapper_fdwoptions - 1] = datum;
778 repl_null[Anum_pg_foreign_data_wrapper_fdwoptions - 1] =
true;
780 repl_repl[Anum_pg_foreign_data_wrapper_fdwoptions - 1] =
true;
785 repl_val, repl_null, repl_repl);
794 if (handler_given || validator_given)
811 referenced.
classId = ProcedureRelationId;
819 referenced.
classId = ProcedureRelationId;
843 bool nulls[Natts_pg_foreign_server];
864 if (
stmt->if_not_exists)
876 errmsg(
"server \"%s\" already exists, skipping",
884 errmsg(
"server \"%s\" already exists",
902 memset(nulls,
false,
sizeof(nulls));
905 Anum_pg_foreign_server_oid);
907 values[Anum_pg_foreign_server_srvname - 1] =
913 if (
stmt->servertype)
914 values[Anum_pg_foreign_server_srvtype - 1] =
917 nulls[Anum_pg_foreign_server_srvtype - 1] =
true;
921 values[Anum_pg_foreign_server_srvversion - 1] =
924 nulls[Anum_pg_foreign_server_srvversion - 1] =
true;
927 nulls[Anum_pg_foreign_server_srvacl - 1] =
true;
936 values[Anum_pg_foreign_server_srvoptions - 1] = srvoptions;
938 nulls[Anum_pg_foreign_server_srvoptions - 1] =
true;
947 myself.
classId = ForeignServerRelationId;
951 referenced.
classId = ForeignDataWrapperRelationId;
978 Datum repl_val[Natts_pg_foreign_server];
979 bool repl_null[Natts_pg_foreign_server];
980 bool repl_repl[Natts_pg_foreign_server];
992 (
errcode(ERRCODE_UNDEFINED_OBJECT),
993 errmsg(
"server \"%s\" does not exist",
stmt->servername)));
996 srvId = srvForm->oid;
1005 memset(repl_val, 0,
sizeof(repl_val));
1006 memset(repl_null,
false,
sizeof(repl_null));
1007 memset(repl_repl,
false,
sizeof(repl_repl));
1009 if (
stmt->has_version)
1015 repl_val[Anum_pg_foreign_server_srvversion - 1] =
1018 repl_null[Anum_pg_foreign_server_srvversion - 1] =
true;
1020 repl_repl[Anum_pg_foreign_server_srvversion - 1] =
true;
1032 Anum_pg_foreign_server_srvoptions,
1044 repl_val[Anum_pg_foreign_server_srvoptions - 1] = datum;
1046 repl_null[Anum_pg_foreign_server_srvoptions - 1] =
true;
1048 repl_repl[Anum_pg_foreign_server_srvoptions - 1] =
true;
1053 repl_val, repl_null, repl_repl);
1081 if (umuserid == curuserid)
1105 bool nulls[Natts_pg_user_mapping];
1130 umId =
GetSysCacheOid2(USERMAPPINGUSERSERVER, Anum_pg_user_mapping_oid,
1136 if (
stmt->if_not_exists)
1144 errmsg(
"user mapping for \"%s\" already exists for server \"%s\", skipping",
1146 stmt->servername)));
1154 errmsg(
"user mapping for \"%s\" already exists for server \"%s\"",
1156 stmt->servername)));
1165 memset(nulls,
false,
sizeof(nulls));
1168 Anum_pg_user_mapping_oid);
1180 values[Anum_pg_user_mapping_umoptions - 1] = useoptions;
1182 nulls[Anum_pg_user_mapping_umoptions - 1] =
true;
1191 myself.
classId = UserMappingRelationId;
1195 referenced.
classId = ForeignServerRelationId;
1230 Datum repl_val[Natts_pg_user_mapping];
1231 bool repl_null[Natts_pg_user_mapping];
1232 bool repl_repl[Natts_pg_user_mapping];
1248 umId =
GetSysCacheOid2(USERMAPPINGUSERSERVER, Anum_pg_user_mapping_oid,
1253 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1254 errmsg(
"user mapping for \"%s\" does not exist for server \"%s\"",
1262 elog(
ERROR,
"cache lookup failed for user mapping %u", umId);
1264 memset(repl_val, 0,
sizeof(repl_val));
1265 memset(repl_null,
false,
sizeof(repl_null));
1266 memset(repl_repl,
false,
sizeof(repl_repl));
1282 Anum_pg_user_mapping_umoptions,
1294 repl_val[Anum_pg_user_mapping_umoptions - 1] = datum;
1296 repl_null[Anum_pg_user_mapping_umoptions - 1] =
true;
1298 repl_repl[Anum_pg_user_mapping_umoptions - 1] =
true;
1303 repl_val, repl_null, repl_repl);
1343 elog(
NOTICE,
"role \"%s\" does not exist, skipping",
1353 if (!
stmt->missing_ok)
1355 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1356 errmsg(
"server \"%s\" does not exist",
1357 stmt->servername)));
1360 (
errmsg(
"server \"%s\" does not exist, skipping",
1361 stmt->servername)));
1365 umId =
GetSysCacheOid2(USERMAPPINGUSERSERVER, Anum_pg_user_mapping_oid,
1371 if (!
stmt->missing_ok)
1373 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1374 errmsg(
"user mapping for \"%s\" does not exist for server \"%s\"",
1379 (
errmsg(
"user mapping for \"%s\" does not exist for server \"%s\", skipping",
1389 object.classId = UserMappingRelationId;
1390 object.objectId = umId;
1391 object.objectSubId = 0;
1409 bool nulls[Natts_pg_foreign_table];
1446 memset(nulls,
false,
sizeof(nulls));
1457 values[Anum_pg_foreign_table_ftoptions - 1] = ftoptions;
1459 nulls[Anum_pg_foreign_table_ftoptions - 1] =
true;
1468 myself.
classId = RelationRelationId;
1472 referenced.
classId = ForeignServerRelationId;
1506 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1507 errmsg(
"foreign-data wrapper \"%s\" has no handler",
1512 (
errcode(ERRCODE_FDW_NO_SCHEMAS),
1513 errmsg(
"foreign-data wrapper \"%s\" does not support IMPORT FOREIGN SCHEMA",
1520 foreach(lc, cmd_list)
1522 char *cmd = (
char *)
lfirst(lc);
1525 List *raw_parsetree_list;
1533 callback_arg.
cmd = cmd;
1535 sqlerrcontext.
arg = &callback_arg;
1548 foreach(lc2, raw_parsetree_list)
1560 "foreign-data wrapper \"%s\" returned incorrect statement type %d",
1576 pstmt->canSetTag =
false;
1577 pstmt->utilityStmt = (
Node *) cstmt;
1603 int syntaxerrposition;
1607 if (syntaxerrposition > 0)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayType * construct_empty_array(Oid elmtype)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define PointerIsValid(pointer)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
char * defGetString(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
DestReceiver * None_Receiver
int internalerrquery(const char *query)
int internalerrposition(int cursorpos)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
int errposition(int cursorpos)
#define ereport(elevel,...)
#define DirectFunctionCall1(func, arg1)
#define OidFunctionCall2(functionId, arg1, arg2)
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
ForeignDataWrapper * GetForeignDataWrapperByName(const char *fdwname, bool missing_ok)
bool IsImportableForeignTable(const char *tablename, ImportForeignSchemaStmt *stmt)
FdwRoutine * GetFdwRoutine(Oid fdwhandler)
#define MappingUserName(userid)
static void AlterForeignServerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
static Oid lookup_fdw_handler_func(DefElem *handler)
ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId)
static void import_error_callback(void *arg)
void AlterForeignServerOwner_oid(Oid srvId, Oid newOwnerId)
void ImportForeignSchema(ImportForeignSchemaStmt *stmt)
ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
static Datum optionListToArray(List *options)
static void AlterForeignDataWrapperOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
static Oid lookup_fdw_validator_func(DefElem *validator)
void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId)
static void user_mapping_ddl_aclcheck(Oid umuserid, Oid serverid, const char *servername)
ObjectAddress AlterForeignDataWrapper(ParseState *pstate, AlterFdwStmt *stmt)
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
ObjectAddress CreateForeignDataWrapper(ParseState *pstate, CreateFdwStmt *stmt)
static void parse_func_options(ParseState *pstate, List *func_options, bool *handler_given, Oid *fdwhandler, bool *validator_given, Oid *fdwvalidator)
ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt)
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Datum transformGenericOptions(Oid catalogId, Datum oldOptions, List *options, Oid fdwvalidator)
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_delete_cell(List *list, ListCell *cell)
Oid get_func_rettype(Oid funcid)
char * pstrdup(const char *in)
MemoryContext CurrentMemoryContext
Datum namein(PG_FUNCTION_ARGS)
char * NameListToString(const List *names)
Oid LookupCreationNamespace(const char *nspname)
#define IsA(nodeptr, _type_)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
void checkMembershipInCurrentExtension(const ObjectAddress *object)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
FormData_pg_foreign_server * Form_pg_foreign_server
#define lfirst_node(type, lc)
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
List * pg_parse_query(const char *query_string)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
#define RelationGetDescr(relation)
List * untransformRelOptions(Datum options)
#define ERRCODE_DUPLICATE_OBJECT
struct ErrorContextCallback * previous
void(* callback)(void *arg)
ImportForeignSchema_function ImportForeignSchema
bool superuser_arg(Oid roleid)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define SearchSysCacheCopy1(cacheId, key1)
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
@ PROCESS_UTILITY_SUBCOMMAND
#define SET_VARSIZE(PTR, len)
void CommandCounterIncrement(void)