PostgreSQL Source Code  git master
pg_config.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_config.c
4  * Expose same output as pg_config except as an SRF
5  *
6  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/backend/utils/misc/pg_config.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres.h"
16 
17 #include "common/config_info.h"
18 #include "funcapi.h"
19 #include "miscadmin.h"
20 #include "utils/builtins.h"
21 
22 Datum
24 {
25  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
26  ConfigData *configdata;
27  size_t configdata_len;
28  int i = 0;
29 
30  /* initialize our tuplestore */
31  InitMaterializedSRF(fcinfo, 0);
32 
33  configdata = get_configdata(my_exec_path, &configdata_len);
34  for (i = 0; i < configdata_len; i++)
35  {
36  Datum values[2];
37  bool nulls[2];
38 
39  memset(values, 0, sizeof(values));
40  memset(nulls, 0, sizeof(nulls));
41 
42  values[0] = CStringGetTextDatum(configdata[i].name);
43  values[1] = CStringGetTextDatum(configdata[i].setting);
44 
45  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
46  }
47 
48  return (Datum) 0;
49 }
Datum pg_config(PG_FUNCTION_ARGS)
Definition: pg_config.c:23
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define CStringGetTextDatum(s)
Definition: builtins.h:97
ConfigData * get_configdata(const char *my_exec_path, size_t *configdata_len)
Definition: config_info.c:33
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
char my_exec_path[MAXPGPATH]
Definition: globals.c:80
int i
Definition: isn.c:72
uintptr_t Datum
Definition: postgres.h:64
TupleDesc setDesc
Definition: execnodes.h:343
Tuplestorestate * setResult
Definition: execnodes.h:342
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition: tuplestore.c:784
const char * name