PostgreSQL Source Code git master
Loading...
Searching...
No Matches
foreign.h File Reference
#include "nodes/parsenodes.h"
Include dependency graph for foreign.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ForeignDataWrapper
 
struct  ForeignServer
 
struct  UserMapping
 
struct  ForeignTable
 

Macros

#define MappingUserName(userid)    (OidIsValid(userid) ? GetUserNameFromId(userid, false) : "public")
 
#define FSV_MISSING_OK   0x01
 
#define FDW_MISSING_OK   0x01
 

Typedefs

typedef struct ForeignDataWrapper ForeignDataWrapper
 
typedef struct ForeignServer ForeignServer
 
typedef struct UserMapping UserMapping
 
typedef struct ForeignTable ForeignTable
 

Functions

ForeignServer * GetForeignServer (Oid serverid)
 
ForeignServer * GetForeignServerExtended (Oid serverid, uint16 flags)
 
ForeignServer * GetForeignServerByName (const char *srvname, bool missing_ok)
 
char * ForeignServerConnectionString (Oid userid, ForeignServer *server)
 
UserMapping * GetUserMapping (Oid userid, Oid serverid)
 
ForeignDataWrapper * GetForeignDataWrapper (Oid fdwid)
 
ForeignDataWrapper * GetForeignDataWrapperExtended (Oid fdwid, uint16 flags)
 
ForeignDataWrapper * GetForeignDataWrapperByName (const char *fdwname, bool missing_ok)
 
ForeignTable * GetForeignTable (Oid relid)
 
List * GetForeignColumnOptions (Oid relid, AttrNumber attnum)
 
Oid get_foreign_data_wrapper_oid (const char *fdwname, bool missing_ok)
 
Oid get_foreign_server_oid (const char *servername, bool missing_ok)
 

Macro Definition Documentation

◆ FDW_MISSING_OK

#define FDW_MISSING_OK   0x01

Definition at line 65 of file foreign.h.

◆ FSV_MISSING_OK

#define FSV_MISSING_OK   0x01

Definition at line 62 of file foreign.h.

◆ MappingUserName

#define MappingUserName (   userid)     (OidIsValid(userid) ? GetUserNameFromId(userid, false) : "public")

Definition at line 20 of file foreign.h.

21 : "public")

Typedef Documentation

◆ ForeignDataWrapper

◆ ForeignServer

◆ ForeignTable

◆ UserMapping

Function Documentation

◆ ForeignServerConnectionString()

char * ForeignServerConnectionString ( Oid  userid,
ForeignServer *  server 
)
extern

Definition at line 202 of file foreign.c.

203{
206
208
209 if (!OidIsValid(fdw->fdwconnection))
212 errmsg("foreign data wrapper \"%s\" does not support subscription connections",
213 fdw->fdwname),
214 errdetail("Foreign data wrapper must be defined with CONNECTION specified.")));
215
216 connection_datum = OidFunctionCall3(fdw->fdwconnection,
217 ObjectIdGetDatum(userid),
218 ObjectIdGetDatum(server->serverid),
220
222}
#define OidIsValid(objectId)
Definition c.h:917
int errcode(int sqlerrcode)
Definition elog.c:875
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
#define DatumGetTextPP(X)
Definition fmgr.h:293
#define OidFunctionCall3(functionId, arg1, arg2, arg3)
Definition fmgr.h:730
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition foreign.c:39
static char * errmsg
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
uint64_t Datum
Definition postgres.h:70
#define PointerGetDatum(X)
Definition postgres.h:354
static int fb(int x)
char * text_to_cstring(const text *t)
Definition varlena.c:217

References DatumGetTextPP, ereport, errcode(), errdetail(), errmsg, ERROR, fb(), ForeignServer::fdwid, GetForeignDataWrapper(), ObjectIdGetDatum(), OidFunctionCall3, OidIsValid, PointerGetDatum, ForeignServer::serverid, and text_to_cstring().

Referenced by AlterSubscription(), AlterSubscriptionOwner_internal(), construct_subserver_conninfo(), and GetSubscription().

◆ get_foreign_data_wrapper_oid()

Oid get_foreign_data_wrapper_oid ( const char *  fdwname,
bool  missing_ok 
)
extern

Definition at line 713 of file foreign.c.

714{
715 Oid oid;
716
719 CStringGetDatum(fdwname));
720 if (!OidIsValid(oid) && !missing_ok)
723 errmsg("foreign-data wrapper \"%s\" does not exist",
724 fdwname)));
725 return oid;
726}
static Datum CStringGetDatum(const char *X)
Definition postgres.h:383
unsigned int Oid
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition syscache.h:109

References CStringGetDatum(), ereport, errcode(), errmsg, ERROR, fb(), GetSysCacheOid1, and OidIsValid.

Referenced by convert_foreign_data_wrapper_name(), get_object_address_unqualified(), and GetForeignDataWrapperByName().

◆ get_foreign_server_oid()

Oid get_foreign_server_oid ( const char *  servername,
bool  missing_ok 
)
extern

Definition at line 736 of file foreign.c.

737{
738 Oid oid;
739
741 CStringGetDatum(servername));
742 if (!OidIsValid(oid) && !missing_ok)
745 errmsg("server \"%s\" does not exist", servername)));
746 return oid;
747}

References CStringGetDatum(), ereport, errcode(), errmsg, ERROR, fb(), GetSysCacheOid1, and OidIsValid.

Referenced by convert_server_name(), CreateForeignServer(), get_object_address_unqualified(), and GetForeignServerByName().

◆ GetForeignColumnOptions()

List * GetForeignColumnOptions ( Oid  relid,
AttrNumber  attnum 
)
extern

Definition at line 324 of file foreign.c.

325{
326 List *options;
327 HeapTuple tp;
328 Datum datum;
329 bool isnull;
330
332 ObjectIdGetDatum(relid),
334 if (!HeapTupleIsValid(tp))
335 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
336 attnum, relid);
337 datum = SysCacheGetAttr(ATTNUM,
338 tp,
340 &isnull);
341 if (isnull)
342 options = NIL;
343 else
345
346 ReleaseSysCache(tp);
347
348 return options;
349}
#define elog(elevel,...)
Definition elog.h:228
#define HeapTupleIsValid(tuple)
Definition htup.h:78
int16 attnum
#define NIL
Definition pg_list.h:68
static Datum Int16GetDatum(int16 X)
Definition postgres.h:172
List * untransformRelOptions(Datum options)
Definition pg_list.h:54
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:231
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596

References attnum, elog, ERROR, fb(), HeapTupleIsValid, Int16GetDatum(), NIL, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache2(), SysCacheGetAttr(), and untransformRelOptions().

Referenced by build_remattrmap(), deparseAnalyzeSql(), deparseColumnRef(), and get_file_fdw_attribute_options().

◆ GetForeignDataWrapper()

◆ GetForeignDataWrapperByName()

ForeignDataWrapper * GetForeignDataWrapperByName ( const char *  fdwname,
bool  missing_ok 
)
extern

Definition at line 99 of file foreign.c.

100{
101 Oid fdwId = get_foreign_data_wrapper_oid(fdwname, missing_ok);
102
103 if (!OidIsValid(fdwId))
104 return NULL;
105
107}
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition foreign.c:713

References fb(), get_foreign_data_wrapper_oid(), GetForeignDataWrapper(), and OidIsValid.

Referenced by CreateForeignDataWrapper(), and CreateForeignServer().

◆ GetForeignDataWrapperExtended()

ForeignDataWrapper * GetForeignDataWrapperExtended ( Oid  fdwid,
uint16  flags 
)
extern

Definition at line 51 of file foreign.c.

52{
55 Datum datum;
56 HeapTuple tp;
57 bool isnull;
58
60
61 if (!HeapTupleIsValid(tp))
62 {
63 if ((flags & FDW_MISSING_OK) == 0)
64 elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
65 return NULL;
66 }
67
69
71 fdw->fdwid = fdwid;
72 fdw->owner = fdwform->fdwowner;
73 fdw->fdwname = pstrdup(NameStr(fdwform->fdwname));
74 fdw->fdwhandler = fdwform->fdwhandler;
75 fdw->fdwvalidator = fdwform->fdwvalidator;
76 fdw->fdwconnection = fdwform->fdwconnection;
77
78 /* Extract the fdwoptions */
80 tp,
82 &isnull);
83 if (isnull)
84 fdw->options = NIL;
85 else
86 fdw->options = untransformRelOptions(datum);
87
89
90 return fdw;
91}
#define NameStr(name)
Definition c.h:894
#define palloc_object(type)
Definition fe_memutils.h:89
#define FDW_MISSING_OK
Definition foreign.h:65
static void * GETSTRUCT(const HeapTupleData *tuple)
char * pstrdup(const char *in)
Definition mcxt.c:1910
END_CATALOG_STRUCT typedef FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

References elog, ERROR, fb(), FDW_MISSING_OK, Form_pg_foreign_data_wrapper, GETSTRUCT(), HeapTupleIsValid, NameStr, NIL, ObjectIdGetDatum(), palloc_object, pstrdup(), ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), and untransformRelOptions().

Referenced by GetForeignDataWrapper(), getObjectDescription(), and getObjectIdentityParts().

◆ GetForeignServer()

◆ GetForeignServerByName()

ForeignServer * GetForeignServerByName ( const char *  srvname,
bool  missing_ok 
)
extern

Definition at line 185 of file foreign.c.

186{
187 Oid serverid = get_foreign_server_oid(srvname, missing_ok);
188
189 if (!OidIsValid(serverid))
190 return NULL;
191
192 return GetForeignServer(serverid);
193}
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition foreign.c:736
ForeignServer * GetForeignServer(Oid serverid)
Definition foreign.c:114

References fb(), get_foreign_server_oid(), GetForeignServer(), and OidIsValid.

Referenced by AlterSubscription(), AlterUserMapping(), CreateForeignTable(), CreateUserMapping(), get_connect_string(), get_object_address_usermapping(), ImportForeignSchema(), postgres_fdw_disconnect(), and RemoveUserMapping().

◆ GetForeignServerExtended()

ForeignServer * GetForeignServerExtended ( Oid  serverid,
uint16  flags 
)
extern

Definition at line 126 of file foreign.c.

127{
129 ForeignServer *server;
130 HeapTuple tp;
131 Datum datum;
132 bool isnull;
133
135
136 if (!HeapTupleIsValid(tp))
137 {
138 if ((flags & FSV_MISSING_OK) == 0)
139 elog(ERROR, "cache lookup failed for foreign server %u", serverid);
140 return NULL;
141 }
142
144
146 server->serverid = serverid;
147 server->servername = pstrdup(NameStr(serverform->srvname));
148 server->owner = serverform->srvowner;
149 server->fdwid = serverform->srvfdw;
150
151 /* Extract server type */
153 tp,
155 &isnull);
156 server->servertype = isnull ? NULL : TextDatumGetCString(datum);
157
158 /* Extract server version */
160 tp,
162 &isnull);
163 server->serverversion = isnull ? NULL : TextDatumGetCString(datum);
164
165 /* Extract the srvoptions */
167 tp,
169 &isnull);
170 if (isnull)
171 server->options = NIL;
172 else
173 server->options = untransformRelOptions(datum);
174
175 ReleaseSysCache(tp);
176
177 return server;
178}
#define TextDatumGetCString(d)
Definition builtins.h:99
#define FSV_MISSING_OK
Definition foreign.h:62
END_CATALOG_STRUCT typedef FormData_pg_foreign_server * Form_pg_foreign_server
List * options
Definition foreign.h:43
char * serverversion
Definition foreign.h:42
char * servername
Definition foreign.h:40
char * servertype
Definition foreign.h:41

References elog, ERROR, fb(), ForeignServer::fdwid, Form_pg_foreign_server, FSV_MISSING_OK, GETSTRUCT(), HeapTupleIsValid, NameStr, NIL, ObjectIdGetDatum(), ForeignServer::options, ForeignServer::owner, palloc_object, pstrdup(), ReleaseSysCache(), SearchSysCache1(), ForeignServer::serverid, ForeignServer::servername, ForeignServer::servertype, ForeignServer::serverversion, SysCacheGetAttr(), TextDatumGetCString, and untransformRelOptions().

Referenced by disconnect_cached_connections(), GetForeignServer(), getObjectDescription(), getObjectIdentityParts(), and postgres_fdw_get_connections_internal().

◆ GetForeignTable()

ForeignTable * GetForeignTable ( Oid  relid)
extern

Definition at line 286 of file foreign.c.

287{
290 HeapTuple tp;
291 Datum datum;
292 bool isnull;
293
295 if (!HeapTupleIsValid(tp))
296 elog(ERROR, "cache lookup failed for foreign table %u", relid);
298
300 ft->relid = relid;
301 ft->serverid = tableform->ftserver;
302
303 /* Extract the ftoptions */
305 tp,
307 &isnull);
308 if (isnull)
309 ft->options = NIL;
310 else
311 ft->options = untransformRelOptions(datum);
312
313 ReleaseSysCache(tp);
314
315 return ft;
316}
END_CATALOG_STRUCT typedef FormData_pg_foreign_table * Form_pg_foreign_table

References elog, ERROR, fb(), Form_pg_foreign_table, GETSTRUCT(), HeapTupleIsValid, NIL, ObjectIdGetDatum(), palloc_object, ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), and untransformRelOptions().

Referenced by check_selective_binary_conversion(), create_foreign_modify(), deparseRelation(), fileGetOptions(), get_batch_size_option(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignScan(), postgresExecForeignTruncate(), postgresGetAnalyzeInfoForForeignTable(), postgresGetForeignRelSize(), postgresImportForeignStatistics(), and postgresIsForeignRelUpdatable().

◆ GetUserMapping()

UserMapping * GetUserMapping ( Oid  userid,
Oid  serverid 
)
extern

Definition at line 232 of file foreign.c.

233{
234 Datum datum;
235 HeapTuple tp;
236 bool isnull;
238
240 ObjectIdGetDatum(userid),
241 ObjectIdGetDatum(serverid));
242
243 if (!HeapTupleIsValid(tp))
244 {
245 /* Not found for the specific user -- try PUBLIC */
248 ObjectIdGetDatum(serverid));
249 }
250
251 if (!HeapTupleIsValid(tp))
252 {
253 ForeignServer *server = GetForeignServer(serverid);
254
257 errmsg("user mapping not found for user \"%s\", server \"%s\"",
258 MappingUserName(userid), server->servername)));
259 }
260
262 um->umid = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
263 um->userid = userid;
264 um->serverid = serverid;
265
266 /* Extract the umoptions */
268 tp,
270 &isnull);
271 if (isnull)
272 um->options = NIL;
273 else
274 um->options = untransformRelOptions(datum);
275
276 ReleaseSysCache(tp);
277
278 return um;
279}
#define MappingUserName(userid)
Definition foreign.h:20
END_CATALOG_STRUCT typedef FormData_pg_user_mapping * Form_pg_user_mapping
#define InvalidOid

References ereport, errcode(), errmsg, ERROR, fb(), Form_pg_user_mapping, GetForeignServer(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, MappingUserName, NIL, ObjectIdGetDatum(), palloc_object, ReleaseSysCache(), SearchSysCache2(), ForeignServer::servername, SysCacheGetAttr(), and untransformRelOptions().

Referenced by AlterSubscription(), AlterSubscriptionOwner_internal(), create_foreign_modify(), fetch_remote_statistics(), get_connect_string(), postgres_fdw_connection(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignScan(), postgresExecForeignTruncate(), postgresGetAnalyzeInfoForForeignTable(), postgresGetForeignRelSize(), postgresImportForeignSchema(), test_fdw_connection(), and test_fdw_connection_no_password().