PostgreSQL Source Code git master
Data Structures | Macros | Typedefs | Functions
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 ForeignServer  ForeignServer
 
typedef struct UserMapping  UserMapping
 
typedef struct ForeignTable  ForeignTable
 

Functions

 
 
ForeignServerGetForeignServerByName (const char *srvname, bool missing_ok)
 
UserMappingGetUserMapping (Oid userid, Oid serverid)
 
 
 
ForeignDataWrapperGetForeignDataWrapperByName (const char *fdwname, bool missing_ok)
 
 
 
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.

Typedef Documentation

ForeignDataWrapper

ForeignServer

typedef struct ForeignServer ForeignServer

ForeignTable

typedef struct ForeignTable ForeignTable

UserMapping

typedef struct UserMapping UserMapping

Function Documentation

get_foreign_data_wrapper_oid()

Oid get_foreign_data_wrapper_oid ( const char *  fdwname,
bool  missing_ok 
)

Definition at line 682 of file foreign.c.

683{
684 Oid oid;
685
686 oid = GetSysCacheOid1(FOREIGNDATAWRAPPERNAME,
687 Anum_pg_foreign_data_wrapper_oid,
688 CStringGetDatum(fdwname));
689 if (!OidIsValid(oid) && !missing_ok)
691 (errcode(ERRCODE_UNDEFINED_OBJECT),
692 errmsg("foreign-data wrapper \"%s\" does not exist",
693 fdwname)));
694 return oid;
695}
#define OidIsValid(objectId)
Definition: c.h:774
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:360
unsigned int Oid
Definition: postgres_ext.h:32
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:109

References CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, 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 
)

Definition at line 705 of file foreign.c.

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

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

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

GetForeignColumnOptions()

List * GetForeignColumnOptions ( Oid  relid,
AttrNumber  attnum 
)

Definition at line 293 of file foreign.c.

294{
295 List *options;
296 HeapTuple tp;
297 Datum datum;
298 bool isnull;
299
300 tp = SearchSysCache2(ATTNUM,
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,
308 Anum_pg_attribute_attfdwoptions,
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
Definition: pg_attribute.h:74
#define NIL
Definition: pg_list.h:68
static char ** options
Definition: pg_recvlogical.c:59
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: reloptions.c:1351
Definition: pg_list.h:54
Definition: oid2name.c:30
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, HeapTupleIsValid, Int16GetDatum(), NIL, ObjectIdGetDatum(), options, ReleaseSysCache(), SearchSysCache2(), SysCacheGetAttr(), and untransformRelOptions().

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

GetForeignDataWrapper()

ForeignDataWrapper * GetForeignDataWrapper ( Oid  fdwid )

Definition at line 38 of file foreign.c.

39{
40 return GetForeignDataWrapperExtended(fdwid, 0);
41}
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:50

References GetForeignDataWrapperExtended().

Referenced by AlterForeignServer(), AlterForeignServerOwner_internal(), AlterUserMapping(), ATExecAlterColumnGenericOptions(), ATExecGenericOptions(), CreateForeignTable(), CreateUserMapping(), fileGetOptions(), get_connect_string(), GetForeignDataWrapperByName(), and ImportForeignSchema().

GetForeignDataWrapperByName()

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

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
104 return GetForeignDataWrapper(fdwId);
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 get_foreign_data_wrapper_oid(), GetForeignDataWrapper(), and OidIsValid.

Referenced by CreateForeignDataWrapper(), and CreateForeignServer().

GetForeignDataWrapperExtended()

ForeignDataWrapper * GetForeignDataWrapperExtended ( Oid  fdwid,
bits16  flags 
)

Definition at line 50 of file foreign.c.

51{
54 Datum datum;
55 HeapTuple tp;
56 bool isnull;
57
58 tp = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdwid));
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 */
77 datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID,
78 tp,
79 Anum_pg_foreign_data_wrapper_fdwoptions,
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:751
#define FDW_MISSING_OK
Definition: foreign.h:64
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
char * pstrdup(const char *in)
Definition: mcxt.c:1759
void * palloc(Size size)
Definition: mcxt.c:1365
FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
char * fdwname
Definition: foreign.h:28
Oid fdwhandler
Definition: foreign.h:29
Oid fdwvalidator
Definition: foreign.h:30
List * options
Definition: foreign.h:31
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220

References elog, ERROR, FDW_MISSING_OK, ForeignDataWrapper::fdwhandler, ForeignDataWrapper::fdwid, ForeignDataWrapper::fdwname, ForeignDataWrapper::fdwvalidator, GETSTRUCT(), HeapTupleIsValid, NameStr, NIL, ObjectIdGetDatum(), ForeignDataWrapper::options, ForeignDataWrapper::owner, palloc(), pstrdup(), ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), and untransformRelOptions().

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

GetForeignServer()

ForeignServer * GetForeignServer ( Oid  serverid )

Definition at line 112 of file foreign.c.

113{
114 return GetForeignServerExtended(serverid, 0);
115}
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:124

References GetForeignServerExtended().

Referenced by ATExecAlterColumnGenericOptions(), ATExecGenericOptions(), fileGetOptions(), get_batch_size_option(), GetForeignServerByName(), getObjectDescription(), getObjectIdentityParts(), GetUserMapping(), make_new_connection(), pgfdw_reject_incomplete_xact_state_change(), postgresAcquireSampleRowsFunc(), postgresExecForeignTruncate(), postgresGetForeignRelSize(), postgresImportForeignSchema(), and postgresIsForeignRelUpdatable().

GetForeignServerByName()

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

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 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 
)

Definition at line 124 of file foreign.c.

125{
126 Form_pg_foreign_server serverform;
127 ForeignServer *server;
128 HeapTuple tp;
129 Datum datum;
130 bool isnull;
131
132 tp = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(serverid));
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
141 serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
142
143 server = (ForeignServer *) palloc(sizeof(ForeignServer));
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 */
150 datum = SysCacheGetAttr(FOREIGNSERVEROID,
151 tp,
152 Anum_pg_foreign_server_srvtype,
153 &isnull);
154 server->servertype = isnull ? NULL : TextDatumGetCString(datum);
155
156 /* Extract server version */
157 datum = SysCacheGetAttr(FOREIGNSERVEROID,
158 tp,
159 Anum_pg_foreign_server_srvversion,
160 &isnull);
161 server->serverversion = isnull ? NULL : TextDatumGetCString(datum);
162
163 /* Extract the srvoptions */
164 datum = SysCacheGetAttr(FOREIGNSERVEROID,
165 tp,
166 Anum_pg_foreign_server_srvoptions,
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
Oid owner
Definition: foreign.h:38
char * serverversion
Definition: foreign.h:41
char * servername
Definition: foreign.h:39
Oid fdwid
Definition: foreign.h:37
Oid serverid
Definition: foreign.h:36
char * servertype
Definition: foreign.h:40

References elog, ERROR, ForeignServer::fdwid, FSV_MISSING_OK, GETSTRUCT(), HeapTupleIsValid, NameStr, NIL, ObjectIdGetDatum(), ForeignServer::options, ForeignServer::owner, palloc(), 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 )

Definition at line 255 of file foreign.c.

256{
257 Form_pg_foreign_table tableform;
258 ForeignTable *ft;
259 HeapTuple tp;
260 Datum datum;
261 bool isnull;
262
263 tp = SearchSysCache1(FOREIGNTABLEREL, ObjectIdGetDatum(relid));
264 if (!HeapTupleIsValid(tp))
265 elog(ERROR, "cache lookup failed for foreign table %u", relid);
266 tableform = (Form_pg_foreign_table) GETSTRUCT(tp);
267
268 ft = (ForeignTable *) palloc(sizeof(ForeignTable));
269 ft->relid = relid;
270 ft->serverid = tableform->ftserver;
271
272 /* Extract the ftoptions */
273 datum = SysCacheGetAttr(FOREIGNTABLEREL,
274 tp,
275 Anum_pg_foreign_table_ftoptions,
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
Oid relid
Definition: foreign.h:55
List * options
Definition: foreign.h:57
Oid serverid
Definition: foreign.h:56

References elog, ERROR, GETSTRUCT(), HeapTupleIsValid, NIL, ObjectIdGetDatum(), ForeignTable::options, palloc(), ReleaseSysCache(), ForeignTable::relid, SearchSysCache1(), ForeignTable::serverid, 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 
)

Definition at line 201 of file foreign.c.

202{
203 Datum datum;
204 HeapTuple tp;
205 bool isnull;
206 UserMapping *um;
207
208 tp = SearchSysCache2(USERMAPPINGUSERSERVER,
209 ObjectIdGetDatum(userid),
210 ObjectIdGetDatum(serverid));
211
212 if (!HeapTupleIsValid(tp))
213 {
214 /* Not found for the specific user -- try PUBLIC */
215 tp = SearchSysCache2(USERMAPPINGUSERSERVER,
217 ObjectIdGetDatum(serverid));
218 }
219
220 if (!HeapTupleIsValid(tp))
221 {
222 ForeignServer *server = GetForeignServer(serverid);
223
225 (errcode(ERRCODE_UNDEFINED_OBJECT),
226 errmsg("user mapping not found for user \"%s\", server \"%s\"",
227 MappingUserName(userid), server->servername)));
228 }
229
230 um = (UserMapping *) palloc(sizeof(UserMapping));
231 um->umid = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
232 um->userid = userid;
233 um->serverid = serverid;
234
235 /* Extract the umoptions */
236 datum = SysCacheGetAttr(USERMAPPINGUSERSERVER,
237 tp,
238 Anum_pg_user_mapping_umoptions,
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
Definition: postgres_ext.h:37
Oid userid
Definition: foreign.h:48
Oid umid
Definition: foreign.h:47
Oid serverid
Definition: foreign.h:49
List * options
Definition: foreign.h:50

References ereport, errcode(), errmsg(), ERROR, GetForeignServer(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, MappingUserName, NIL, ObjectIdGetDatum(), UserMapping::options, palloc(), ReleaseSysCache(), SearchSysCache2(), UserMapping::serverid, ForeignServer::servername, SysCacheGetAttr(), UserMapping::umid, untransformRelOptions(), and UserMapping::userid.

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

AltStyle によって変換されたページ (->オリジナル) /