guc GetConfigOptionByNum and tablefunc API - minor changes - Mailing list pgsql-patches
From | Joe Conway |
---|---|
Subject | guc GetConfigOptionByNum and tablefunc API - minor changes |
Date | |
Msg-id | 3D3A2CB6.9080102@joeconway.com Whole thread Raw |
Responses |
Re: guc GetConfigOptionByNum and tablefunc API - minor changes
|
List | pgsql-patches |
Tom Lane wrote: > One thing that possibly needs discussion is the handling of > GUC_NO_SHOW_ALL. I moved that test into the SHOW ALL code because > the intended behavior is for the marked variable to not be in the > SHOW ALL output at all, rather than be there with a null value as > your patch originally behaved. Now that was fine for SHOW ALL because > it can examine the config record directly anyway, but what of external > callers of GetConfigOptionByNum? There aren't any right now so I'm > kind of speculating in a vacuum about what they'll want. But it seems > possible that they will want to be able to discover whether the var is > marked NO_SHOW_ALL or not. Maybe that should be an additional return > variable from GetConfigOptionByNum, along the lines of > > GetConfigOptionByNum(..., bool *noshow) > { > if (noshow) > *noshow = (conf->flags & GUC_NO_SHOW_ALL) ? true : false; > } > > Any thoughts? > > Oh btw: an Assert() verifying that the arg of GetConfigOptionByNum is > in range wouldn't be out of place, I think. Here are two patches. The guc_and_tablefunc patch addresses the two changes mentioned above, and also adds a new function to the tablefunc API. The tablefunc API change adds the following function: * Oid foidGetTypeId(Oid foid) - Get a function's typeid given the * function Oid. Use this together with TypeGetTupleDesc() to get a * TupleDesc which is derived from the function's declared return type. In the next post I'll send the contrib/tablefunc patch, which illustrates the usage of this new function. Also attached is a doc patch for this change. The doc patch also adds a function that I failed to document previously. If there are no objections, please apply. Thanks, Joe Index: doc/src/sgml/xfunc.sgml =================================================================== RCS file: /opt/src/cvs/pgsql/doc/src/sgml/xfunc.sgml,v retrieving revision 1.53 diff -c -r1.53 xfunc.sgml *** doc/src/sgml/xfunc.sgml 18 Jul 2002 04:47:17 -0000 1.53 --- doc/src/sgml/xfunc.sgml 21 Jul 2002 01:51:10 -0000 *************** *** 1557,1562 **** --- 1557,1580 ---- </para> <para> + In order to get an attribute "in" function and typelem value given the + typeid, use + <programlisting> + void get_type_metadata(Oid typeid, Oid *attinfuncid, Oid *attelem) + </programlisting> + </para> + + <para> + You can use this next function together with TypeGetTupleDesc(), to get + a TupleDesc which is derived from the function's declared return type. + <programlisting> + Oid foidGetTypeId(Oid foid) + </programlisting> + This allows you to avoid hard-coding the return data type name into your + function. + </para> + + <para> Finally, in order to return a tuple using the SRF portion of the API (described below), the tuple must be converted into a Datum. Use <programlisting> Index: src/backend/utils/fmgr/funcapi.c =================================================================== RCS file: /opt/src/cvs/pgsql/src/backend/utils/fmgr/funcapi.c,v retrieving revision 1.2 diff -c -r1.2 funcapi.c *** src/backend/utils/fmgr/funcapi.c 18 Jul 2002 04:40:30 -0000 1.2 --- src/backend/utils/fmgr/funcapi.c 21 Jul 2002 01:04:51 -0000 *************** *** 10,15 **** --- 10,16 ---- */ #include "funcapi.h" + #include "catalog/pg_proc.h" #include "catalog/pg_type.h" #include "utils/syscache.h" *************** *** 136,139 **** --- 137,168 ---- *attelem = typtup->typelem; ReleaseSysCache(typeTuple); + } + + /* + * get the typeid for a function given the function Oid + */ + Oid + foidGetTypeId(Oid foid) + { + HeapTuple procedureTuple; + Form_pg_proc procedureStruct; + Oid functypeid; + + /* get the procedure tuple corresponding to the given function Oid */ + procedureTuple = SearchSysCache(PROCOID, + ObjectIdGetDatum(foid), + 0, 0, 0); + if (!HeapTupleIsValid(procedureTuple)) + elog(ERROR, "foidGetTypeId: Cache lookup failed for procedure %u", + foid); + + procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple); + + functypeid = procedureStruct->prorettype; + + /* clean up */ + ReleaseSysCache(procedureTuple); + + return functypeid; } Index: src/backend/utils/misc/guc.c =================================================================== RCS file: /opt/src/cvs/pgsql/src/backend/utils/misc/guc.c,v retrieving revision 1.75 diff -c -r1.75 guc.c *** src/backend/utils/misc/guc.c 20 Jul 2002 15:12:55 -0000 1.75 --- src/backend/utils/misc/guc.c 21 Jul 2002 01:36:12 -0000 *************** *** 2347,2358 **** * form of name. Return value is palloc'd. */ char * ! GetConfigOptionByNum(int varnum, const char **varname) { ! struct config_generic *conf = guc_variables[varnum]; if (varname) *varname = conf->name; return _ShowOption(conf); } --- 2347,2366 ---- * form of name. Return value is palloc'd. */ char * ! GetConfigOptionByNum(int varnum, const char **varname, bool *noshow) { ! struct config_generic *conf; ! ! /* check requested variable number valid */ ! Assert((varnum >= 0) && (varnum < num_guc_variables)); ! ! conf = guc_variables[varnum]; if (varname) *varname = conf->name; + + if (noshow) + *noshow = (conf->flags & GUC_NO_SHOW_ALL) ? true : false; return _ShowOption(conf); } Index: src/include/funcapi.h =================================================================== RCS file: /opt/src/cvs/pgsql/src/include/funcapi.h,v retrieving revision 1.3 diff -c -r1.3 funcapi.h *** src/include/funcapi.h 18 Jul 2002 04:40:30 -0000 1.3 --- src/include/funcapi.h 21 Jul 2002 01:02:26 -0000 *************** *** 139,144 **** --- 139,149 ---- * HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values) - * build a HeapTuple given user data in C string form. values is an array * of C strings, one for each attribute of the return tuple. + * void get_type_metadata(Oid typeid, Oid *attinfuncid, Oid *attelem) - Get + * an attribute "in" function and typelem value given the typeid. + * Oid foidGetTypeId(Oid foid) - Get a function's typeid given the function + * Oid. Use this together with TypeGetTupleDesc() to get a TupleDesc + * which is derived from the function's declared return type. * * Macro declarations: * TupleGetDatum(TupleTableSlot *slot, HeapTuple tuple) - get a Datum *************** *** 156,161 **** --- 161,167 ---- /* from funcapi.c */ extern void get_type_metadata(Oid typeid, Oid *attinfuncid, Oid *attelem); + extern Oid foidGetTypeId(Oid foid); #define TupleGetDatum(_slot, _tuple) \ PointerGetDatum(ExecStoreTuple(_tuple, _slot, InvalidBuffer, true)) Index: src/include/utils/guc.h =================================================================== RCS file: /opt/src/cvs/pgsql/src/include/utils/guc.h,v retrieving revision 1.19 diff -c -r1.19 guc.h *** src/include/utils/guc.h 20 Jul 2002 15:12:56 -0000 1.19 --- src/include/utils/guc.h 20 Jul 2002 23:44:52 -0000 *************** *** 87,93 **** extern void ShowGUCConfigOption(const char *name); extern void ShowAllGUCConfig(void); extern char *GetConfigOptionByName(const char *name, const char **varname); ! extern char *GetConfigOptionByNum(int varnum, const char **varname); extern int GetNumConfigOptions(void); extern void SetPGVariable(const char *name, List *args, bool is_local); --- 87,93 ---- extern void ShowGUCConfigOption(const char *name); extern void ShowAllGUCConfig(void); extern char *GetConfigOptionByName(const char *name, const char **varname); ! extern char *GetConfigOptionByNum(int varnum, const char **varname, bool *noshow); extern int GetNumConfigOptions(void); extern void SetPGVariable(const char *name, List *args, bool is_local);
pgsql-patches by date: