PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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")
 

Typedefs

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

Enumerations

enum  GenericOptionFlags { ServerOpt = 1, UserMappingOpt = 2, FdwOpt = 4 }
 

Functions

ForeignServerGetForeignServer (Oid serverid)
 
ForeignServerGetForeignServerByName (const char *name, bool missing_ok)
 
UserMappingGetUserMapping (Oid userid, Oid serverid)
 
ForeignDataWrapperGetForeignDataWrapper (Oid fdwid)
 
ForeignDataWrapperGetForeignDataWrapperByName (const char *name, 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

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

Definition at line 20 of file foreign.h.

Referenced by AlterUserMapping(), CreateUserMapping(), GetUserMapping(), and RemoveUserMapping().

Typedef Documentation

Enumeration Type Documentation

Enumerator
ServerOpt 
UserMappingOpt 
FdwOpt 

Definition at line 28 of file foreign.h.

29 {
30  ServerOpt = 1, /* options applicable to SERVER */
31  UserMappingOpt = 2, /* options for USER MAPPING */
32  FdwOpt = 4 /* options for FOREIGN DATA WRAPPER */
Definition: foreign.h:32
GenericOptionFlags
Definition: foreign.h:28

Function Documentation

Oid get_foreign_data_wrapper_oid ( const char *  fdwname,
bool  missing_ok 
)

Definition at line 659 of file foreign.c.

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

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

660 {
661  Oid oid;
662 
664  if (!OidIsValid(oid) && !missing_ok)
665  ereport(ERROR,
666  (errcode(ERRCODE_UNDEFINED_OBJECT),
667  errmsg("foreign-data wrapper \"%s\" does not exist",
668  fdwname)));
669  return oid;
670 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:191
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
Oid get_foreign_server_oid ( const char *  servername,
bool  missing_ok 
)

Definition at line 680 of file foreign.c.

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

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

681 {
682  Oid oid;
683 
685  if (!OidIsValid(oid) && !missing_ok)
686  ereport(ERROR,
687  (errcode(ERRCODE_UNDEFINED_OBJECT),
688  errmsg("server \"%s\" does not exist", servername)));
689  return oid;
690 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:191
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
List* GetForeignColumnOptions ( Oid  relid,
AttrNumber  attnum 
)

Definition at line 254 of file foreign.c.

References Anum_pg_attribute_attfdwoptions, ATTNUM, elog, ERROR, HeapTupleIsValid, Int16GetDatum, NIL, ObjectIdGetDatum, options, ReleaseSysCache(), SearchSysCache2(), SysCacheGetAttr(), and untransformRelOptions().

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

255 {
256  List *options;
257  HeapTuple tp;
258  Datum datum;
259  bool isnull;
260 
261  tp = SearchSysCache2(ATTNUM,
262  ObjectIdGetDatum(relid),
263  Int16GetDatum(attnum));
264  if (!HeapTupleIsValid(tp))
265  elog(ERROR, "cache lookup failed for attribute %d of relation %u",
266  attnum, relid);
267  datum = SysCacheGetAttr(ATTNUM,
268  tp,
270  &isnull);
271  if (isnull)
272  options = NIL;
273  else
274  options = untransformRelOptions(datum);
275 
276  ReleaseSysCache(tp);
277 
278  return options;
279 }
#define NIL
Definition: pg_list.h:69
#define Int16GetDatum(X)
Definition: postgres.h:457
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
static char ** options
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
List * untransformRelOptions(Datum options)
Definition: reloptions.c:907
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1123
#define Anum_pg_attribute_attfdwoptions
Definition: pg_attribute.h:216
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
ForeignDataWrapper* GetForeignDataWrapper ( Oid  fdwid)

Definition at line 35 of file foreign.c.

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

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

36 {
38  ForeignDataWrapper *fdw;
39  Datum datum;
40  HeapTuple tp;
41  bool isnull;
42 
44 
45  if (!HeapTupleIsValid(tp))
46  elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);
47 
49 
50  fdw = (ForeignDataWrapper *) palloc(sizeof(ForeignDataWrapper));
51  fdw->fdwid = fdwid;
52  fdw->owner = fdwform->fdwowner;
53  fdw->fdwname = pstrdup(NameStr(fdwform->fdwname));
54  fdw->fdwhandler = fdwform->fdwhandler;
55  fdw->fdwvalidator = fdwform->fdwvalidator;
56 
57  /* Extract the fdwoptions */
59  tp,
61  &isnull);
62  if (isnull)
63  fdw->options = NIL;
64  else
65  fdw->options = untransformRelOptions(datum);
66 
67  ReleaseSysCache(tp);
68 
69  return fdw;
70 }
#define NIL
Definition: pg_list.h:69
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * fdwname
Definition: foreign.h:39
char * pstrdup(const char *in)
Definition: mcxt.c:1076
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
List * options
Definition: foreign.h:42
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
List * untransformRelOptions(Datum options)
Definition: reloptions.c:907
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_foreign_data_wrapper * Form_pg_foreign_data_wrapper
void * palloc(Size size)
Definition: mcxt.c:848
#define NameStr(name)
Definition: c.h:493
#define elog
Definition: elog.h:219
#define Anum_pg_foreign_data_wrapper_fdwoptions
ForeignDataWrapper* GetForeignDataWrapperByName ( const char *  name,
bool  missing_ok 
)

Definition at line 78 of file foreign.c.

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

Referenced by CreateForeignDataWrapper(), and CreateForeignServer().

79 {
80  Oid fdwId = get_foreign_data_wrapper_oid(fdwname, missing_ok);
81 
82  if (!OidIsValid(fdwId))
83  return NULL;
84 
85  return GetForeignDataWrapper(fdwId);
86 }
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:659
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
ForeignServer* GetForeignServer ( Oid  serverid)

Definition at line 93 of file foreign.c.

References Anum_pg_foreign_server_srvoptions, Anum_pg_foreign_server_srvtype, Anum_pg_foreign_server_srvversion, elog, ERROR, ForeignServer::fdwid, FOREIGNSERVEROID, 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 ATExecAlterColumnGenericOptions(), ATExecGenericOptions(), fileGetOptions(), GetConnection(), GetForeignServerByName(), getObjectDescription(), getObjectIdentityParts(), pgfdw_reject_incomplete_xact_state_change(), postgresAcquireSampleRowsFunc(), postgresGetForeignRelSize(), postgresImportForeignSchema(), and postgresIsForeignRelUpdatable().

94 {
95  Form_pg_foreign_server serverform;
96  ForeignServer *server;
97  HeapTuple tp;
98  Datum datum;
99  bool isnull;
100 
102 
103  if (!HeapTupleIsValid(tp))
104  elog(ERROR, "cache lookup failed for foreign server %u", serverid);
105 
106  serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
107 
108  server = (ForeignServer *) palloc(sizeof(ForeignServer));
109  server->serverid = serverid;
110  server->servername = pstrdup(NameStr(serverform->srvname));
111  server->owner = serverform->srvowner;
112  server->fdwid = serverform->srvfdw;
113 
114  /* Extract server type */
116  tp,
118  &isnull);
119  server->servertype = isnull ? NULL : TextDatumGetCString(datum);
120 
121  /* Extract server version */
123  tp,
125  &isnull);
126  server->serverversion = isnull ? NULL : TextDatumGetCString(datum);
127 
128  /* Extract the srvoptions */
130  tp,
132  &isnull);
133  if (isnull)
134  server->options = NIL;
135  else
136  server->options = untransformRelOptions(datum);
137 
138  ReleaseSysCache(tp);
139 
140  return server;
141 }
#define NIL
Definition: pg_list.h:69
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define Anum_pg_foreign_server_srvversion
char * pstrdup(const char *in)
Definition: mcxt.c:1076
char * serverversion
Definition: foreign.h:52
char * servertype
Definition: foreign.h:51
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
#define TextDatumGetCString(d)
Definition: builtins.h:92
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
List * untransformRelOptions(Datum options)
Definition: reloptions.c:907
FormData_pg_foreign_server * Form_pg_foreign_server
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Anum_pg_foreign_server_srvtype
void * palloc(Size size)
Definition: mcxt.c:848
char * servername
Definition: foreign.h:50
#define NameStr(name)
Definition: c.h:493
#define elog
Definition: elog.h:219
#define Anum_pg_foreign_server_srvoptions
List * options
Definition: foreign.h:53
Oid serverid
Definition: foreign.h:47
ForeignServer* GetForeignServerByName ( const char *  name,
bool  missing_ok 
)

Definition at line 148 of file foreign.c.

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

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

149 {
150  Oid serverid = get_foreign_server_oid(srvname, missing_ok);
151 
152  if (!OidIsValid(serverid))
153  return NULL;
154 
155  return GetForeignServer(serverid);
156 }
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:93
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:680
ForeignTable* GetForeignTable ( Oid  relid)

Definition at line 216 of file foreign.c.

References Anum_pg_foreign_table_ftoptions, elog, ERROR, FOREIGNTABLEREL, GETSTRUCT, HeapTupleIsValid, NIL, ObjectIdGetDatum, ForeignTable::options, palloc(), ReleaseSysCache(), ForeignTable::relid, SearchSysCache1(), ForeignTable::serverid, SysCacheGetAttr(), and untransformRelOptions().

Referenced by check_selective_binary_conversion(), deparseRelation(), fileGetOptions(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignModify(), postgresBeginForeignScan(), postgresGetForeignRelSize(), and postgresIsForeignRelUpdatable().

217 {
218  Form_pg_foreign_table tableform;
219  ForeignTable *ft;
220  HeapTuple tp;
221  Datum datum;
222  bool isnull;
223 
225  if (!HeapTupleIsValid(tp))
226  elog(ERROR, "cache lookup failed for foreign table %u", relid);
227  tableform = (Form_pg_foreign_table) GETSTRUCT(tp);
228 
229  ft = (ForeignTable *) palloc(sizeof(ForeignTable));
230  ft->relid = relid;
231  ft->serverid = tableform->ftserver;
232 
233  /* Extract the ftoptions */
235  tp,
237  &isnull);
238  if (isnull)
239  ft->options = NIL;
240  else
241  ft->options = untransformRelOptions(datum);
242 
243  ReleaseSysCache(tp);
244 
245  return ft;
246 }
#define NIL
Definition: pg_list.h:69
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
FormData_pg_foreign_table * Form_pg_foreign_table
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
Oid relid
Definition: foreign.h:66
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
#define Anum_pg_foreign_table_ftoptions
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
List * untransformRelOptions(Datum options)
Definition: reloptions.c:907
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
Oid serverid
Definition: foreign.h:67
List * options
Definition: foreign.h:68
void * palloc(Size size)
Definition: mcxt.c:848
#define elog
Definition: elog.h:219
UserMapping* GetUserMapping ( Oid  userid,
Oid  serverid 
)

Definition at line 166 of file foreign.c.

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

Referenced by get_connect_string(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignModify(), postgresBeginForeignScan(), postgresGetForeignRelSize(), and postgresImportForeignSchema().

167 {
168  Datum datum;
169  HeapTuple tp;
170  bool isnull;
171  UserMapping *um;
172 
173  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
174  ObjectIdGetDatum(userid),
175  ObjectIdGetDatum(serverid));
176 
177  if (!HeapTupleIsValid(tp))
178  {
179  /* Not found for the specific user -- try PUBLIC */
180  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
182  ObjectIdGetDatum(serverid));
183  }
184 
185  if (!HeapTupleIsValid(tp))
186  ereport(ERROR,
187  (errcode(ERRCODE_UNDEFINED_OBJECT),
188  errmsg("user mapping not found for \"%s\"",
189  MappingUserName(userid))));
190 
191  um = (UserMapping *) palloc(sizeof(UserMapping));
192  um->umid = HeapTupleGetOid(tp);
193  um->userid = userid;
194  um->serverid = serverid;
195 
196  /* Extract the umoptions */
197  datum = SysCacheGetAttr(USERMAPPINGUSERSERVER,
198  tp,
200  &isnull);
201  if (isnull)
202  um->options = NIL;
203  else
204  um->options = untransformRelOptions(datum);
205 
206  ReleaseSysCache(tp);
207 
208  return um;
209 }
Oid umid
Definition: foreign.h:58
#define NIL
Definition: pg_list.h:69
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid userid
Definition: foreign.h:59
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define Anum_pg_user_mapping_umoptions
List * options
Definition: foreign.h:61
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
List * untransformRelOptions(Datum options)
Definition: reloptions.c:907
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
Oid serverid
Definition: foreign.h:60
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1123
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
#define MappingUserName(userid)
Definition: foreign.h:20