PostgreSQL Source Code  git master
foreign.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * foreign.h
4  * support for foreign-data wrappers, servers and user mappings.
5  *
6  *
7  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
8  *
9  * src/include/foreign/foreign.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef FOREIGN_H
14 #define FOREIGN_H
15 
16 #include "nodes/parsenodes.h"
17 
18 
19 /* Helper for obtaining username for user mapping */
20 #define MappingUserName(userid) \
21  (OidIsValid(userid) ? GetUserNameFromId(userid, false) : "public")
22 
23 
24 typedef struct ForeignDataWrapper
25 {
26  Oid fdwid; /* FDW Oid */
27  Oid owner; /* FDW owner user Oid */
28  char *fdwname; /* Name of the FDW */
29  Oid fdwhandler; /* Oid of handler function, or 0 */
30  Oid fdwvalidator; /* Oid of validator function, or 0 */
31  List *options; /* fdwoptions as DefElem list */
33 
34 typedef struct ForeignServer
35 {
36  Oid serverid; /* server Oid */
37  Oid fdwid; /* foreign-data wrapper */
38  Oid owner; /* server owner user Oid */
39  char *servername; /* name of the server */
40  char *servertype; /* server type, optional */
41  char *serverversion; /* server version, optional */
42  List *options; /* srvoptions as DefElem list */
44 
45 typedef struct UserMapping
46 {
47  Oid umid; /* Oid of user mapping */
48  Oid userid; /* local user Oid */
49  Oid serverid; /* server Oid */
50  List *options; /* useoptions as DefElem list */
52 
53 typedef struct ForeignTable
54 {
55  Oid relid; /* relation Oid */
56  Oid serverid; /* server Oid */
57  List *options; /* ftoptions as DefElem list */
59 
60 /* Flags for GetForeignServerExtended */
61 #define FSV_MISSING_OK 0x01
62 
63 /* Flags for GetForeignDataWrapperExtended */
64 #define FDW_MISSING_OK 0x01
65 
66 
67 extern ForeignServer *GetForeignServer(Oid serverid);
69  bits16 flags);
70 extern ForeignServer *GetForeignServerByName(const char *srvname,
71  bool missing_ok);
72 extern UserMapping *GetUserMapping(Oid userid, Oid serverid);
75  bits16 flags);
76 extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *fdwname,
77  bool missing_ok);
78 extern ForeignTable *GetForeignTable(Oid relid);
79 
81 
82 extern Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok);
83 extern Oid get_foreign_server_oid(const char *servername, bool missing_ok);
84 
85 #endif /* FOREIGN_H */
int16 AttrNumber
Definition: attnum.h:21
uint16 bits16
Definition: c.h:450
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:37
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:123
struct ForeignServer ForeignServer
ForeignTable * GetForeignTable(Oid relid)
Definition: foreign.c:250
struct ForeignTable ForeignTable
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:690
UserMapping * GetUserMapping(Oid userid, Oid serverid)
Definition: foreign.c:200
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
Definition: foreign.c:288
struct ForeignDataWrapper ForeignDataWrapper
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:49
ForeignDataWrapper * GetForeignDataWrapperByName(const char *fdwname, bool missing_ok)
Definition: foreign.c:96
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:111
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition: foreign.c:182
struct UserMapping UserMapping
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:667
int16 attnum
Definition: pg_attribute.h:83
unsigned int Oid
Definition: postgres_ext.h:31
char * fdwname
Definition: foreign.h:28
List * options
Definition: foreign.h:31
List * options
Definition: foreign.h:42
char * serverversion
Definition: foreign.h:41
char * servername
Definition: foreign.h:39
Oid serverid
Definition: foreign.h:36
char * servertype
Definition: foreign.h:40
Oid relid
Definition: foreign.h:55
List * options
Definition: foreign.h:57
Oid serverid
Definition: foreign.h:56
Definition: pg_list.h:52
Oid userid
Definition: foreign.h:48
Oid umid
Definition: foreign.h:47
Oid serverid
Definition: foreign.h:49
List * options
Definition: foreign.h:50