diff options
| author | Tom Lane | 2012-03-07 23:20:58 +0000 |
|---|---|---|
| committer | Tom Lane | 2012-03-07 23:20:58 +0000 |
| commit | 9088d1b96504717fd589ff7eeacc96b6d1c08ead (patch) | |
| tree | 3e2614521673ddfb0a1f7c6a9696053157a4b915 /src/backend/foreign/foreign.c | |
| parent | cf7026b64b3e56889f8a81194a57221500e23a0f (diff) | |
Add GetForeignColumnOptions() to foreign.c, and add some documentation.
GetForeignColumnOptions provides some abstraction for accessing
column-specific FDW options, on a par with the access functions that were
already provided here for other FDW-related information.
Adjust file_fdw.c to use GetForeignColumnOptions instead of equivalent
hand-rolled code.
In addition, add some SGML documentation for the functions exported by
foreign.c that are meant for use by FDW authors.
(This is the fdw_helper portion of the proposed pgsql_fdw patch.)
Hanada Shigeru, reviewed by KaiGai Kohei
Diffstat (limited to 'src/backend/foreign/foreign.c')
| -rw-r--r-- | src/backend/foreign/foreign.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/backend/foreign/foreign.c b/src/backend/foreign/foreign.c index c4c2a61d5dc..f27b55a66e4 100644 --- a/src/backend/foreign/foreign.c +++ b/src/backend/foreign/foreign.c @@ -28,7 +28,6 @@ extern Datum pg_options_to_table(PG_FUNCTION_ARGS); extern Datum postgresql_fdw_validator(PG_FUNCTION_ARGS); - /* * GetForeignDataWrapper - look up the foreign-data wrapper by OID. */ @@ -71,7 +70,6 @@ GetForeignDataWrapper(Oid fdwid) } - /* * GetForeignDataWrapperByName - look up the foreign-data wrapper * definition by name. @@ -248,6 +246,39 @@ GetForeignTable(Oid relid) /* + * GetForeignColumnOptions - Get attfdwoptions of given relation/attnum + * as list of DefElem. + */ +List * +GetForeignColumnOptions(Oid relid, AttrNumber attnum) +{ + List *options; + HeapTuple tp; + Datum datum; + bool isnull; + + tp = SearchSysCache2(ATTNUM, + ObjectIdGetDatum(relid), + Int16GetDatum(attnum)); + if (!HeapTupleIsValid(tp)) + elog(ERROR, "cache lookup failed for attribute %d of relation %u", + attnum, relid); + datum = SysCacheGetAttr(ATTNUM, + tp, + Anum_pg_attribute_attfdwoptions, + &isnull); + if (isnull) + options = NIL; + else + options = untransformRelOptions(datum); + + ReleaseSysCache(tp); + + return options; +} + + +/* * GetFdwRoutine - call the specified foreign-data wrapper handler routine * to get its FdwRoutine struct. */ @@ -498,6 +529,7 @@ postgresql_fdw_validator(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); } + /* * get_foreign_data_wrapper_oid - given a FDW name, look up the OID * @@ -518,6 +550,7 @@ get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok) return oid; } + /* * get_foreign_server_oid - given a FDW name, look up the OID * |
