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-2022, 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 "catalog/pg_type.h"
18 #include "common/config_info.h"
19 #include "funcapi.h"
20 #include "miscadmin.h"
21 #include "port.h"
22 #include "utils/builtins.h"
23 
24 Datum
26 {
27  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
28  ConfigData *configdata;
29  size_t configdata_len;
30  int i = 0;
31 
32  /* initialize our tuplestore */
33  InitMaterializedSRF(fcinfo, 0);
34 
35  configdata = get_configdata(my_exec_path, &configdata_len);
36  for (i = 0; i < configdata_len; i++)
37  {
38  Datum values[2];
39  bool nulls[2];
40 
41  memset(values, 0, sizeof(values));
42  memset(nulls, 0, sizeof(nulls));
43 
44  values[0] = CStringGetTextDatum(configdata[i].name);
45  values[1] = CStringGetTextDatum(configdata[i].setting);
46 
47  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
48  }
49 
50  return (Datum) 0;
51 }
Datum pg_config(PG_FUNCTION_ARGS)
Definition: pg_config.c:25
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
ConfigData * get_configdata(const char *my_exec_path, size_t *configdata_len)
Definition: config_info.c:33
const char * name
Definition: encode.c:561
#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:76
int i
Definition: isn.c:73
uintptr_t Datum
Definition: postgres.h:412
TupleDesc setDesc
Definition: execnodes.h:332
Tuplestorestate * setResult
Definition: execnodes.h:331
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750