show() function - Mailing list pgsql-patches
| From | Joe Conway |
|---|---|
| Subject | show() function |
| Date | |
| Msg-id | 3D13EC54.4070304@joeconway.com Whole thread Raw |
| Responses |
Re: show() function
Re: show() function |
| List | pgsql-patches |
Attached is a patch which (I believe) addresses Peter's concerns with
respect to the previous showguc patch. In this patch, contrib/showguc is
gone, the term GUC is not exposed to user space, and a builtin
show('gucvarname') function returning a single scalar value has been
added, e.g.:
test=# select show('wal_sync_method');
show
-----------
fdatasync
(1 row)
I will work up new table function API examples per Peter's suggestion,
and finish the C API documentation (hopefully before the weekend is
over) in a separate patch.
If there are no further objections, please apply.
Thanks,
Joe
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /opt/src/cvs/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.70
diff -c -r1.70 guc.c
*** src/backend/utils/misc/guc.c 16 Jun 2002 00:09:12 -0000 1.70
--- src/backend/utils/misc/guc.c 22 Jun 2002 02:33:37 -0000
***************
*** 819,825 ****
static int guc_var_compare(const void *a, const void *b);
! static void _ShowOption(struct config_generic *record);
/*
--- 819,825 ----
static int guc_var_compare(const void *a, const void *b);
! static char *_ShowOption(struct config_generic *record);
/*
***************
*** 2199,2210 ****
ShowGUCConfigOption(const char *name)
{
struct config_generic *record;
record = find_option(name);
if (record == NULL)
elog(ERROR, "Option '%s' is not recognized", name);
! _ShowOption(record);
}
/*
--- 2199,2216 ----
ShowGUCConfigOption(const char *name)
{
struct config_generic *record;
+ char *val;
record = find_option(name);
if (record == NULL)
elog(ERROR, "Option '%s' is not recognized", name);
! val = _ShowOption(record);
! if(val != NULL)
! {
! elog(INFO, "%s is %s", record->name, val);
! pfree(val);
! }
}
/*
***************
*** 2214,2234 ****
ShowAllGUCConfig(void)
{
int i;
for (i = 0; i < num_guc_variables; i++)
{
struct config_generic *conf = guc_variables[i];
if ((conf->flags & GUC_NO_SHOW_ALL) == 0)
! _ShowOption(conf);
}
}
! static void
_ShowOption(struct config_generic *record)
{
char buffer[256];
const char *val;
switch (record->vartype)
{
--- 2220,2314 ----
ShowAllGUCConfig(void)
{
int i;
+ char *val;
for (i = 0; i < num_guc_variables; i++)
{
struct config_generic *conf = guc_variables[i];
if ((conf->flags & GUC_NO_SHOW_ALL) == 0)
! {
! val = _ShowOption(conf);
! if(val != NULL)
! {
! elog(INFO, "%s is %s", conf->name, val);
! pfree(val);
! }
! }
}
}
! /*
! * Return GUC variable value by name
! */
! char *
! GetConfigOptionByName(const char *name)
! {
! struct config_generic *record;
!
! record = find_option(name);
! if (record == NULL)
! elog(ERROR, "Option '%s' is not recognized", name);
!
! return _ShowOption(record);
! }
!
! /*
! * Return GUC variable value and set varname for a specific
! * variable by number.
! */
! char *
! GetConfigOptionByNum(int varnum, char **varname)
! {
! struct config_generic *conf = guc_variables[varnum];
!
! *varname = pstrdup(conf->name);
!
! if ((conf->flags & GUC_NO_SHOW_ALL) == 0)
! return _ShowOption(conf);
! else
! return NULL;
! }
!
! /*
! * Return the total number of GUC variables
! */
! int
! GetNumConfigOptions(void)
! {
! return num_guc_variables;
! }
!
! /*
! * show_config_by_name - equiv to SHOW X command but implemented as
! * a function.
! */
! Datum
! show_config_by_name(PG_FUNCTION_ARGS)
! {
! char *varname;
! char *varval;
! text *result_text;
!
! /* Get the GUC variable name */
! varname = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(0))));
!
! /* Get the value */
! varval = GetConfigOptionByName(varname);
!
! /* Convert to text */
! result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(varval)));
!
! /* return it */
! PG_RETURN_TEXT_P(result_text);
! }
!
! static char *
_ShowOption(struct config_generic *record)
{
char buffer[256];
const char *val;
+ char *retval;
switch (record->vartype)
{
***************
*** 2292,2298 ****
break;
}
! elog(INFO, "%s is %s", record->name, val);
}
--- 2372,2380 ----
break;
}
! retval = pstrdup(val);
!
! return retval;
}
Index: src/include/catalog/catversion.h
===================================================================
RCS file: /opt/src/cvs/pgsql/src/include/catalog/catversion.h,v
retrieving revision 1.136
diff -c -r1.136 catversion.h
*** src/include/catalog/catversion.h 20 Jun 2002 20:29:43 -0000 1.136
--- src/include/catalog/catversion.h 22 Jun 2002 02:35:42 -0000
***************
*** 53,58 ****
*/
/* yyyymmddN */
! #define CATALOG_VERSION_NO 200206151
#endif
--- 53,58 ----
*/
/* yyyymmddN */
! #define CATALOG_VERSION_NO 200206211
#endif
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /opt/src/cvs/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.243
diff -c -r1.243 pg_proc.h
*** src/include/catalog/pg_proc.h 20 Jun 2002 20:29:44 -0000 1.243
--- src/include/catalog/pg_proc.h 22 Jun 2002 02:35:28 -0000
***************
*** 2881,2886 ****
--- 2881,2889 ----
DATA(insert OID = 2074 ( substring PGNSP PGUID 14 f f f t f i 3 25 "25 25 25" 100 0 0 100 "select
substring($1,like_escape($2, $3))" - _null_ ));
DESCR("substitutes regular expression with escape argument");
+ DATA(insert OID = 2099 ( show PGNSP PGUID 12 f f f t f s 1 25 "25" 100 0 0 100 show_config_by_name -
_null_));
+ DESCR("SHOW X as a function");
+
/* Aggregates (moved here from pg_aggregate for 7.3) */
DATA(insert OID = 2100 ( avg PGNSP PGUID 12 t f f f f i 1 1700 "20" 100 0 0 100 aggregate_dummy -
_null_));
Index: src/include/utils/builtins.h
===================================================================
RCS file: /opt/src/cvs/pgsql/src/include/utils/builtins.h,v
retrieving revision 1.186
diff -c -r1.186 builtins.h
*** src/include/utils/builtins.h 20 Jun 2002 20:29:52 -0000 1.186
--- src/include/utils/builtins.h 22 Jun 2002 02:33:23 -0000
***************
*** 633,636 ****
--- 633,639 ----
extern Datum quote_ident(PG_FUNCTION_ARGS);
extern Datum quote_literal(PG_FUNCTION_ARGS);
+ /* guc.c */
+ extern Datum show_config_by_name(PG_FUNCTION_ARGS);
+
#endif /* BUILTINS_H */
Index: src/include/utils/guc.h
===================================================================
RCS file: /opt/src/cvs/pgsql/src/include/utils/guc.h,v
retrieving revision 1.17
diff -c -r1.17 guc.h
*** src/include/utils/guc.h 17 May 2002 01:19:19 -0000 1.17
--- src/include/utils/guc.h 22 Jun 2002 02:23:14 -0000
***************
*** 86,91 ****
--- 86,94 ----
bool isLocal, bool DoIt);
extern void ShowGUCConfigOption(const char *name);
extern void ShowAllGUCConfig(void);
+ extern char *GetConfigOptionByName(const char *name);
+ extern char *GetConfigOptionByNum(int varnum, char **varname);
+ extern int GetNumConfigOptions(void);
extern void SetPGVariable(const char *name, List *args, bool is_local);
extern void GetPGVariable(const char *name);
pgsql-patches by date: