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 /contrib/file_fdw | |
| 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 'contrib/file_fdw')
| -rw-r--r-- | contrib/file_fdw/file_fdw.c | 49 |
1 files changed, 12 insertions, 37 deletions
diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index c2faa6235e7..29f203c6f10 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -27,7 +27,6 @@ #include "optimizer/cost.h" #include "optimizer/pathnode.h" #include "utils/rel.h" -#include "utils/syscache.h" PG_MODULE_MAGIC; @@ -346,54 +345,30 @@ get_file_fdw_attribute_options(Oid relid) /* Retrieve FDW options for all user-defined attributes. */ for (attnum = 1; attnum <= natts; attnum++) { - HeapTuple tuple; - Form_pg_attribute attr; - Datum datum; - bool isnull; + Form_pg_attribute attr = tupleDesc->attrs[attnum - 1]; + List *options; + ListCell *lc; /* Skip dropped attributes. */ - if (tupleDesc->attrs[attnum - 1]->attisdropped) + if (attr->attisdropped) continue; - /* - * We need the whole pg_attribute tuple not just what is in the - * tupleDesc, so must do a catalog lookup. - */ - tuple = SearchSysCache2(ATTNUM, - RelationGetRelid(rel), - Int16GetDatum(attnum)); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "cache lookup failed for attribute %d of relation %u", - attnum, RelationGetRelid(rel)); - attr = (Form_pg_attribute) GETSTRUCT(tuple); - - datum = SysCacheGetAttr(ATTNUM, - tuple, - Anum_pg_attribute_attfdwoptions, - &isnull); - if (!isnull) + options = GetForeignColumnOptions(relid, attnum); + foreach(lc, options) { - List *options = untransformRelOptions(datum); - ListCell *lc; + DefElem *def = (DefElem *) lfirst(lc); - foreach(lc, options) + if (strcmp(def->defname, "force_not_null") == 0) { - DefElem *def = (DefElem *) lfirst(lc); - - if (strcmp(def->defname, "force_not_null") == 0) + if (defGetBoolean(def)) { - if (defGetBoolean(def)) - { - char *attname = pstrdup(NameStr(attr->attname)); + char *attname = pstrdup(NameStr(attr->attname)); - fnncolumns = lappend(fnncolumns, makeString(attname)); - } + fnncolumns = lappend(fnncolumns, makeString(attname)); } - /* maybe in future handle other options here */ } + /* maybe in future handle other options here */ } - - ReleaseSysCache(tuple); } heap_close(rel, AccessShareLock); |
