PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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 /*
25  * Generic option types for validation.
26  * NB! These are treated as flags, so use only powers of two here.
27  */
28 typedef enum
29 {
30  ServerOpt = 1, /* options applicable to SERVER */
31  UserMappingOpt = 2, /* options for USER MAPPING */
32  FdwOpt = 4 /* options for FOREIGN DATA WRAPPER */
34 
35 typedef struct ForeignDataWrapper
36 {
37  Oid fdwid; /* FDW Oid */
38  Oid owner; /* FDW owner user Oid */
39  char *fdwname; /* Name of the FDW */
40  Oid fdwhandler; /* Oid of handler function, or 0 */
41  Oid fdwvalidator; /* Oid of validator function, or 0 */
42  List *options; /* fdwoptions as DefElem list */
44 
45 typedef struct ForeignServer
46 {
47  Oid serverid; /* server Oid */
48  Oid fdwid; /* foreign-data wrapper */
49  Oid owner; /* server owner user Oid */
50  char *servername; /* name of the server */
51  char *servertype; /* server type, optional */
52  char *serverversion; /* server version, optional */
53  List *options; /* srvoptions as DefElem list */
55 
56 typedef struct UserMapping
57 {
58  Oid umid; /* Oid of user mapping */
59  Oid userid; /* local user Oid */
60  Oid serverid; /* server Oid */
61  List *options; /* useoptions as DefElem list */
62 } UserMapping;
63 
64 typedef struct ForeignTable
65 {
66  Oid relid; /* relation Oid */
67  Oid serverid; /* server Oid */
68  List *options; /* ftoptions as DefElem list */
69 } ForeignTable;
70 
71 
72 extern ForeignServer *GetForeignServer(Oid serverid);
73 extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok);
74 extern UserMapping *GetUserMapping(Oid userid, Oid serverid);
77  bool missing_ok);
78 extern ForeignTable *GetForeignTable(Oid relid);
79 
80 extern List *GetForeignColumnOptions(Oid relid, AttrNumber attnum);
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 */
ForeignTable * GetForeignTable(Oid relid)
Definition: foreign.c:216
Oid umid
Definition: foreign.h:58
Definition: foreign.h:32
GenericOptionFlags
Definition: foreign.h:28
char * fdwname
Definition: foreign.h:39
struct ForeignTable ForeignTable
char * serverversion
Definition: foreign.h:52
unsigned int Oid
Definition: postgres_ext.h:31
Oid userid
Definition: foreign.h:59
char * servertype
Definition: foreign.h:51
ForeignDataWrapper * GetForeignDataWrapperByName(const char *name, bool missing_ok)
Definition: foreign.c:78
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:93
struct ForeignDataWrapper ForeignDataWrapper
Oid relid
Definition: foreign.h:66
UserMapping * GetUserMapping(Oid userid, Oid serverid)
Definition: foreign.c:166
List * options
Definition: foreign.h:61
List * options
Definition: foreign.h:42
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:659
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
Definition: foreign.c:254
ForeignServer * GetForeignServerByName(const char *name, bool missing_ok)
Definition: foreign.c:148
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:680
Oid serverid
Definition: foreign.h:67
Oid serverid
Definition: foreign.h:60
const char * name
Definition: encode.c:521
List * options
Definition: foreign.h:68
char * servername
Definition: foreign.h:50
Definition: pg_list.h:45
List * options
Definition: foreign.h:53
struct ForeignServer ForeignServer
int16 AttrNumber
Definition: attnum.h:21
Oid serverid
Definition: foreign.h:47
struct UserMapping UserMapping