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

ForeignServerGetForeignServer (Oid serverid)
 
ForeignServerGetForeignServerExtended (Oid serverid, bits16 flags)
 
ForeignServerGetForeignServerByName (const char *srvname, bool missing_ok)
 
UserMappingGetUserMapping (Oid userid, Oid serverid)
 
ForeignDataWrapperGetForeignDataWrapper (Oid fdwid)
 
ForeignDataWrapperGetForeignDataWrapperExtended (Oid fdwid, bits16 flags)
 
ForeignDataWrapperGetForeignDataWrapperByName (const char *fdwname, bool missing_ok)
 
ForeignTableGetForeignTable (Oid relid)
 
ListGetForeignColumnOptions (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 64 of file foreign.h.

◆ FSV_MISSING_OK

#define FSV_MISSING_OK   0x01

Definition at line 61 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

◆ get_foreign_data_wrapper_oid()

Oid get_foreign_data_wrapper_oid ( const char fdwname,
bool  missing_ok 
)
extern

Definition at line 682 of file foreign.c.

683{
684 Oid oid;
685
688 CStringGetDatum(fdwname));
689 if (!OidIsValid(oid) && !missing_ok)
692 errmsg("foreign-data wrapper \"%s\" does not exist",
693 fdwname)));
694 return oid;
695}
#define OidIsValid(objectId)
Definition c.h:788
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
unsigned int Oid
static int fb(int x)
#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 705 of file foreign.c.

706{
707 Oid oid;
708
710 CStringGetDatum(servername));
711 if (!OidIsValid(oid) && !missing_ok)
714 errmsg("server \"%s\" does not exist", servername)));
715 return oid;
716}

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 293 of file foreign.c.

294{
295 List *options;
296 HeapTuple tp;
297 Datum datum;
298 bool isnull;
299
301 ObjectIdGetDatum(relid),
303 if (!HeapTupleIsValid(tp))
304 elog(ERROR, "cache lookup failed for attribute %d of relation %u",
305 attnum, relid);
306 datum = SysCacheGetAttr(ATTNUM,
307 tp,
309 &isnull);
310 if (isnull)
311 options = NIL;
312 else
314
315 ReleaseSysCache(tp);
316
317 return options;
318}
#define elog(elevel,...)
Definition elog.h:226
#define HeapTupleIsValid(tuple)
Definition htup.h:78
int16 attnum
#define NIL
Definition pg_list.h:68
static Datum Int16GetDatum(int16 X)
Definition postgres.h:182
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
List * untransformRelOptions(Datum options)
Definition pg_list.h:54
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:595
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition syscache.c:230

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

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

◆ GetForeignDataWrapper()

◆ GetForeignDataWrapperByName()

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

Definition at line 97 of file foreign.c.

98{
99 Oid fdwId = get_foreign_data_wrapper_oid(fdwname, missing_ok);
100
101 if (!OidIsValid(fdwId))
102 return NULL;
103
105}
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition foreign.c:38
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition foreign.c:682

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

Referenced by CreateForeignDataWrapper(), and CreateForeignServer().

◆ GetForeignDataWrapperExtended()

ForeignDataWrapper * GetForeignDataWrapperExtended ( Oid  fdwid,
bits16  flags 
)
extern

Definition at line 50 of file foreign.c.

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

References elog, ERROR, fb(), FDW_MISSING_OK, 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 183 of file foreign.c.

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

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

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

◆ GetForeignServerExtended()

ForeignServer * GetForeignServerExtended ( Oid  serverid,
bits16  flags 
)
extern

Definition at line 124 of file foreign.c.

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

References elog, ERROR, fb(), ForeignServer::fdwid, 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 255 of file foreign.c.

256{
259 HeapTuple tp;
260 Datum datum;
261 bool isnull;
262
264 if (!HeapTupleIsValid(tp))
265 elog(ERROR, "cache lookup failed for foreign table %u", relid);
267
269 ft->relid = relid;
270 ft->serverid = tableform->ftserver;
271
272 /* Extract the ftoptions */
274 tp,
276 &isnull);
277 if (isnull)
278 ft->options = NIL;
279 else
280 ft->options = untransformRelOptions(datum);
281
282 ReleaseSysCache(tp);
283
284 return ft;
285}
FormData_pg_foreign_table * Form_pg_foreign_table

References elog, ERROR, fb(), 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(), and postgresIsForeignRelUpdatable().

◆ GetUserMapping()

UserMapping * GetUserMapping ( Oid  userid,
Oid  serverid 
)
extern

Definition at line 201 of file foreign.c.

202{
203 Datum datum;
204 HeapTuple tp;
205 bool isnull;
207
209 ObjectIdGetDatum(userid),
210 ObjectIdGetDatum(serverid));
211
212 if (!HeapTupleIsValid(tp))
213 {
214 /* Not found for the specific user -- try PUBLIC */
217 ObjectIdGetDatum(serverid));
218 }
219
220 if (!HeapTupleIsValid(tp))
221 {
222 ForeignServer *server = GetForeignServer(serverid);
223
226 errmsg("user mapping not found for user \"%s\", server \"%s\"",
227 MappingUserName(userid), server->servername)));
228 }
229
231 um->umid = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
232 um->userid = userid;
233 um->serverid = serverid;
234
235 /* Extract the umoptions */
237 tp,
239 &isnull);
240 if (isnull)
241 um->options = NIL;
242 else
243 um->options = untransformRelOptions(datum);
244
245 ReleaseSysCache(tp);
246
247 return um;
248}
#define MappingUserName(userid)
Definition foreign.h:20
FormData_pg_user_mapping * Form_pg_user_mapping
#define InvalidOid

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

Referenced by create_foreign_modify(), get_connect_string(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignScan(), postgresExecForeignTruncate(), postgresGetAnalyzeInfoForForeignTable(), postgresGetForeignRelSize(), and postgresImportForeignSchema().