PostgreSQL Source Code  git master
describe.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool describeAggregates (const char *pattern, bool verbose, bool showSystem)
 
bool describeAccessMethods (const char *pattern, bool verbose)
 
bool describeTablespaces (const char *pattern, bool verbose)
 
bool describeFunctions (const char *functypes, const char *func_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
 
bool describeTypes (const char *pattern, bool verbose, bool showSystem)
 
bool describeOperators (const char *oper_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
 
bool describeRoles (const char *pattern, bool verbose, bool showSystem)
 
bool listDbRoleSettings (const char *pattern, const char *pattern2)
 
bool permissionsList (const char *pattern)
 
bool listDefaultACLs (const char *pattern)
 
bool objectDescription (const char *pattern, bool showSystem)
 
bool describeTableDetails (const char *pattern, bool verbose, bool showSystem)
 
bool listTSConfigs (const char *pattern, bool verbose)
 
bool listTSParsers (const char *pattern, bool verbose)
 
bool listTSDictionaries (const char *pattern, bool verbose)
 
bool listTSTemplates (const char *pattern, bool verbose)
 
bool listAllDbs (const char *pattern, bool verbose)
 
bool listTables (const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
 
bool listPartitionedTables (const char *reltypes, const char *pattern, bool verbose)
 
bool listDomains (const char *pattern, bool verbose, bool showSystem)
 
bool listConversions (const char *pattern, bool verbose, bool showSystem)
 
bool listCasts (const char *pattern, bool verbose)
 
bool listCollations (const char *pattern, bool verbose, bool showSystem)
 
bool listSchemas (const char *pattern, bool verbose, bool showSystem)
 
bool listForeignDataWrappers (const char *pattern, bool verbose)
 
bool listForeignServers (const char *pattern, bool verbose)
 
bool listUserMappings (const char *pattern, bool verbose)
 
bool listForeignTables (const char *pattern, bool verbose)
 
bool listLanguages (const char *pattern, bool verbose, bool showSystem)
 
bool listExtensions (const char *pattern)
 
bool listExtensionContents (const char *pattern)
 
bool listExtendedStats (const char *pattern)
 
bool listEventTriggers (const char *pattern, bool verbose)
 
bool listPublications (const char *pattern)
 
bool describePublications (const char *pattern)
 
bool describeSubscriptions (const char *pattern, bool verbose)
 
bool listOperatorClasses (const char *access_method_pattern, const char *opclass_pattern, bool verbose)
 
bool listOperatorFamilies (const char *access_method_pattern, const char *opclass_pattern, bool verbose)
 
bool listOpFamilyOperators (const char *accessMethod_pattern, const char *family_pattern, bool verbose)
 
bool listOpFamilyFunctions (const char *access_method_pattern, const char *family_pattern, bool verbose)
 

Function Documentation

◆ describeAccessMethods()

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 150 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

151 {
153  PGresult *res;
154  printQueryOpt myopt = pset.popt;
155  static const bool translate_columns[] = {false, true, false, false};
156 
157  if (pset.sversion < 90600)
158  {
159  char sverbuf[32];
160 
161  pg_log_error("The server (version %s) does not support access methods.",
163  sverbuf, sizeof(sverbuf)));
164  return true;
165  }
166 
167  initPQExpBuffer(&buf);
168 
169  printfPQExpBuffer(&buf,
170  "SELECT amname AS \"%s\",\n"
171  " CASE amtype"
172  " WHEN 'i' THEN '%s'"
173  " WHEN 't' THEN '%s'"
174  " END AS \"%s\"",
175  gettext_noop("Name"),
176  gettext_noop("Index"),
177  gettext_noop("Table"),
178  gettext_noop("Type"));
179 
180  if (verbose)
181  {
182  appendPQExpBuffer(&buf,
183  ",\n amhandler AS \"%s\",\n"
184  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
185  gettext_noop("Handler"),
186  gettext_noop("Description"));
187  }
188 
190  "\nFROM pg_catalog.pg_am\n");
191 
192  processSQLNamePattern(pset.db, &buf, pattern, false, false,
193  NULL, "amname", NULL,
194  NULL);
195 
196  appendPQExpBufferStr(&buf, "ORDER BY 1;");
197 
198  res = PSQLexec(buf.data);
199  termPQExpBuffer(&buf);
200  if (!res)
201  return false;
202 
203  myopt.nullPrint = NULL;
204  myopt.title = _("List of access methods");
205  myopt.translate_header = true;
206  myopt.translate_columns = translate_columns;
207  myopt.n_translate_columns = lengthof(translate_columns);
208 
209  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
210 
211  PQclear(res);
212  return true;
213 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeAggregates()

bool describeAggregates ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 64 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

65 {
67  PGresult *res;
68  printQueryOpt myopt = pset.popt;
69 
70  initPQExpBuffer(&buf);
71 
72  printfPQExpBuffer(&buf,
73  "SELECT n.nspname as \"%s\",\n"
74  " p.proname AS \"%s\",\n"
75  " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n",
76  gettext_noop("Schema"),
77  gettext_noop("Name"),
78  gettext_noop("Result data type"));
79 
80  if (pset.sversion >= 80400)
81  appendPQExpBuffer(&buf,
82  " CASE WHEN p.pronargs = 0\n"
83  " THEN CAST('*' AS pg_catalog.text)\n"
84  " ELSE pg_catalog.pg_get_function_arguments(p.oid)\n"
85  " END AS \"%s\",\n",
86  gettext_noop("Argument data types"));
87  else if (pset.sversion >= 80200)
88  appendPQExpBuffer(&buf,
89  " CASE WHEN p.pronargs = 0\n"
90  " THEN CAST('*' AS pg_catalog.text)\n"
91  " ELSE\n"
92  " pg_catalog.array_to_string(ARRAY(\n"
93  " SELECT\n"
94  " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
95  " FROM\n"
96  " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
97  " ), ', ')\n"
98  " END AS \"%s\",\n",
99  gettext_noop("Argument data types"));
100  else
101  appendPQExpBuffer(&buf,
102  " pg_catalog.format_type(p.proargtypes[0], NULL) AS \"%s\",\n",
103  gettext_noop("Argument data types"));
104 
105  if (pset.sversion >= 110000)
106  appendPQExpBuffer(&buf,
107  " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
108  "FROM pg_catalog.pg_proc p\n"
109  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
110  "WHERE p.prokind = 'a'\n",
111  gettext_noop("Description"));
112  else
113  appendPQExpBuffer(&buf,
114  " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
115  "FROM pg_catalog.pg_proc p\n"
116  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
117  "WHERE p.proisagg\n",
118  gettext_noop("Description"));
119 
120  if (!showSystem && !pattern)
121  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
122  " AND n.nspname <> 'information_schema'\n");
123 
124  processSQLNamePattern(pset.db, &buf, pattern, true, false,
125  "n.nspname", "p.proname", NULL,
126  "pg_catalog.pg_function_is_visible(p.oid)");
127 
128  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
129 
130  res = PSQLexec(buf.data);
131  termPQExpBuffer(&buf);
132  if (!res)
133  return false;
134 
135  myopt.nullPrint = NULL;
136  myopt.title = _("List of aggregate functions");
137  myopt.translate_header = true;
138 
139  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
140 
141  PQclear(res);
142  return true;
143 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeFunctions()

bool describeFunctions ( const char *  functypes,
const char *  func_pattern,
char **  arg_patterns,
int  num_arg_patterns,
bool  verbose,
bool  showSystem 
)

Definition at line 316 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, i, initPQExpBuffer(), lengthof, _psqlSettings::logfile, map_typename_pattern(), printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, snprintf, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, and typname.

Referenced by exec_command_dfo().

319 {
320  bool showAggregate = strchr(functypes, 'a') != NULL;
321  bool showNormal = strchr(functypes, 'n') != NULL;
322  bool showProcedure = strchr(functypes, 'p') != NULL;
323  bool showTrigger = strchr(functypes, 't') != NULL;
324  bool showWindow = strchr(functypes, 'w') != NULL;
325  bool have_where;
327  PGresult *res;
328  printQueryOpt myopt = pset.popt;
329  static const bool translate_columns[] = {false, false, false, false, true, true, true, false, true, false, false, false, false};
330 
331  /* No "Parallel" column before 9.6 */
332  static const bool translate_columns_pre_96[] = {false, false, false, false, true, true, false, true, false, false, false, false};
333 
334  if (strlen(functypes) != strspn(functypes, "anptwS+"))
335  {
336  pg_log_error("\\df only takes [anptwS+] as options");
337  return true;
338  }
339 
340  if (showProcedure && pset.sversion < 110000)
341  {
342  char sverbuf[32];
343 
344  pg_log_error("\\df does not take a \"%c\" option with server version %s",
345  'p',
347  sverbuf, sizeof(sverbuf)));
348  return true;
349  }
350 
351  if (showWindow && pset.sversion < 80400)
352  {
353  char sverbuf[32];
354 
355  pg_log_error("\\df does not take a \"%c\" option with server version %s",
356  'w',
358  sverbuf, sizeof(sverbuf)));
359  return true;
360  }
361 
362  if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
363  {
364  showAggregate = showNormal = showTrigger = true;
365  if (pset.sversion >= 110000)
366  showProcedure = true;
367  if (pset.sversion >= 80400)
368  showWindow = true;
369  }
370 
371  initPQExpBuffer(&buf);
372 
373  printfPQExpBuffer(&buf,
374  "SELECT n.nspname as \"%s\",\n"
375  " p.proname as \"%s\",\n",
376  gettext_noop("Schema"),
377  gettext_noop("Name"));
378 
379  if (pset.sversion >= 110000)
380  appendPQExpBuffer(&buf,
381  " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
382  " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
383  " CASE p.prokind\n"
384  " WHEN 'a' THEN '%s'\n"
385  " WHEN 'w' THEN '%s'\n"
386  " WHEN 'p' THEN '%s'\n"
387  " ELSE '%s'\n"
388  " END as \"%s\"",
389  gettext_noop("Result data type"),
390  gettext_noop("Argument data types"),
391  /* translator: "agg" is short for "aggregate" */
392  gettext_noop("agg"),
393  gettext_noop("window"),
394  gettext_noop("proc"),
395  gettext_noop("func"),
396  gettext_noop("Type"));
397  else if (pset.sversion >= 80400)
398  appendPQExpBuffer(&buf,
399  " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
400  " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
401  " CASE\n"
402  " WHEN p.proisagg THEN '%s'\n"
403  " WHEN p.proiswindow THEN '%s'\n"
404  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
405  " ELSE '%s'\n"
406  " END as \"%s\"",
407  gettext_noop("Result data type"),
408  gettext_noop("Argument data types"),
409  /* translator: "agg" is short for "aggregate" */
410  gettext_noop("agg"),
411  gettext_noop("window"),
412  gettext_noop("trigger"),
413  gettext_noop("func"),
414  gettext_noop("Type"));
415  else if (pset.sversion >= 80100)
416  appendPQExpBuffer(&buf,
417  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
418  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
419  " CASE WHEN proallargtypes IS NOT NULL THEN\n"
420  " pg_catalog.array_to_string(ARRAY(\n"
421  " SELECT\n"
422  " CASE\n"
423  " WHEN p.proargmodes[s.i] = 'i' THEN ''\n"
424  " WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n"
425  " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n"
426  " WHEN p.proargmodes[s.i] = 'v' THEN 'VARIADIC '\n"
427  " END ||\n"
428  " CASE\n"
429  " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n"
430  " ELSE p.proargnames[s.i] || ' '\n"
431  " END ||\n"
432  " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n"
433  " FROM\n"
434  " pg_catalog.generate_series(1, pg_catalog.array_upper(p.proallargtypes, 1)) AS s(i)\n"
435  " ), ', ')\n"
436  " ELSE\n"
437  " pg_catalog.array_to_string(ARRAY(\n"
438  " SELECT\n"
439  " CASE\n"
440  " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n"
441  " ELSE p.proargnames[s.i+1] || ' '\n"
442  " END ||\n"
443  " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
444  " FROM\n"
445  " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
446  " ), ', ')\n"
447  " END AS \"%s\",\n"
448  " CASE\n"
449  " WHEN p.proisagg THEN '%s'\n"
450  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
451  " ELSE '%s'\n"
452  " END AS \"%s\"",
453  gettext_noop("Result data type"),
454  gettext_noop("Argument data types"),
455  /* translator: "agg" is short for "aggregate" */
456  gettext_noop("agg"),
457  gettext_noop("trigger"),
458  gettext_noop("func"),
459  gettext_noop("Type"));
460  else
461  appendPQExpBuffer(&buf,
462  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
463  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
464  " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
465  " CASE\n"
466  " WHEN p.proisagg THEN '%s'\n"
467  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
468  " ELSE '%s'\n"
469  " END AS \"%s\"",
470  gettext_noop("Result data type"),
471  gettext_noop("Argument data types"),
472  /* translator: "agg" is short for "aggregate" */
473  gettext_noop("agg"),
474  gettext_noop("trigger"),
475  gettext_noop("func"),
476  gettext_noop("Type"));
477 
478  if (verbose)
479  {
480  appendPQExpBuffer(&buf,
481  ",\n CASE\n"
482  " WHEN p.provolatile = 'i' THEN '%s'\n"
483  " WHEN p.provolatile = 's' THEN '%s'\n"
484  " WHEN p.provolatile = 'v' THEN '%s'\n"
485  " END as \"%s\"",
486  gettext_noop("immutable"),
487  gettext_noop("stable"),
488  gettext_noop("volatile"),
489  gettext_noop("Volatility"));
490  if (pset.sversion >= 90600)
491  appendPQExpBuffer(&buf,
492  ",\n CASE\n"
493  " WHEN p.proparallel = 'r' THEN '%s'\n"
494  " WHEN p.proparallel = 's' THEN '%s'\n"
495  " WHEN p.proparallel = 'u' THEN '%s'\n"
496  " END as \"%s\"",
497  gettext_noop("restricted"),
498  gettext_noop("safe"),
499  gettext_noop("unsafe"),
500  gettext_noop("Parallel"));
501  appendPQExpBuffer(&buf,
502  ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
503  ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
504  gettext_noop("Owner"),
505  gettext_noop("definer"),
506  gettext_noop("invoker"),
507  gettext_noop("Security"));
508  appendPQExpBufferStr(&buf, ",\n ");
509  printACLColumn(&buf, "p.proacl");
510  appendPQExpBuffer(&buf,
511  ",\n l.lanname as \"%s\"",
512  gettext_noop("Language"));
513  if (pset.sversion >= 140000)
514  appendPQExpBuffer(&buf,
515  ",\n COALESCE(pg_catalog.pg_get_function_sqlbody(p.oid), p.prosrc) as \"%s\"",
516  gettext_noop("Source code"));
517  else
518  appendPQExpBuffer(&buf,
519  ",\n p.prosrc as \"%s\"",
520  gettext_noop("Source code"));
521  appendPQExpBuffer(&buf,
522  ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
523  gettext_noop("Description"));
524  }
525 
527  "\nFROM pg_catalog.pg_proc p"
528  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
529 
530  for (int i = 0; i < num_arg_patterns; i++)
531  {
532  appendPQExpBuffer(&buf,
533  " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
534  " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
535  i, i, i, i, i, i);
536  }
537 
538  if (verbose)
540  " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
541 
542  have_where = false;
543 
544  /* filter by function type, if requested */
545  if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
546  /* Do nothing */ ;
547  else if (showNormal)
548  {
549  if (!showAggregate)
550  {
551  if (have_where)
552  appendPQExpBufferStr(&buf, " AND ");
553  else
554  {
555  appendPQExpBufferStr(&buf, "WHERE ");
556  have_where = true;
557  }
558  if (pset.sversion >= 110000)
559  appendPQExpBufferStr(&buf, "p.prokind <> 'a'\n");
560  else
561  appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
562  }
563  if (!showProcedure && pset.sversion >= 110000)
564  {
565  if (have_where)
566  appendPQExpBufferStr(&buf, " AND ");
567  else
568  {
569  appendPQExpBufferStr(&buf, "WHERE ");
570  have_where = true;
571  }
572  appendPQExpBufferStr(&buf, "p.prokind <> 'p'\n");
573  }
574  if (!showTrigger)
575  {
576  if (have_where)
577  appendPQExpBufferStr(&buf, " AND ");
578  else
579  {
580  appendPQExpBufferStr(&buf, "WHERE ");
581  have_where = true;
582  }
583  appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
584  }
585  if (!showWindow && pset.sversion >= 80400)
586  {
587  if (have_where)
588  appendPQExpBufferStr(&buf, " AND ");
589  else
590  {
591  appendPQExpBufferStr(&buf, "WHERE ");
592  have_where = true;
593  }
594  if (pset.sversion >= 110000)
595  appendPQExpBufferStr(&buf, "p.prokind <> 'w'\n");
596  else
597  appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
598  }
599  }
600  else
601  {
602  bool needs_or = false;
603 
604  appendPQExpBufferStr(&buf, "WHERE (\n ");
605  have_where = true;
606  /* Note: at least one of these must be true ... */
607  if (showAggregate)
608  {
609  if (pset.sversion >= 110000)
610  appendPQExpBufferStr(&buf, "p.prokind = 'a'\n");
611  else
612  appendPQExpBufferStr(&buf, "p.proisagg\n");
613  needs_or = true;
614  }
615  if (showTrigger)
616  {
617  if (needs_or)
618  appendPQExpBufferStr(&buf, " OR ");
620  "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
621  needs_or = true;
622  }
623  if (showProcedure)
624  {
625  if (needs_or)
626  appendPQExpBufferStr(&buf, " OR ");
627  appendPQExpBufferStr(&buf, "p.prokind = 'p'\n");
628  needs_or = true;
629  }
630  if (showWindow)
631  {
632  if (needs_or)
633  appendPQExpBufferStr(&buf, " OR ");
634  if (pset.sversion >= 110000)
635  appendPQExpBufferStr(&buf, "p.prokind = 'w'\n");
636  else
637  appendPQExpBufferStr(&buf, "p.proiswindow\n");
638  }
639  appendPQExpBufferStr(&buf, " )\n");
640  }
641 
642  processSQLNamePattern(pset.db, &buf, func_pattern, have_where, false,
643  "n.nspname", "p.proname", NULL,
644  "pg_catalog.pg_function_is_visible(p.oid)");
645 
646  for (int i = 0; i < num_arg_patterns; i++)
647  {
648  if (strcmp(arg_patterns[i], "-") != 0)
649  {
650  /*
651  * Match type-name patterns against either internal or external
652  * name, like \dT. Unlike \dT, there seems no reason to
653  * discriminate against arrays or composite types.
654  */
655  char nspname[64];
656  char typname[64];
657  char ft[64];
658  char tiv[64];
659 
660  snprintf(nspname, sizeof(nspname), "nt%d.nspname", i);
661  snprintf(typname, sizeof(typname), "t%d.typname", i);
662  snprintf(ft, sizeof(ft),
663  "pg_catalog.format_type(t%d.oid, NULL)", i);
664  snprintf(tiv, sizeof(tiv),
665  "pg_catalog.pg_type_is_visible(t%d.oid)", i);
667  map_typename_pattern(arg_patterns[i]),
668  true, false,
669  nspname, typname, ft, tiv);
670  }
671  else
672  {
673  /* "-" pattern specifies no such parameter */
674  appendPQExpBuffer(&buf, " AND t%d.typname IS NULL\n", i);
675  }
676  }
677 
678  if (!showSystem && !func_pattern)
679  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
680  " AND n.nspname <> 'information_schema'\n");
681 
682  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
683 
684  res = PSQLexec(buf.data);
685  termPQExpBuffer(&buf);
686  if (!res)
687  return false;
688 
689  myopt.nullPrint = NULL;
690  myopt.title = _("List of functions");
691  myopt.translate_header = true;
692  if (pset.sversion >= 90600)
693  {
694  myopt.translate_columns = translate_columns;
695  myopt.n_translate_columns = lengthof(translate_columns);
696  }
697  else
698  {
699  myopt.translate_columns = translate_columns_pre_96;
700  myopt.n_translate_columns = lengthof(translate_columns_pre_96);
701  }
702 
703  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
704 
705  PQclear(res);
706  return true;
707 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
static const char * map_typename_pattern(const char *pattern)
Definition: describe.c:840
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
NameData typname
Definition: pg_type.h:41
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
int i
const bool * translate_columns
Definition: print.h:174
#define snprintf
Definition: port.h:217
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeOperators()

bool describeOperators ( const char *  oper_pattern,
char **  arg_patterns,
int  num_arg_patterns,
bool  verbose,
bool  showSystem 
)

Definition at line 890 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, i, initPQExpBuffer(), _psqlSettings::logfile, map_typename_pattern(), printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, snprintf, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, and typname.

Referenced by exec_command_dfo().

893 {
895  PGresult *res;
896  printQueryOpt myopt = pset.popt;
897 
898  initPQExpBuffer(&buf);
899 
900  /*
901  * Note: before Postgres 9.1, we did not assign comments to any built-in
902  * operators, preferring to let the comment on the underlying function
903  * suffice. The coalesce() on the obj_description() calls below supports
904  * this convention by providing a fallback lookup of a comment on the
905  * operator's function. As of 9.1 there is a policy that every built-in
906  * operator should have a comment; so the coalesce() is no longer
907  * necessary so far as built-in operators are concerned. We keep it
908  * anyway, for now, because (1) third-party modules may still be following
909  * the old convention, and (2) we'd need to do it anyway when talking to a
910  * pre-9.1 server.
911  *
912  * The support for postfix operators in this query is dead code as of
913  * Postgres 14, but we need to keep it for as long as we support talking
914  * to pre-v14 servers.
915  */
916 
917  printfPQExpBuffer(&buf,
918  "SELECT n.nspname as \"%s\",\n"
919  " o.oprname AS \"%s\",\n"
920  " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
921  " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
922  " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
923  gettext_noop("Schema"),
924  gettext_noop("Name"),
925  gettext_noop("Left arg type"),
926  gettext_noop("Right arg type"),
927  gettext_noop("Result type"));
928 
929  if (verbose)
930  appendPQExpBuffer(&buf,
931  " o.oprcode AS \"%s\",\n",
932  gettext_noop("Function"));
933 
934  appendPQExpBuffer(&buf,
935  " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
936  " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
937  "FROM pg_catalog.pg_operator o\n"
938  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
939  gettext_noop("Description"));
940 
941  if (num_arg_patterns >= 2)
942  {
943  num_arg_patterns = 2; /* ignore any additional arguments */
945  " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
946  " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
947  " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
948  " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
949  }
950  else if (num_arg_patterns == 1)
951  {
953  " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
954  " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
955  }
956 
957  if (!showSystem && !oper_pattern)
958  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
959  " AND n.nspname <> 'information_schema'\n");
960 
961  processSQLNamePattern(pset.db, &buf, oper_pattern,
962  !showSystem && !oper_pattern, true,
963  "n.nspname", "o.oprname", NULL,
964  "pg_catalog.pg_operator_is_visible(o.oid)");
965 
966  if (num_arg_patterns == 1)
967  appendPQExpBufferStr(&buf, " AND o.oprleft = 0\n");
968 
969  for (int i = 0; i < num_arg_patterns; i++)
970  {
971  if (strcmp(arg_patterns[i], "-") != 0)
972  {
973  /*
974  * Match type-name patterns against either internal or external
975  * name, like \dT. Unlike \dT, there seems no reason to
976  * discriminate against arrays or composite types.
977  */
978  char nspname[64];
979  char typname[64];
980  char ft[64];
981  char tiv[64];
982 
983  snprintf(nspname, sizeof(nspname), "nt%d.nspname", i);
984  snprintf(typname, sizeof(typname), "t%d.typname", i);
985  snprintf(ft, sizeof(ft),
986  "pg_catalog.format_type(t%d.oid, NULL)", i);
987  snprintf(tiv, sizeof(tiv),
988  "pg_catalog.pg_type_is_visible(t%d.oid)", i);
990  map_typename_pattern(arg_patterns[i]),
991  true, false,
992  nspname, typname, ft, tiv);
993  }
994  else
995  {
996  /* "-" pattern specifies no such parameter */
997  appendPQExpBuffer(&buf, " AND t%d.typname IS NULL\n", i);
998  }
999  }
1000 
1001  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
1002 
1003  res = PSQLexec(buf.data);
1004  termPQExpBuffer(&buf);
1005  if (!res)
1006  return false;
1007 
1008  myopt.nullPrint = NULL;
1009  myopt.title = _("List of operators");
1010  myopt.translate_header = true;
1011 
1012  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1013 
1014  PQclear(res);
1015  return true;
1016 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
static const char * map_typename_pattern(const char *pattern)
Definition: describe.c:840
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
NameData typname
Definition: pg_type.h:41
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
int i
#define snprintf
Definition: port.h:217
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describePublications()

bool describePublications ( const char *  pattern)

Definition at line 6219 of file describe.c.

References _, appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, i, initPQExpBuffer(), _psqlSettings::logfile, pg_log_error, _psqlSettings::popt, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), printTable(), printTableAddCell(), printTableAddFooter(), printTableAddHeader(), printTableCleanup(), printTableInit(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::quiet, _psqlSettings::sversion, termPQExpBuffer(), and printQueryOpt::topt.

Referenced by exec_command_d().

6220 {
6222  int i;
6223  PGresult *res;
6224  bool has_pubtruncate;
6225  bool has_pubviaroot;
6226 
6227  if (pset.sversion < 100000)
6228  {
6229  char sverbuf[32];
6230 
6231  pg_log_error("The server (version %s) does not support publications.",
6233  sverbuf, sizeof(sverbuf)));
6234  return true;
6235  }
6236 
6237  has_pubtruncate = (pset.sversion >= 110000);
6238  has_pubviaroot = (pset.sversion >= 130000);
6239 
6240  initPQExpBuffer(&buf);
6241 
6242  printfPQExpBuffer(&buf,
6243  "SELECT oid, pubname,\n"
6244  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6245  " puballtables, pubinsert, pubupdate, pubdelete");
6246  if (has_pubtruncate)
6247  appendPQExpBufferStr(&buf,
6248  ", pubtruncate");
6249  if (has_pubviaroot)
6250  appendPQExpBufferStr(&buf,
6251  ", pubviaroot");
6252  appendPQExpBufferStr(&buf,
6253  "\nFROM pg_catalog.pg_publication\n");
6254 
6255  processSQLNamePattern(pset.db, &buf, pattern, false, false,
6256  NULL, "pubname", NULL,
6257  NULL);
6258 
6259  appendPQExpBufferStr(&buf, "ORDER BY 2;");
6260 
6261  res = PSQLexec(buf.data);
6262  if (!res)
6263  {
6264  termPQExpBuffer(&buf);
6265  return false;
6266  }
6267 
6268  if (PQntuples(res) == 0)
6269  {
6270  if (!pset.quiet)
6271  {
6272  if (pattern)
6273  pg_log_error("Did not find any publication named \"%s\".",
6274  pattern);
6275  else
6276  pg_log_error("Did not find any publications.");
6277  }
6278 
6279  termPQExpBuffer(&buf);
6280  PQclear(res);
6281  return false;
6282  }
6283 
6284  for (i = 0; i < PQntuples(res); i++)
6285  {
6286  const char align = 'l';
6287  int ncols = 5;
6288  int nrows = 1;
6289  int tables = 0;
6290  PGresult *tabres;
6291  char *pubid = PQgetvalue(res, i, 0);
6292  char *pubname = PQgetvalue(res, i, 1);
6293  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
6294  int j;
6295  PQExpBufferData title;
6296  printTableOpt myopt = pset.popt.topt;
6297  printTableContent cont;
6298 
6299  if (has_pubtruncate)
6300  ncols++;
6301  if (has_pubviaroot)
6302  ncols++;
6303 
6304  initPQExpBuffer(&title);
6305  printfPQExpBuffer(&title, _("Publication %s"), pubname);
6306  printTableInit(&cont, &myopt, title.data, ncols, nrows);
6307 
6308  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
6309  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
6310  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
6311  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
6312  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
6313  if (has_pubtruncate)
6314  printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
6315  if (has_pubviaroot)
6316  printTableAddHeader(&cont, gettext_noop("Via root"), true, align);
6317 
6318  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
6319  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
6320  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
6321  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
6322  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
6323  if (has_pubtruncate)
6324  printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
6325  if (has_pubviaroot)
6326  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
6327 
6328  if (!puballtables)
6329  {
6330  printfPQExpBuffer(&buf,
6331  "SELECT n.nspname, c.relname\n"
6332  "FROM pg_catalog.pg_class c,\n"
6333  " pg_catalog.pg_namespace n,\n"
6334  " pg_catalog.pg_publication_rel pr\n"
6335  "WHERE c.relnamespace = n.oid\n"
6336  " AND c.oid = pr.prrelid\n"
6337  " AND pr.prpubid = '%s'\n"
6338  "ORDER BY 1,2", pubid);
6339 
6340  tabres = PSQLexec(buf.data);
6341  if (!tabres)
6342  {
6343  printTableCleanup(&cont);
6344  PQclear(res);
6345  termPQExpBuffer(&buf);
6346  termPQExpBuffer(&title);
6347  return false;
6348  }
6349  else
6350  tables = PQntuples(tabres);
6351 
6352  if (tables > 0)
6353  printTableAddFooter(&cont, _("Tables:"));
6354 
6355  for (j = 0; j < tables; j++)
6356  {
6357  printfPQExpBuffer(&buf, " \"%s.%s\"",
6358  PQgetvalue(tabres, j, 0),
6359  PQgetvalue(tabres, j, 1));
6360 
6361  printTableAddFooter(&cont, buf.data);
6362  }
6363  PQclear(tabres);
6364  }
6365 
6366  printTable(&cont, pset.queryFout, false, pset.logfile);
6367  printTableCleanup(&cont);
6368 
6369  termPQExpBuffer(&title);
6370  }
6371 
6372  termPQExpBuffer(&buf);
6373  PQclear(res);
6374 
6375  return true;
6376 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:32
void printTableCleanup(printTableContent *const content)
Definition: print.c:3225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
printTableOpt topt
Definition: print.h:169
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3094
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3134
static char * buf
Definition: pg_test_fsync.c:68
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3314
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3182
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3057
int i
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeRoles()

bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3738 of file describe.c.

References _, add_role_attribute(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), buf, conns, PQExpBufferData::data, _psqlSettings::db, printTableOpt::default_footer, free, gettext_noop, i, initPQExpBuffer(), PQExpBufferData::len, _psqlSettings::logfile, ngettext, pg_malloc0(), pg_strdup(), _psqlSettings::popt, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), printTable(), printTableAddCell(), printTableAddHeader(), printTableCleanup(), printTableInit(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, resetPQExpBuffer(), _psqlSettings::sversion, termPQExpBuffer(), and printQueryOpt::topt.

Referenced by exec_command_d().

3739 {
3741  PGresult *res;
3742  printTableContent cont;
3743  printTableOpt myopt = pset.popt.topt;
3744  int ncols = 3;
3745  int nrows = 0;
3746  int i;
3747  int conns;
3748  const char align = 'l';
3749  char **attr;
3750 
3751  myopt.default_footer = false;
3752 
3753  initPQExpBuffer(&buf);
3754 
3755  if (pset.sversion >= 80100)
3756  {
3757  printfPQExpBuffer(&buf,
3758  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3759  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3760  " r.rolconnlimit, r.rolvaliduntil,\n"
3761  " ARRAY(SELECT b.rolname\n"
3762  " FROM pg_catalog.pg_auth_members m\n"
3763  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3764  " WHERE m.member = r.oid) as memberof");
3765 
3766  if (verbose && pset.sversion >= 80200)
3767  {
3768  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3769  ncols++;
3770  }
3771  if (pset.sversion >= 90100)
3772  {
3773  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3774  }
3775 
3776  if (pset.sversion >= 90500)
3777  {
3778  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3779  }
3780 
3781  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3782 
3783  if (!showSystem && !pattern)
3784  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3785 
3786  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3787  NULL, "r.rolname", NULL, NULL);
3788  }
3789  else
3790  {
3791  printfPQExpBuffer(&buf,
3792  "SELECT u.usename AS rolname,\n"
3793  " u.usesuper AS rolsuper,\n"
3794  " true AS rolinherit, false AS rolcreaterole,\n"
3795  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3796  " -1 AS rolconnlimit,"
3797  " u.valuntil as rolvaliduntil,\n"
3798  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3799  "\nFROM pg_catalog.pg_user u\n");
3800 
3801  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3802  NULL, "u.usename", NULL, NULL);
3803  }
3804 
3805  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3806 
3807  res = PSQLexec(buf.data);
3808  if (!res)
3809  return false;
3810 
3811  nrows = PQntuples(res);
3812  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3813 
3814  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3815 
3816  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3817  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3818  /* ignores implicit memberships from superuser & pg_database_owner */
3819  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3820 
3821  if (verbose && pset.sversion >= 80200)
3822  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3823 
3824  for (i = 0; i < nrows; i++)
3825  {
3826  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3827 
3828  resetPQExpBuffer(&buf);
3829  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3830  add_role_attribute(&buf, _("Superuser"));
3831 
3832  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3833  add_role_attribute(&buf, _("No inheritance"));
3834 
3835  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3836  add_role_attribute(&buf, _("Create role"));
3837 
3838  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3839  add_role_attribute(&buf, _("Create DB"));
3840 
3841  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3842  add_role_attribute(&buf, _("Cannot login"));
3843 
3844  if (pset.sversion >= 90100)
3845  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3846  add_role_attribute(&buf, _("Replication"));
3847 
3848  if (pset.sversion >= 90500)
3849  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3850  add_role_attribute(&buf, _("Bypass RLS"));
3851 
3852  conns = atoi(PQgetvalue(res, i, 6));
3853  if (conns >= 0)
3854  {
3855  if (buf.len > 0)
3856  appendPQExpBufferChar(&buf, '\n');
3857 
3858  if (conns == 0)
3859  appendPQExpBufferStr(&buf, _("No connections"));
3860  else
3861  appendPQExpBuffer(&buf, ngettext("%d connection",
3862  "%d connections",
3863  conns),
3864  conns);
3865  }
3866 
3867  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3868  {
3869  if (buf.len > 0)
3870  appendPQExpBufferChar(&buf, '\n');
3871  appendPQExpBufferStr(&buf, _("Password valid until "));
3872  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3873  }
3874 
3875  attr[i] = pg_strdup(buf.data);
3876 
3877  printTableAddCell(&cont, attr[i], false, false);
3878 
3879  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3880 
3881  if (verbose && pset.sversion >= 80200)
3882  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3883  }
3884  termPQExpBuffer(&buf);
3885 
3886  printTable(&cont, pset.queryFout, false, pset.logfile);
3887  printTableCleanup(&cont);
3888 
3889  for (i = 0; i < nrows; i++)
3890  free(attr[i]);
3891  free(attr);
3892 
3893  PQclear(res);
3894  return true;
3895 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:32
void printTableCleanup(printTableContent *const content)
Definition: print.c:3225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
printTableOpt topt
Definition: print.h:169
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3898
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3094
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static IsoConnInfo * conns
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3134
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3314
static int verbose
#define ngettext(s, p, n)
Definition: c.h:1182
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define free(a)
Definition: header.h:65
bool default_footer
Definition: print.h:113
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3057
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeSubscriptions()

bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 6385 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

6386 {
6388  PGresult *res;
6389  printQueryOpt myopt = pset.popt;
6390  static const bool translate_columns[] = {false, false, false, false,
6391  false, false, false, false, false};
6392 
6393  if (pset.sversion < 100000)
6394  {
6395  char sverbuf[32];
6396 
6397  pg_log_error("The server (version %s) does not support subscriptions.",
6399  sverbuf, sizeof(sverbuf)));
6400  return true;
6401  }
6402 
6403  initPQExpBuffer(&buf);
6404 
6405  printfPQExpBuffer(&buf,
6406  "SELECT subname AS \"%s\"\n"
6407  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6408  ", subenabled AS \"%s\"\n"
6409  ", subpublications AS \"%s\"\n",
6410  gettext_noop("Name"),
6411  gettext_noop("Owner"),
6412  gettext_noop("Enabled"),
6413  gettext_noop("Publication"));
6414 
6415  if (verbose)
6416  {
6417  /* Binary mode and streaming are only supported in v14 and higher */
6418  if (pset.sversion >= 140000)
6419  appendPQExpBuffer(&buf,
6420  ", subbinary AS \"%s\"\n"
6421  ", substream AS \"%s\"\n",
6422  gettext_noop("Binary"),
6423  gettext_noop("Streaming"));
6424 
6425  /* Two_phase is only supported in v15 and higher */
6426  if (pset.sversion >= 150000)
6427  appendPQExpBuffer(&buf,
6428  ", subtwophasestate AS \"%s\"\n",
6429  gettext_noop("Two phase commit"));
6430 
6431  appendPQExpBuffer(&buf,
6432  ", subsynccommit AS \"%s\"\n"
6433  ", subconninfo AS \"%s\"\n",
6434  gettext_noop("Synchronous commit"),
6435  gettext_noop("Conninfo"));
6436  }
6437 
6438  /* Only display subscriptions in current database. */
6439  appendPQExpBufferStr(&buf,
6440  "FROM pg_catalog.pg_subscription\n"
6441  "WHERE subdbid = (SELECT oid\n"
6442  " FROM pg_catalog.pg_database\n"
6443  " WHERE datname = pg_catalog.current_database())");
6444 
6445  processSQLNamePattern(pset.db, &buf, pattern, true, false,
6446  NULL, "subname", NULL,
6447  NULL);
6448 
6449  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6450 
6451  res = PSQLexec(buf.data);
6452  termPQExpBuffer(&buf);
6453  if (!res)
6454  return false;
6455 
6456  myopt.nullPrint = NULL;
6457  myopt.title = _("List of subscriptions");
6458  myopt.translate_header = true;
6459  myopt.translate_columns = translate_columns;
6460  myopt.n_translate_columns = lengthof(translate_columns);
6461 
6462  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6463 
6464  PQclear(res);
6465  return true;
6466 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeTableDetails()

bool describeTableDetails ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 1532 of file describe.c.

References appendPQExpBufferStr(), buf, cancel_pressed, PQExpBufferData::data, _psqlSettings::db, describeOneTableDetails(), i, initPQExpBuffer(), pg_log_error, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::quiet, relname, and termPQExpBuffer().

Referenced by exec_command_d().

1533 {
1535  PGresult *res;
1536  int i;
1537 
1538  initPQExpBuffer(&buf);
1539 
1540  printfPQExpBuffer(&buf,
1541  "SELECT c.oid,\n"
1542  " n.nspname,\n"
1543  " c.relname\n"
1544  "FROM pg_catalog.pg_class c\n"
1545  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1546 
1547  if (!showSystem && !pattern)
1548  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1549  " AND n.nspname <> 'information_schema'\n");
1550 
1551  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1552  "n.nspname", "c.relname", NULL,
1553  "pg_catalog.pg_table_is_visible(c.oid)");
1554 
1555  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1556 
1557  res = PSQLexec(buf.data);
1558  termPQExpBuffer(&buf);
1559  if (!res)
1560  return false;
1561 
1562  if (PQntuples(res) == 0)
1563  {
1564  if (!pset.quiet)
1565  {
1566  if (pattern)
1567  pg_log_error("Did not find any relation named \"%s\".",
1568  pattern);
1569  else
1570  pg_log_error("Did not find any relations.");
1571  }
1572  PQclear(res);
1573  return false;
1574  }
1575 
1576  for (i = 0; i < PQntuples(res); i++)
1577  {
1578  const char *oid;
1579  const char *nspname;
1580  const char *relname;
1581 
1582  oid = PQgetvalue(res, i, 0);
1583  nspname = PQgetvalue(res, i, 1);
1584  relname = PQgetvalue(res, i, 2);
1585 
1586  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1587  {
1588  PQclear(res);
1589  return false;
1590  }
1591  if (cancel_pressed)
1592  {
1593  PQclear(res);
1594  return false;
1595  }
1596  }
1597 
1598  PQclear(res);
1599  return true;
1600 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:32
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
NameData relname
Definition: pg_class.h:38
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
static char * buf
Definition: pg_test_fsync.c:68
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1610
static int verbose
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
void PQclear(PGresult *res)
Definition: fe-exec.c:694
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeTablespaces()

bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 220 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_info, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

221 {
223  PGresult *res;
224  printQueryOpt myopt = pset.popt;
225 
226  if (pset.sversion < 80000)
227  {
228  char sverbuf[32];
229 
230  pg_log_info("The server (version %s) does not support tablespaces.",
232  sverbuf, sizeof(sverbuf)));
233  return true;
234  }
235 
236  initPQExpBuffer(&buf);
237 
238  if (pset.sversion >= 90200)
239  printfPQExpBuffer(&buf,
240  "SELECT spcname AS \"%s\",\n"
241  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
242  " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
243  gettext_noop("Name"),
244  gettext_noop("Owner"),
245  gettext_noop("Location"));
246  else
247  printfPQExpBuffer(&buf,
248  "SELECT spcname AS \"%s\",\n"
249  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
250  " spclocation AS \"%s\"",
251  gettext_noop("Name"),
252  gettext_noop("Owner"),
253  gettext_noop("Location"));
254 
255  if (verbose)
256  {
257  appendPQExpBufferStr(&buf, ",\n ");
258  printACLColumn(&buf, "spcacl");
259  }
260 
261  if (verbose && pset.sversion >= 90000)
262  appendPQExpBuffer(&buf,
263  ",\n spcoptions AS \"%s\"",
264  gettext_noop("Options"));
265 
266  if (verbose && pset.sversion >= 90200)
267  appendPQExpBuffer(&buf,
268  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"",
269  gettext_noop("Size"));
270 
271  if (verbose && pset.sversion >= 80200)
272  appendPQExpBuffer(&buf,
273  ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
274  gettext_noop("Description"));
275 
277  "\nFROM pg_catalog.pg_tablespace\n");
278 
279  processSQLNamePattern(pset.db, &buf, pattern, false, false,
280  NULL, "spcname", NULL,
281  NULL);
282 
283  appendPQExpBufferStr(&buf, "ORDER BY 1;");
284 
285  res = PSQLexec(buf.data);
286  termPQExpBuffer(&buf);
287  if (!res)
288  return false;
289 
290  myopt.nullPrint = NULL;
291  myopt.title = _("List of tablespaces");
292  myopt.translate_header = true;
293 
294  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
295 
296  PQclear(res);
297  return true;
298 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
#define pg_log_info(...)
Definition: logging.h:88
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ describeTypes()

bool describeTypes ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 716 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, map_typename_pattern(), printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

717 {
719  PGresult *res;
720  printQueryOpt myopt = pset.popt;
721 
722  initPQExpBuffer(&buf);
723 
724  printfPQExpBuffer(&buf,
725  "SELECT n.nspname as \"%s\",\n"
726  " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
727  gettext_noop("Schema"),
728  gettext_noop("Name"));
729  if (verbose)
730  appendPQExpBuffer(&buf,
731  " t.typname AS \"%s\",\n"
732  " CASE WHEN t.typrelid != 0\n"
733  " THEN CAST('tuple' AS pg_catalog.text)\n"
734  " WHEN t.typlen < 0\n"
735  " THEN CAST('var' AS pg_catalog.text)\n"
736  " ELSE CAST(t.typlen AS pg_catalog.text)\n"
737  " END AS \"%s\",\n",
738  gettext_noop("Internal name"),
739  gettext_noop("Size"));
740  if (verbose && pset.sversion >= 80300)
741  {
743  " pg_catalog.array_to_string(\n"
744  " ARRAY(\n"
745  " SELECT e.enumlabel\n"
746  " FROM pg_catalog.pg_enum e\n"
747  " WHERE e.enumtypid = t.oid\n");
748 
749  if (pset.sversion >= 90100)
751  " ORDER BY e.enumsortorder\n");
752  else
754  " ORDER BY e.oid\n");
755 
756  appendPQExpBuffer(&buf,
757  " ),\n"
758  " E'\\n'\n"
759  " ) AS \"%s\",\n",
760  gettext_noop("Elements"));
761  }
762  if (verbose)
763  {
764  appendPQExpBuffer(&buf,
765  " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
766  gettext_noop("Owner"));
767  }
768  if (verbose && pset.sversion >= 90200)
769  {
770  printACLColumn(&buf, "t.typacl");
771  appendPQExpBufferStr(&buf, ",\n ");
772  }
773 
774  appendPQExpBuffer(&buf,
775  " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
776  gettext_noop("Description"));
777 
778  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
779  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
780 
781  /*
782  * do not include complex types (typrelid!=0) unless they are standalone
783  * composite types
784  */
785  appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
786  appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
787  " FROM pg_catalog.pg_class c "
788  "WHERE c.oid = t.typrelid))\n");
789 
790  /*
791  * do not include array types unless the pattern contains [] (before 8.3
792  * we have to use the assumption that their names start with underscore)
793  */
794  if (pattern == NULL || strstr(pattern, "[]") == NULL)
795  {
796  if (pset.sversion >= 80300)
797  appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
798  else
799  appendPQExpBufferStr(&buf, " AND t.typname !~ '^_'\n");
800  }
801 
802  if (!showSystem && !pattern)
803  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
804  " AND n.nspname <> 'information_schema'\n");
805 
806  /* Match name pattern against either internal or external name */
808  true, false,
809  "n.nspname", "t.typname",
810  "pg_catalog.format_type(t.oid, NULL)",
811  "pg_catalog.pg_type_is_visible(t.oid)");
812 
813  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
814 
815  res = PSQLexec(buf.data);
816  termPQExpBuffer(&buf);
817  if (!res)
818  return false;
819 
820  myopt.nullPrint = NULL;
821  myopt.title = _("List of data types");
822  myopt.translate_header = true;
823 
824  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
825 
826  PQclear(res);
827  return true;
828 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
static const char * map_typename_pattern(const char *pattern)
Definition: describe.c:840
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
#define CppAsString2(x)
Definition: c.h:289
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listAllDbs()

bool listAllDbs ( const char *  pattern,
bool  verbose 
)

Definition at line 1025 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_list(), and main().

1026 {
1027  PGresult *res;
1029  printQueryOpt myopt = pset.popt;
1030 
1031  initPQExpBuffer(&buf);
1032 
1033  printfPQExpBuffer(&buf,
1034  "SELECT d.datname as \"%s\",\n"
1035  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
1036  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
1037  gettext_noop("Name"),
1038  gettext_noop("Owner"),
1039  gettext_noop("Encoding"));
1040  if (pset.sversion >= 80400)
1041  appendPQExpBuffer(&buf,
1042  " d.datcollate as \"%s\",\n"
1043  " d.datctype as \"%s\",\n",
1044  gettext_noop("Collate"),
1045  gettext_noop("Ctype"));
1046  appendPQExpBufferStr(&buf, " ");
1047  printACLColumn(&buf, "d.datacl");
1048  if (verbose && pset.sversion >= 80200)
1049  appendPQExpBuffer(&buf,
1050  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
1051  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
1052  " ELSE 'No Access'\n"
1053  " END as \"%s\"",
1054  gettext_noop("Size"));
1055  if (verbose && pset.sversion >= 80000)
1056  appendPQExpBuffer(&buf,
1057  ",\n t.spcname as \"%s\"",
1058  gettext_noop("Tablespace"));
1059  if (verbose && pset.sversion >= 80200)
1060  appendPQExpBuffer(&buf,
1061  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
1062  gettext_noop("Description"));
1063  appendPQExpBufferStr(&buf,
1064  "\nFROM pg_catalog.pg_database d\n");
1065  if (verbose && pset.sversion >= 80000)
1066  appendPQExpBufferStr(&buf,
1067  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
1068 
1069  if (pattern)
1070  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1071  NULL, "d.datname", NULL, NULL);
1072 
1073  appendPQExpBufferStr(&buf, "ORDER BY 1;");
1074  res = PSQLexec(buf.data);
1075  termPQExpBuffer(&buf);
1076  if (!res)
1077  return false;
1078 
1079  myopt.nullPrint = NULL;
1080  myopt.title = _("List of databases");
1081  myopt.translate_header = true;
1082 
1083  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1084 
1085  PQclear(res);
1086  return true;
1087 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listCasts()

bool listCasts ( const char *  pattern,
bool  verbose 
)

Definition at line 4801 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4802 {
4804  PGresult *res;
4805  printQueryOpt myopt = pset.popt;
4806  static const bool translate_columns[] = {false, false, false, true, false};
4807 
4808  initPQExpBuffer(&buf);
4809 
4810  printfPQExpBuffer(&buf,
4811  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4812  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4813  gettext_noop("Source type"),
4814  gettext_noop("Target type"));
4815 
4816  /*
4817  * We don't attempt to localize '(binary coercible)' or '(with inout)',
4818  * because there's too much risk of gettext translating a function name
4819  * that happens to match some string in the PO database.
4820  */
4821  if (pset.sversion >= 80400)
4822  appendPQExpBuffer(&buf,
4823  " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4824  " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4825  " ELSE p.proname\n"
4826  " END AS \"%s\",\n",
4827  COERCION_METHOD_BINARY,
4828  COERCION_METHOD_INOUT,
4829  gettext_noop("Function"));
4830  else
4831  appendPQExpBuffer(&buf,
4832  " CASE WHEN c.castfunc = 0 THEN '(binary coercible)'\n"
4833  " ELSE p.proname\n"
4834  " END AS \"%s\",\n",
4835  gettext_noop("Function"));
4836 
4837  appendPQExpBuffer(&buf,
4838  " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4839  " WHEN c.castcontext = '%c' THEN '%s'\n"
4840  " ELSE '%s'\n"
4841  " END AS \"%s\"",
4842  COERCION_CODE_EXPLICIT,
4843  gettext_noop("no"),
4844  COERCION_CODE_ASSIGNMENT,
4845  gettext_noop("in assignment"),
4846  gettext_noop("yes"),
4847  gettext_noop("Implicit?"));
4848 
4849  if (verbose)
4850  appendPQExpBuffer(&buf,
4851  ",\n d.description AS \"%s\"",
4852  gettext_noop("Description"));
4853 
4854  /*
4855  * We need a left join to pg_proc for binary casts; the others are just
4856  * paranoia.
4857  */
4858  appendPQExpBufferStr(&buf,
4859  "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4860  " ON c.castfunc = p.oid\n"
4861  " LEFT JOIN pg_catalog.pg_type ts\n"
4862  " ON c.castsource = ts.oid\n"
4863  " LEFT JOIN pg_catalog.pg_namespace ns\n"
4864  " ON ns.oid = ts.typnamespace\n"
4865  " LEFT JOIN pg_catalog.pg_type tt\n"
4866  " ON c.casttarget = tt.oid\n"
4867  " LEFT JOIN pg_catalog.pg_namespace nt\n"
4868  " ON nt.oid = tt.typnamespace\n");
4869 
4870  if (verbose)
4871  appendPQExpBufferStr(&buf,
4872  " LEFT JOIN pg_catalog.pg_description d\n"
4873  " ON d.classoid = c.tableoid AND d.objoid = "
4874  "c.oid AND d.objsubid = 0\n");
4875 
4876  appendPQExpBufferStr(&buf, "WHERE ( (true");
4877 
4878  /*
4879  * Match name pattern against either internal or external name of either
4880  * castsource or casttarget
4881  */
4882  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4883  "ns.nspname", "ts.typname",
4884  "pg_catalog.format_type(ts.oid, NULL)",
4885  "pg_catalog.pg_type_is_visible(ts.oid)");
4886 
4887  appendPQExpBufferStr(&buf, ") OR (true");
4888 
4889  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4890  "nt.nspname", "tt.typname",
4891  "pg_catalog.format_type(tt.oid, NULL)",
4892  "pg_catalog.pg_type_is_visible(tt.oid)");
4893 
4894  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
4895 
4896  res = PSQLexec(buf.data);
4897  termPQExpBuffer(&buf);
4898  if (!res)
4899  return false;
4900 
4901  myopt.nullPrint = NULL;
4902  myopt.title = _("List of casts");
4903  myopt.translate_header = true;
4904  myopt.translate_columns = translate_columns;
4905  myopt.n_translate_columns = lengthof(translate_columns);
4906 
4907  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4908 
4909  PQclear(res);
4910  return true;
4911 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listCollations()

bool listCollations ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 4919 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4920 {
4922  PGresult *res;
4923  printQueryOpt myopt = pset.popt;
4924  static const bool translate_columns[] = {false, false, false, false, false, true, false};
4925 
4926  if (pset.sversion < 90100)
4927  {
4928  char sverbuf[32];
4929 
4930  pg_log_error("The server (version %s) does not support collations.",
4932  sverbuf, sizeof(sverbuf)));
4933  return true;
4934  }
4935 
4936  initPQExpBuffer(&buf);
4937 
4938  printfPQExpBuffer(&buf,
4939  "SELECT n.nspname AS \"%s\",\n"
4940  " c.collname AS \"%s\",\n"
4941  " c.collcollate AS \"%s\",\n"
4942  " c.collctype AS \"%s\"",
4943  gettext_noop("Schema"),
4944  gettext_noop("Name"),
4945  gettext_noop("Collate"),
4946  gettext_noop("Ctype"));
4947 
4948  if (pset.sversion >= 100000)
4949  appendPQExpBuffer(&buf,
4950  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
4951  gettext_noop("Provider"));
4952  else
4953  appendPQExpBuffer(&buf,
4954  ",\n 'libc' AS \"%s\"",
4955  gettext_noop("Provider"));
4956 
4957  if (pset.sversion >= 120000)
4958  appendPQExpBuffer(&buf,
4959  ",\n CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4960  gettext_noop("yes"), gettext_noop("no"),
4961  gettext_noop("Deterministic?"));
4962  else
4963  appendPQExpBuffer(&buf,
4964  ",\n '%s' AS \"%s\"",
4965  gettext_noop("yes"),
4966  gettext_noop("Deterministic?"));
4967 
4968  if (verbose)
4969  appendPQExpBuffer(&buf,
4970  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4971  gettext_noop("Description"));
4972 
4973  appendPQExpBufferStr(&buf,
4974  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4975  "WHERE n.oid = c.collnamespace\n");
4976 
4977  if (!showSystem && !pattern)
4978  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4979  " AND n.nspname <> 'information_schema'\n");
4980 
4981  /*
4982  * Hide collations that aren't usable in the current database's encoding.
4983  * If you think to change this, note that pg_collation_is_visible rejects
4984  * unusable collations, so you will need to hack name pattern processing
4985  * somehow to avoid inconsistent behavior.
4986  */
4987  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4988 
4989  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4990  "n.nspname", "c.collname", NULL,
4991  "pg_catalog.pg_collation_is_visible(c.oid)");
4992 
4993  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4994 
4995  res = PSQLexec(buf.data);
4996  termPQExpBuffer(&buf);
4997  if (!res)
4998  return false;
4999 
5000  myopt.nullPrint = NULL;
5001  myopt.title = _("List of collations");
5002  myopt.translate_header = true;
5003  myopt.translate_columns = translate_columns;
5004  myopt.n_translate_columns = lengthof(translate_columns);
5005 
5006  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5007 
5008  PQclear(res);
5009  return true;
5010 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listConversions()

bool listConversions ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 4567 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4568 {
4570  PGresult *res;
4571  printQueryOpt myopt = pset.popt;
4572  static const bool translate_columns[] =
4573  {false, false, false, false, true, false};
4574 
4575  initPQExpBuffer(&buf);
4576 
4577  printfPQExpBuffer(&buf,
4578  "SELECT n.nspname AS \"%s\",\n"
4579  " c.conname AS \"%s\",\n"
4580  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4581  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4582  " CASE WHEN c.condefault THEN '%s'\n"
4583  " ELSE '%s' END AS \"%s\"",
4584  gettext_noop("Schema"),
4585  gettext_noop("Name"),
4586  gettext_noop("Source"),
4587  gettext_noop("Destination"),
4588  gettext_noop("yes"), gettext_noop("no"),
4589  gettext_noop("Default?"));
4590 
4591  if (verbose)
4592  appendPQExpBuffer(&buf,
4593  ",\n d.description AS \"%s\"",
4594  gettext_noop("Description"));
4595 
4596  appendPQExpBufferStr(&buf,
4597  "\nFROM pg_catalog.pg_conversion c\n"
4598  " JOIN pg_catalog.pg_namespace n "
4599  "ON n.oid = c.connamespace\n");
4600 
4601  if (verbose)
4602  appendPQExpBufferStr(&buf,
4603  "LEFT JOIN pg_catalog.pg_description d "
4604  "ON d.classoid = c.tableoid\n"
4605  " AND d.objoid = c.oid "
4606  "AND d.objsubid = 0\n");
4607 
4608  appendPQExpBufferStr(&buf, "WHERE true\n");
4609 
4610  if (!showSystem && !pattern)
4611  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4612  " AND n.nspname <> 'information_schema'\n");
4613 
4614  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4615  "n.nspname", "c.conname", NULL,
4616  "pg_catalog.pg_conversion_is_visible(c.oid)");
4617 
4618  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4619 
4620  res = PSQLexec(buf.data);
4621  termPQExpBuffer(&buf);
4622  if (!res)
4623  return false;
4624 
4625  myopt.nullPrint = NULL;
4626  myopt.title = _("List of conversions");
4627  myopt.translate_header = true;
4628  myopt.translate_columns = translate_columns;
4629  myopt.n_translate_columns = lengthof(translate_columns);
4630 
4631  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4632 
4633  PQclear(res);
4634  return true;
4635 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listDbRoleSettings()

bool listDbRoleSettings ( const char *  pattern,
const char *  pattern2 
)

Definition at line 3910 of file describe.c.

References _, appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), PQntuples(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::quiet, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

3911 {
3913  PGresult *res;
3914  printQueryOpt myopt = pset.popt;
3915  bool havewhere;
3916 
3917  if (pset.sversion < 90000)
3918  {
3919  char sverbuf[32];
3920 
3921  pg_log_error("The server (version %s) does not support per-database role settings.",
3923  sverbuf, sizeof(sverbuf)));
3924  return true;
3925  }
3926 
3927  initPQExpBuffer(&buf);
3928 
3929  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3930  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3931  "FROM pg_catalog.pg_db_role_setting s\n"
3932  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3933  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3934  gettext_noop("Role"),
3935  gettext_noop("Database"),
3936  gettext_noop("Settings"));
3937  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3938  NULL, "r.rolname", NULL, NULL);
3939  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3940  NULL, "d.datname", NULL, NULL);
3941  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3942 
3943  res = PSQLexec(buf.data);
3944  termPQExpBuffer(&buf);
3945  if (!res)
3946  return false;
3947 
3948  /*
3949  * Most functions in this file are content to print an empty table when
3950  * there are no matching objects. We intentionally deviate from that
3951  * here, but only in !quiet mode, because of the possibility that the user
3952  * is confused about what the two pattern arguments mean.
3953  */
3954  if (PQntuples(res) == 0 && !pset.quiet)
3955  {
3956  if (pattern && pattern2)
3957  pg_log_error("Did not find any settings for role \"%s\" and database \"%s\".",
3958  pattern, pattern2);
3959  else if (pattern)
3960  pg_log_error("Did not find any settings for role \"%s\".",
3961  pattern);
3962  else
3963  pg_log_error("Did not find any settings.");
3964  }
3965  else
3966  {
3967  myopt.nullPrint = NULL;
3968  myopt.title = _("List of settings");
3969  myopt.translate_header = true;
3970 
3971  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3972  }
3973 
3974  PQclear(res);
3975  return true;
3976 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1255 of file describe.c.

References _, appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

1256 {
1258  PGresult *res;
1259  printQueryOpt myopt = pset.popt;
1260  static const bool translate_columns[] = {false, false, true, false};
1261 
1262  if (pset.sversion < 90000)
1263  {
1264  char sverbuf[32];
1265 
1266  pg_log_error("The server (version %s) does not support altering default privileges.",
1268  sverbuf, sizeof(sverbuf)));
1269  return true;
1270  }
1271 
1272  initPQExpBuffer(&buf);
1273 
1274  printfPQExpBuffer(&buf,
1275  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1276  " n.nspname AS \"%s\",\n"
1277  " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1278  " ",
1279  gettext_noop("Owner"),
1280  gettext_noop("Schema"),
1281  DEFACLOBJ_RELATION,
1282  gettext_noop("table"),
1283  DEFACLOBJ_SEQUENCE,
1284  gettext_noop("sequence"),
1285  DEFACLOBJ_FUNCTION,
1286  gettext_noop("function"),
1287  DEFACLOBJ_TYPE,
1288  gettext_noop("type"),
1289  DEFACLOBJ_NAMESPACE,
1290  gettext_noop("schema"),
1291  gettext_noop("Type"));
1292 
1293  printACLColumn(&buf, "d.defaclacl");
1294 
1295  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1296  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1297 
1298  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1299  NULL,
1300  "n.nspname",
1301  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1302  NULL);
1303 
1304  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1305 
1306  res = PSQLexec(buf.data);
1307  if (!res)
1308  {
1309  termPQExpBuffer(&buf);
1310  return false;
1311  }
1312 
1313  myopt.nullPrint = NULL;
1314  printfPQExpBuffer(&buf, _("Default access privileges"));
1315  myopt.title = buf.data;
1316  myopt.translate_header = true;
1317  myopt.translate_columns = translate_columns;
1318  myopt.n_translate_columns = lengthof(translate_columns);
1319 
1320  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1321 
1322  termPQExpBuffer(&buf);
1323  PQclear(res);
1324  return true;
1325 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listDomains()

bool listDomains ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 4481 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4482 {
4484  PGresult *res;
4485  printQueryOpt myopt = pset.popt;
4486 
4487  initPQExpBuffer(&buf);
4488 
4489  printfPQExpBuffer(&buf,
4490  "SELECT n.nspname as \"%s\",\n"
4491  " t.typname as \"%s\",\n"
4492  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
4493  gettext_noop("Schema"),
4494  gettext_noop("Name"),
4495  gettext_noop("Type"));
4496 
4497  if (pset.sversion >= 90100)
4498  appendPQExpBuffer(&buf,
4499  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4500  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
4501  gettext_noop("Collation"));
4502  appendPQExpBuffer(&buf,
4503  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4504  " t.typdefault as \"%s\",\n"
4505  " pg_catalog.array_to_string(ARRAY(\n"
4506  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4507  " ), ' ') as \"%s\"",
4508  gettext_noop("Nullable"),
4509  gettext_noop("Default"),
4510  gettext_noop("Check"));
4511 
4512  if (verbose)
4513  {
4514  if (pset.sversion >= 90200)
4515  {
4516  appendPQExpBufferStr(&buf, ",\n ");
4517  printACLColumn(&buf, "t.typacl");
4518  }
4519  appendPQExpBuffer(&buf,
4520  ",\n d.description as \"%s\"",
4521  gettext_noop("Description"));
4522  }
4523 
4524  appendPQExpBufferStr(&buf,
4525  "\nFROM pg_catalog.pg_type t\n"
4526  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4527 
4528  if (verbose)
4529  appendPQExpBufferStr(&buf,
4530  " LEFT JOIN pg_catalog.pg_description d "
4531  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4532  "AND d.objsubid = 0\n");
4533 
4534  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
4535 
4536  if (!showSystem && !pattern)
4537  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4538  " AND n.nspname <> 'information_schema'\n");
4539 
4540  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4541  "n.nspname", "t.typname", NULL,
4542  "pg_catalog.pg_type_is_visible(t.oid)");
4543 
4544  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4545 
4546  res = PSQLexec(buf.data);
4547  termPQExpBuffer(&buf);
4548  if (!res)
4549  return false;
4550 
4551  myopt.nullPrint = NULL;
4552  myopt.title = _("List of domains");
4553  myopt.translate_header = true;
4554 
4555  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4556 
4557  PQclear(res);
4558  return true;
4559 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listEventTriggers()

bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 4643 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4644 {
4646  PGresult *res;
4647  printQueryOpt myopt = pset.popt;
4648  static const bool translate_columns[] =
4649  {false, false, false, true, false, false, false};
4650 
4651  initPQExpBuffer(&buf);
4652 
4653  printfPQExpBuffer(&buf,
4654  "SELECT evtname as \"%s\", "
4655  "evtevent as \"%s\", "
4656  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4657  " case evtenabled when 'O' then '%s'"
4658  " when 'R' then '%s'"
4659  " when 'A' then '%s'"
4660  " when 'D' then '%s' end as \"%s\",\n"
4661  " e.evtfoid::pg_catalog.regproc as \"%s\", "
4662  "pg_catalog.array_to_string(array(select x"
4663  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4664  gettext_noop("Name"),
4665  gettext_noop("Event"),
4666  gettext_noop("Owner"),
4667  gettext_noop("enabled"),
4668  gettext_noop("replica"),
4669  gettext_noop("always"),
4670  gettext_noop("disabled"),
4671  gettext_noop("Enabled"),
4672  gettext_noop("Function"),
4673  gettext_noop("Tags"));
4674  if (verbose)
4675  appendPQExpBuffer(&buf,
4676  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4677  gettext_noop("Description"));
4678  appendPQExpBufferStr(&buf,
4679  "\nFROM pg_catalog.pg_event_trigger e ");
4680 
4681  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4682  NULL, "evtname", NULL, NULL);
4683 
4684  appendPQExpBufferStr(&buf, "ORDER BY 1");
4685 
4686  res = PSQLexec(buf.data);
4687  termPQExpBuffer(&buf);
4688  if (!res)
4689  return false;
4690 
4691  myopt.nullPrint = NULL;
4692  myopt.title = _("List of event triggers");
4693  myopt.translate_header = true;
4694  myopt.translate_columns = translate_columns;
4695  myopt.n_translate_columns = lengthof(translate_columns);
4696 
4697  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4698 
4699  PQclear(res);
4700  return true;
4701 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listExtendedStats()

bool listExtendedStats ( const char *  pattern)

Definition at line 4709 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4710 {
4712  PGresult *res;
4713  printQueryOpt myopt = pset.popt;
4714 
4715  if (pset.sversion < 100000)
4716  {
4717  char sverbuf[32];
4718 
4719  pg_log_error("The server (version %s) does not support extended statistics.",
4721  sverbuf, sizeof(sverbuf)));
4722  return true;
4723  }
4724 
4725  initPQExpBuffer(&buf);
4726  printfPQExpBuffer(&buf,
4727  "SELECT \n"
4728  "es.stxnamespace::pg_catalog.regnamespace::text AS \"%s\", \n"
4729  "es.stxname AS \"%s\", \n",
4730  gettext_noop("Schema"),
4731  gettext_noop("Name"));
4732 
4733  if (pset.sversion >= 140000)
4734  appendPQExpBuffer(&buf,
4735  "pg_catalog.format('%%s FROM %%s', \n"
4736  " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4737  " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4738  gettext_noop("Definition"));
4739  else
4740  appendPQExpBuffer(&buf,
4741  "pg_catalog.format('%%s FROM %%s', \n"
4742  " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4743  " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4744  " JOIN pg_catalog.pg_attribute a \n"
4745  " ON (es.stxrelid = a.attrelid \n"
4746  " AND a.attnum = s.attnum \n"
4747  " AND NOT a.attisdropped)), \n"
4748  "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4749  gettext_noop("Definition"));
4750 
4751  appendPQExpBuffer(&buf,
4752  ",\nCASE WHEN 'd' = any(es.stxkind) THEN 'defined' \n"
4753  "END AS \"%s\", \n"
4754  "CASE WHEN 'f' = any(es.stxkind) THEN 'defined' \n"
4755  "END AS \"%s\"",
4756  gettext_noop("Ndistinct"),
4757  gettext_noop("Dependencies"));
4758 
4759  /*
4760  * Include the MCV statistics kind.
4761  */
4762  if (pset.sversion >= 120000)
4763  {
4764  appendPQExpBuffer(&buf,
4765  ",\nCASE WHEN 'm' = any(es.stxkind) THEN 'defined' \n"
4766  "END AS \"%s\" ",
4767  gettext_noop("MCV"));
4768  }
4769 
4770  appendPQExpBufferStr(&buf,
4771  " \nFROM pg_catalog.pg_statistic_ext es \n");
4772 
4773  processSQLNamePattern(pset.db, &buf, pattern,
4774  false, false,
4775  "es.stxnamespace::pg_catalog.regnamespace::text", "es.stxname",
4776  NULL, "pg_catalog.pg_statistics_obj_is_visible(es.oid)");
4777 
4778  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4779 
4780  res = PSQLexec(buf.data);
4781  termPQExpBuffer(&buf);
4782  if (!res)
4783  return false;
4784 
4785  myopt.nullPrint = NULL;
4786  myopt.title = _("List of extended statistics");
4787  myopt.translate_header = true;
4788 
4789  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4790 
4791  PQclear(res);
4792  return true;
4793 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listExtensionContents()

bool listExtensionContents ( const char *  pattern)

Definition at line 6031 of file describe.c.

References appendPQExpBufferStr(), buf, cancel_pressed, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), i, initPQExpBuffer(), listOneExtensionContents(), pg_log_error, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::quiet, _psqlSettings::sversion, and termPQExpBuffer().

Referenced by exec_command_d().

6032 {
6034  PGresult *res;
6035  int i;
6036 
6037  if (pset.sversion < 90100)
6038  {
6039  char sverbuf[32];
6040 
6041  pg_log_error("The server (version %s) does not support extensions.",
6043  sverbuf, sizeof(sverbuf)));
6044  return true;
6045  }
6046 
6047  initPQExpBuffer(&buf);
6048  printfPQExpBuffer(&buf,
6049  "SELECT e.extname, e.oid\n"
6050  "FROM pg_catalog.pg_extension e\n");
6051 
6052  processSQLNamePattern(pset.db, &buf, pattern,
6053  false, false,
6054  NULL, "e.extname", NULL,
6055  NULL);
6056 
6057  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6058 
6059  res = PSQLexec(buf.data);
6060  termPQExpBuffer(&buf);
6061  if (!res)
6062  return false;
6063 
6064  if (PQntuples(res) == 0)
6065  {
6066  if (!pset.quiet)
6067  {
6068  if (pattern)
6069  pg_log_error("Did not find any extension named \"%s\".",
6070  pattern);
6071  else
6072  pg_log_error("Did not find any extensions.");
6073  }
6074  PQclear(res);
6075  return false;
6076  }
6077 
6078  for (i = 0; i < PQntuples(res); i++)
6079  {
6080  const char *extname;
6081  const char *oid;
6082 
6083  extname = PQgetvalue(res, i, 0);
6084  oid = PQgetvalue(res, i, 1);
6085 
6086  if (!listOneExtensionContents(extname, oid))
6087  {
6088  PQclear(res);
6089  return false;
6090  }
6091  if (cancel_pressed)
6092  {
6093  PQclear(res);
6094  return false;
6095  }
6096  }
6097 
6098  PQclear(res);
6099  return true;
6100 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:32
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3642
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3248
static char * buf
Definition: pg_test_fsync.c:68
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:6103
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
void PQclear(PGresult *res)
Definition: fe-exec.c:694
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listExtensions()

bool listExtensions ( const char *  pattern)

Definition at line 5974 of file describe.c.

References _, appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

5975 {
5977  PGresult *res;
5978  printQueryOpt myopt = pset.popt;
5979 
5980  if (pset.sversion < 90100)
5981  {
5982  char sverbuf[32];
5983 
5984  pg_log_error("The server (version %s) does not support extensions.",
5986  sverbuf, sizeof(sverbuf)));
5987  return true;
5988  }
5989 
5990  initPQExpBuffer(&buf);
5991  printfPQExpBuffer(&buf,
5992  "SELECT e.extname AS \"%s\", "
5993  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
5994  "FROM pg_catalog.pg_extension e "
5995  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
5996  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
5997  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
5998  gettext_noop("Name"),
5999  gettext_noop("Version"),
6000  gettext_noop("Schema"),
6001  gettext_noop("Description"));
6002 
6003  processSQLNamePattern(pset.db, &buf, pattern,
6004  false, false,
6005  NULL, "e.extname", NULL,
6006  NULL);
6007 
6008  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6009 
6010  res = PSQLexec(buf.data);
6011  termPQExpBuffer(&buf);
6012  if (!res)
6013  return false;
6014 
6015  myopt.nullPrint = NULL;
6016  myopt.title = _("List of installed extensions");
6017  myopt.translate_header = true;
6018 
6019  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6020 
6021  PQclear(res);
6022  return true;
6023 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 5670 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

5671 {
5673  PGresult *res;
5674  printQueryOpt myopt = pset.popt;
5675 
5676  if (pset.sversion < 80400)
5677  {
5678  char sverbuf[32];
5679 
5680  pg_log_error("The server (version %s) does not support foreign-data wrappers.",
5682  sverbuf, sizeof(sverbuf)));
5683  return true;
5684  }
5685 
5686  initPQExpBuffer(&buf);
5687  printfPQExpBuffer(&buf,
5688  "SELECT fdw.fdwname AS \"%s\",\n"
5689  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
5690  gettext_noop("Name"),
5691  gettext_noop("Owner"));
5692  if (pset.sversion >= 90100)
5693  appendPQExpBuffer(&buf,
5694  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
5695  gettext_noop("Handler"));
5696  appendPQExpBuffer(&buf,
5697  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5698  gettext_noop("Validator"));
5699 
5700  if (verbose)
5701  {
5702  appendPQExpBufferStr(&buf, ",\n ");
5703  printACLColumn(&buf, "fdwacl");
5704  appendPQExpBuffer(&buf,
5705  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5706  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5707  " pg_catalog.quote_ident(option_name) || ' ' || "
5708  " pg_catalog.quote_literal(option_value) FROM "
5709  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5710  " END AS \"%s\"",
5711  gettext_noop("FDW options"));
5712 
5713  if (pset.sversion >= 90100)
5714  appendPQExpBuffer(&buf,
5715  ",\n d.description AS \"%s\" ",
5716  gettext_noop("Description"));
5717  }
5718 
5719  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
5720 
5721  if (verbose && pset.sversion >= 90100)
5722  appendPQExpBufferStr(&buf,
5723  "LEFT JOIN pg_catalog.pg_description d\n"
5724  " ON d.classoid = fdw.tableoid "
5725  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5726 
5727  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5728  NULL, "fdwname", NULL, NULL);
5729 
5730  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5731 
5732  res = PSQLexec(buf.data);
5733  termPQExpBuffer(&buf);
5734  if (!res)
5735  return false;
5736 
5737  myopt.nullPrint = NULL;
5738  myopt.title = _("List of foreign-data wrappers");
5739  myopt.translate_header = true;
5740 
5741  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5742 
5743  PQclear(res);
5744  return true;
5745 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listForeignServers()

bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 5753 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

5754 {
5756  PGresult *res;
5757  printQueryOpt myopt = pset.popt;
5758 
5759  if (pset.sversion < 80400)
5760  {
5761  char sverbuf[32];
5762 
5763  pg_log_error("The server (version %s) does not support foreign servers.",
5765  sverbuf, sizeof(sverbuf)));
5766  return true;
5767  }
5768 
5769  initPQExpBuffer(&buf);
5770  printfPQExpBuffer(&buf,
5771  "SELECT s.srvname AS \"%s\",\n"
5772  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5773  " f.fdwname AS \"%s\"",
5774  gettext_noop("Name"),
5775  gettext_noop("Owner"),
5776  gettext_noop("Foreign-data wrapper"));
5777 
5778  if (verbose)
5779  {
5780  appendPQExpBufferStr(&buf, ",\n ");
5781  printACLColumn(&buf, "s.srvacl");
5782  appendPQExpBuffer(&buf,
5783  ",\n"
5784  " s.srvtype AS \"%s\",\n"
5785  " s.srvversion AS \"%s\",\n"
5786  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5787  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5788  " pg_catalog.quote_ident(option_name) || ' ' || "
5789  " pg_catalog.quote_literal(option_value) FROM "
5790  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
5791  " END AS \"%s\",\n"
5792  " d.description AS \"%s\"",
5793  gettext_noop("Type"),
5794  gettext_noop("Version"),
5795  gettext_noop("FDW options"),
5796  gettext_noop("Description"));
5797  }
5798 
5799  appendPQExpBufferStr(&buf,
5800  "\nFROM pg_catalog.pg_foreign_server s\n"
5801  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
5802 
5803  if (verbose)
5804  appendPQExpBufferStr(&buf,
5805  "LEFT JOIN pg_catalog.pg_description d\n "
5806  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
5807  "AND d.objsubid = 0\n");
5808 
5809  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5810  NULL, "s.srvname", NULL, NULL);
5811 
5812  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5813 
5814  res = PSQLexec(buf.data);
5815  termPQExpBuffer(&buf);
5816  if (!res)
5817  return false;
5818 
5819  myopt.nullPrint = NULL;
5820  myopt.title = _("List of foreign servers");
5821  myopt.translate_header = true;
5822 
5823  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5824 
5825  PQclear(res);
5826  return true;
5827 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listForeignTables()

bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 5896 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

5897 {
5899  PGresult *res;
5900  printQueryOpt myopt = pset.popt;
5901 
5902  if (pset.sversion < 90100)
5903  {
5904  char sverbuf[32];
5905 
5906  pg_log_error("The server (version %s) does not support foreign tables.",
5908  sverbuf, sizeof(sverbuf)));
5909  return true;
5910  }
5911 
5912  initPQExpBuffer(&buf);
5913  printfPQExpBuffer(&buf,
5914  "SELECT n.nspname AS \"%s\",\n"
5915  " c.relname AS \"%s\",\n"
5916  " s.srvname AS \"%s\"",
5917  gettext_noop("Schema"),
5918  gettext_noop("Table"),
5919  gettext_noop("Server"));
5920 
5921  if (verbose)
5922  appendPQExpBuffer(&buf,
5923  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
5924  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5925  " pg_catalog.quote_ident(option_name) || ' ' || "
5926  " pg_catalog.quote_literal(option_value) FROM "
5927  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
5928  " END AS \"%s\",\n"
5929  " d.description AS \"%s\"",
5930  gettext_noop("FDW options"),
5931  gettext_noop("Description"));
5932 
5933  appendPQExpBufferStr(&buf,
5934  "\nFROM pg_catalog.pg_foreign_table ft\n"
5935  " INNER JOIN pg_catalog.pg_class c"
5936  " ON c.oid = ft.ftrelid\n"
5937  " INNER JOIN pg_catalog.pg_namespace n"
5938  " ON n.oid = c.relnamespace\n"
5939  " INNER JOIN pg_catalog.pg_foreign_server s"
5940  " ON s.oid = ft.ftserver\n");
5941  if (verbose)
5942  appendPQExpBufferStr(&buf,
5943  " LEFT JOIN pg_catalog.pg_description d\n"
5944  " ON d.classoid = c.tableoid AND "
5945  "d.objoid = c.oid AND d.objsubid = 0\n");
5946 
5947  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5948  "n.nspname", "c.relname", NULL,
5949  "pg_catalog.pg_table_is_visible(c.oid)");
5950 
5951  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5952 
5953  res = PSQLexec(buf.data);
5954  termPQExpBuffer(&buf);
5955  if (!res)
5956  return false;
5957 
5958  myopt.nullPrint = NULL;
5959  myopt.title = _("List of foreign tables");
5960  myopt.translate_header = true;
5961 
5962  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5963 
5964  PQclear(res);
5965  return true;
5966 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listLanguages()

bool listLanguages ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 4406 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4407 {
4409  PGresult *res;
4410  printQueryOpt myopt = pset.popt;
4411 
4412  initPQExpBuffer(&buf);
4413 
4414  printfPQExpBuffer(&buf,
4415  "SELECT l.lanname AS \"%s\",\n",
4416  gettext_noop("Name"));
4417  if (pset.sversion >= 80300)
4418  appendPQExpBuffer(&buf,
4419  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
4420  gettext_noop("Owner"));
4421 
4422  appendPQExpBuffer(&buf,
4423  " l.lanpltrusted AS \"%s\"",
4424  gettext_noop("Trusted"));
4425 
4426  if (verbose)
4427  {
4428  appendPQExpBuffer(&buf,
4429  ",\n NOT l.lanispl AS \"%s\",\n"
4430  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4431  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n ",
4432  gettext_noop("Internal language"),
4433  gettext_noop("Call handler"),
4434  gettext_noop("Validator"));
4435  if (pset.sversion >= 90000)
4436  appendPQExpBuffer(&buf, "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4437  gettext_noop("Inline handler"));
4438  printACLColumn(&buf, "l.lanacl");
4439  }
4440 
4441  appendPQExpBuffer(&buf,
4442  ",\n d.description AS \"%s\""
4443  "\nFROM pg_catalog.pg_language l\n"
4444  "LEFT JOIN pg_catalog.pg_description d\n"
4445  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4446  " AND d.objsubid = 0\n",
4447  gettext_noop("Description"));
4448 
4449  if (pattern)
4450  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4451  NULL, "l.lanname", NULL, NULL);
4452 
4453  if (!showSystem && !pattern)
4454  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
4455 
4456 
4457  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4458 
4459  res = PSQLexec(buf.data);
4460  termPQExpBuffer(&buf);
4461  if (!res)
4462  return false;
4463 
4464  myopt.nullPrint = NULL;
4465  myopt.title = _("List of languages");
4466  myopt.translate_header = true;
4467 
4468  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4469 
4470  PQclear(res);
4471  return true;
4472 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6476
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listOperatorClasses()

bool listOperatorClasses ( const char *  access_method_pattern,
const char *  opclass_pattern,
bool  verbose 
)

Definition at line 6495 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

6497 {
6499  PGresult *res;
6500  printQueryOpt myopt = pset.popt;
6501  bool have_where = false;
6502  static const bool translate_columns[] = {false, false, false, false, false, false, false};
6503 
6504  initPQExpBuffer(&buf);
6505 
6506  printfPQExpBuffer(&buf,
6507  "SELECT\n"
6508  " am.amname AS \"%s\",\n"
6509  " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6510  " CASE\n"
6511  " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6512  " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6513  " ELSE NULL\n"
6514  " END AS \"%s\",\n"
6515  " CASE\n"
6516  " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6517  " THEN pg_catalog.format('%%I', c.opcname)\n"
6518  " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6519  " END AS \"%s\",\n"
6520  " (CASE WHEN c.opcdefault\n"
6521  " THEN '%s'\n"
6522  " ELSE '%s'\n"
6523  " END) AS \"%s\"",
6524  gettext_noop("AM"),
6525  gettext_noop("Input type"),
6526  gettext_noop("Storage type"),
6527  gettext_noop("Operator class"),
6528  gettext_noop("yes"),
6529  gettext_noop("no"),
6530  gettext_noop("Default?"));
6531  if (verbose)
6532  appendPQExpBuffer(&buf,
6533  ",\n CASE\n"
6534  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6535  " THEN pg_catalog.format('%%I', of.opfname)\n"
6536  " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
6537  " END AS \"%s\",\n"
6538  " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6539  gettext_noop("Operator family"),
6540  gettext_noop("Owner"));
6541  appendPQExpBufferStr(&buf,
6542  "\nFROM pg_catalog.pg_opclass c\n"
6543  " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6544  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6545  " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6546  " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
6547  if (verbose)
6548  appendPQExpBufferStr(&buf,
6549  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6550  " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6551 
6552  if (access_method_pattern)
6553  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6554  false, false, NULL, "am.amname", NULL, NULL);
6555  if (type_pattern)
6556  {
6557  /* Match type name pattern against either internal or external name */
6558  processSQLNamePattern(pset.db, &buf, type_pattern, have_where, false,
6559  "tn.nspname", "t.typname",
6560  "pg_catalog.format_type(t.oid, NULL)",
6561  "pg_catalog.pg_type_is_visible(t.oid)");
6562  }
6563 
6564  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
6565  res = PSQLexec(buf.data);
6566  termPQExpBuffer(&buf);
6567  if (!res)
6568  return false;
6569 
6570  myopt.nullPrint = NULL;
6571  myopt.title = _("List of operator classes");
6572  myopt.translate_header = true;
6573  myopt.translate_columns = translate_columns;
6574  myopt.n_translate_columns = lengthof(translate_columns);
6575 
6576  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6577 
6578  PQclear(res);
6579  return true;
6580 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listOperatorFamilies()

bool listOperatorFamilies ( const char *  access_method_pattern,
const char *  opclass_pattern,
bool  verbose 
)

Definition at line 6589 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

6591 {
6593  PGresult *res;
6594  printQueryOpt myopt = pset.popt;
6595  bool have_where = false;
6596  static const bool translate_columns[] = {false, false, false, false};
6597 
6598  initPQExpBuffer(&buf);
6599 
6600  printfPQExpBuffer(&buf,
6601  "SELECT\n"
6602  " am.amname AS \"%s\",\n"
6603  " CASE\n"
6604  " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
6605  " THEN pg_catalog.format('%%I', f.opfname)\n"
6606  " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
6607  " END AS \"%s\",\n"
6608  " (SELECT\n"
6609  " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
6610  " FROM pg_catalog.pg_opclass oc\n"
6611  " WHERE oc.opcfamily = f.oid) \"%s\"",
6612  gettext_noop("AM"),
6613  gettext_noop("Operator family"),
6614  gettext_noop("Applicable types"));
6615  if (verbose)
6616  appendPQExpBuffer(&buf,
6617  ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
6618  gettext_noop("Owner"));
6619  appendPQExpBufferStr(&buf,
6620  "\nFROM pg_catalog.pg_opfamily f\n"
6621  " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
6622  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
6623 
6624  if (access_method_pattern)
6625  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6626  false, false, NULL, "am.amname", NULL, NULL);
6627  if (type_pattern)
6628  {
6629  appendPQExpBuffer(&buf,
6630  " %s EXISTS (\n"
6631  " SELECT 1\n"
6632  " FROM pg_catalog.pg_type t\n"
6633  " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
6634  " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
6635  " WHERE oc.opcfamily = f.oid\n",
6636  have_where ? "AND" : "WHERE");
6637  /* Match type name pattern against either internal or external name */
6638  processSQLNamePattern(pset.db, &buf, type_pattern, true, false,
6639  "tn.nspname", "t.typname",
6640  "pg_catalog.format_type(t.oid, NULL)",
6641  "pg_catalog.pg_type_is_visible(t.oid)");
6642  appendPQExpBufferStr(&buf, " )\n");
6643  }
6644 
6645  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6646  res = PSQLexec(buf.data);
6647  termPQExpBuffer(&buf);
6648  if (!res)
6649  return false;
6650 
6651  myopt.nullPrint = NULL;
6652  myopt.title = _("List of operator families");
6653  myopt.translate_header = true;
6654  myopt.translate_columns = translate_columns;
6655  myopt.n_translate_columns = lengthof(translate_columns);
6656 
6657  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6658 
6659  PQclear(res);
6660  return true;
6661 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listOpFamilyFunctions()

bool listOpFamilyFunctions ( const char *  access_method_pattern,
const char *  family_pattern,
bool  verbose 
)

Definition at line 6758 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

6760 {
6762  PGresult *res;
6763  printQueryOpt myopt = pset.popt;
6764  bool have_where = false;
6765  static const bool translate_columns[] = {false, false, false, false, false, false};
6766 
6767  initPQExpBuffer(&buf);
6768 
6769  printfPQExpBuffer(&buf,
6770  "SELECT\n"
6771  " am.amname AS \"%s\",\n"
6772  " CASE\n"
6773  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6774  " THEN pg_catalog.format('%%I', of.opfname)\n"
6775  " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
6776  " END AS \"%s\",\n"
6777  " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
6778  " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
6779  " ap.amprocnum AS \"%s\"\n",
6780  gettext_noop("AM"),
6781  gettext_noop("Operator family"),
6782  gettext_noop("Registered left type"),
6783  gettext_noop("Registered right type"),
6784  gettext_noop("Number"));
6785 
6786  if (!verbose)
6787  appendPQExpBuffer(&buf,
6788  ", p.proname AS \"%s\"\n",
6789  gettext_noop("Function"));
6790  else
6791  appendPQExpBuffer(&buf,
6792  ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
6793  gettext_noop("Function"));
6794 
6795  appendPQExpBufferStr(&buf,
6796  "FROM pg_catalog.pg_amproc ap\n"
6797  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
6798  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
6799  " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
6800  " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
6801 
6802  if (access_method_pattern)
6803  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6804  false, false, NULL, "am.amname",
6805  NULL, NULL);
6806  if (family_pattern)
6807  processSQLNamePattern(pset.db, &buf, family_pattern, have_where, false,
6808  "ns.nspname", "of.opfname", NULL, NULL);
6809 
6810  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6811  " ap.amproclefttype = ap.amprocrighttype DESC,\n"
6812  " 3, 4, 5;");
6813 
6814  res = PSQLexec(buf.data);
6815  termPQExpBuffer(&buf);
6816  if (!res)
6817  return false;
6818 
6819  myopt.nullPrint = NULL;
6820  myopt.title = _("List of support functions of operator families");
6821  myopt.translate_header = true;
6822  myopt.translate_columns = translate_columns;
6823  myopt.n_translate_columns = lengthof(translate_columns);
6824 
6825  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6826 
6827  PQclear(res);
6828  return true;
6829 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listOpFamilyOperators()

bool listOpFamilyOperators ( const char *  accessMethod_pattern,
const char *  family_pattern,
bool  verbose 
)

Definition at line 6671 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

6673 {
6675  PGresult *res;
6676  printQueryOpt myopt = pset.popt;
6677  bool have_where = false;
6678 
6679  static const bool translate_columns[] = {false, false, false, false, false, false};
6680 
6681  initPQExpBuffer(&buf);
6682 
6683  printfPQExpBuffer(&buf,
6684  "SELECT\n"
6685  " am.amname AS \"%s\",\n"
6686  " CASE\n"
6687  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6688  " THEN pg_catalog.format('%%I', of.opfname)\n"
6689  " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
6690  " END AS \"%s\",\n"
6691  " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
6692  " o.amopstrategy AS \"%s\",\n"
6693  " CASE o.amoppurpose\n"
6694  " WHEN 'o' THEN '%s'\n"
6695  " WHEN 's' THEN '%s'\n"
6696  " END AS \"%s\"\n",
6697  gettext_noop("AM"),
6698  gettext_noop("Operator family"),
6699  gettext_noop("Operator"),
6700  gettext_noop("Strategy"),
6701  gettext_noop("ordering"),
6702  gettext_noop("search"),
6703  gettext_noop("Purpose"));
6704 
6705  if (verbose)
6706  appendPQExpBuffer(&buf,
6707  ", ofs.opfname AS \"%s\"\n",
6708  gettext_noop("Sort opfamily"));
6709  appendPQExpBufferStr(&buf,
6710  "FROM pg_catalog.pg_amop o\n"
6711  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
6712  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
6713  " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
6714  if (verbose)
6715  appendPQExpBufferStr(&buf,
6716  " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n");
6717 
6718  if (access_method_pattern)
6719  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6720  false, false, NULL, "am.amname",
6721  NULL, NULL);
6722 
6723  if (family_pattern)
6724  processSQLNamePattern(pset.db, &buf, family_pattern, have_where, false,
6725  "nsf.nspname", "of.opfname", NULL, NULL);
6726 
6727  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6728  " o.amoplefttype = o.amoprighttype DESC,\n"
6729  " pg_catalog.format_type(o.amoplefttype, NULL),\n"
6730  " pg_catalog.format_type(o.amoprighttype, NULL),\n"
6731  " o.amopstrategy;");
6732 
6733  res = PSQLexec(buf.data);
6734  termPQExpBuffer(&buf);
6735  if (!res)
6736  return false;
6737 
6738  myopt.nullPrint = NULL;
6739  myopt.title = _("List of operators of operator families");
6740  myopt.translate_header = true;
6741  myopt.translate_columns = translate_columns;
6742  myopt.n_translate_columns = lengthof(translate_columns);
6743 
6744  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6745 
6746  PQclear(res);
6747  return true;
6748 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listPartitionedTables()

bool listPartitionedTables ( const char *  reltypes,
const char *  pattern,
bool  verbose 
)

Definition at line 4210 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

4211 {
4212  bool showTables = strchr(reltypes, 't') != NULL;
4213  bool showIndexes = strchr(reltypes, 'i') != NULL;
4214  bool showNested = strchr(reltypes, 'n') != NULL;
4216  PQExpBufferData title;
4217  PGresult *res;
4218  printQueryOpt myopt = pset.popt;
4219  bool translate_columns[] = {false, false, false, false, false, false, false, false, false};
4220  const char *tabletitle;
4221  bool mixed_output = false;
4222 
4223  /*
4224  * Note: Declarative table partitioning is only supported as of Pg 10.0.
4225  */
4226  if (pset.sversion < 100000)
4227  {
4228  char sverbuf[32];
4229 
4230  pg_log_error("The server (version %s) does not support declarative table partitioning.",
4232  sverbuf, sizeof(sverbuf)));
4233  return true;
4234  }
4235 
4236  /* If no relation kind was selected, show them all */
4237  if (!showTables && !showIndexes)
4238  showTables = showIndexes = true;
4239 
4240  if (showIndexes && !showTables)
4241  tabletitle = _("List of partitioned indexes"); /* \dPi */
4242  else if (showTables && !showIndexes)
4243  tabletitle = _("List of partitioned tables"); /* \dPt */
4244  else
4245  {
4246  /* show all kinds */
4247  tabletitle = _("List of partitioned relations");
4248  mixed_output = true;
4249  }
4250 
4251  initPQExpBuffer(&buf);
4252 
4253  printfPQExpBuffer(&buf,
4254  "SELECT n.nspname as \"%s\",\n"
4255  " c.relname as \"%s\",\n"
4256  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4257  gettext_noop("Schema"),
4258  gettext_noop("Name"),
4259  gettext_noop("Owner"));
4260 
4261  if (mixed_output)
4262  {
4263  appendPQExpBuffer(&buf,
4264  ",\n CASE c.relkind"
4265  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
4266  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
4267  " END as \"%s\"",
4268  gettext_noop("partitioned table"),
4269  gettext_noop("partitioned index"),
4270  gettext_noop("Type"));
4271 
4272  translate_columns[3] = true;
4273  }
4274 
4275  if (showNested || pattern)
4276  appendPQExpBuffer(&buf,
4277  ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4278  gettext_noop("Parent name"));
4279 
4280  if (showIndexes)
4281  appendPQExpBuffer(&buf,
4282  ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4283  gettext_noop("Table"));
4284 
4285  if (verbose)
4286  {
4287  if (showNested)
4288  {
4289  appendPQExpBuffer(&buf,
4290  ",\n s.dps as \"%s\"",
4291  gettext_noop("Leaf partition size"));
4292  appendPQExpBuffer(&buf,
4293  ",\n s.tps as \"%s\"",
4294  gettext_noop("Total size"));
4295  }
4296  else
4297  /* Sizes of all partitions are considered in this case. */
4298  appendPQExpBuffer(&buf,
4299  ",\n s.tps as \"%s\"",
4300  gettext_noop("Total size"));
4301 
4302  appendPQExpBuffer(&buf,
4303  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4304  gettext_noop("Description"));
4305  }
4306 
4307  appendPQExpBufferStr(&buf,
4308  "\nFROM pg_catalog.pg_class c"
4309  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4310 
4311  if (showIndexes)
4312  appendPQExpBufferStr(&buf,
4313  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4314  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4315 
4316  if (showNested || pattern)
4317  appendPQExpBufferStr(&buf,
4318  "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4319 
4320  if (verbose)
4321  {
4322  if (pset.sversion < 120000)
4323  {
4324  appendPQExpBufferStr(&buf,
4325  ",\n LATERAL (WITH RECURSIVE d\n"
4326  " AS (SELECT inhrelid AS oid, 1 AS level\n"
4327  " FROM pg_catalog.pg_inherits\n"
4328  " WHERE inhparent = c.oid\n"
4329  " UNION ALL\n"
4330  " SELECT inhrelid, level + 1\n"
4331  " FROM pg_catalog.pg_inherits i\n"
4332  " JOIN d ON i.inhparent = d.oid)\n"
4333  " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4334  "d.oid))) AS tps,\n"
4335  " pg_catalog.pg_size_pretty(sum("
4336  "\n CASE WHEN d.level = 1"
4337  " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4338  " FROM d) s");
4339  }
4340  else
4341  {
4342  /* PostgreSQL 12 has pg_partition_tree function */
4343  appendPQExpBufferStr(&buf,
4344  ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4345  "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4346  "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4347  " ELSE 0 END)) AS dps"
4348  ",\n pg_catalog.pg_size_pretty(sum("
4349  "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4350  "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4351  }
4352  }
4353 
4354  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4355  if (showTables)
4356  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
4357  if (showIndexes)
4358  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
4359  appendPQExpBufferStr(&buf, "''"); /* dummy */
4360  appendPQExpBufferStr(&buf, ")\n");
4361 
4362  appendPQExpBufferStr(&buf, !showNested && !pattern ?
4363  " AND NOT c.relispartition\n" : "");
4364 
4365  if (!pattern)
4366  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4367  " AND n.nspname !~ '^pg_toast'\n"
4368  " AND n.nspname <> 'information_schema'\n");
4369 
4370  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4371  "n.nspname", "c.relname", NULL,
4372  "pg_catalog.pg_table_is_visible(c.oid)");
4373 
4374  appendPQExpBuffer(&buf, "ORDER BY \"Schema\", %s%s\"Name\";",
4375  mixed_output ? "\"Type\" DESC, " : "",
4376  showNested || pattern ? "\"Parent name\" NULLS FIRST, " : "");
4377 
4378  res = PSQLexec(buf.data);
4379  termPQExpBuffer(&buf);
4380  if (!res)
4381  return false;
4382 
4383  initPQExpBuffer(&title);
4384  appendPQExpBufferStr(&title, tabletitle);
4385 
4386  myopt.nullPrint = NULL;
4387  myopt.title = title.data;
4388  myopt.translate_header = true;
4389  myopt.translate_columns = translate_columns;
4390  myopt.n_translate_columns = lengthof(translate_columns);
4391 
4392  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4393 
4394  termPQExpBuffer(&title);
4395 
4396  PQclear(res);
4397  return true;
4398 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
static int verbose
#define CppAsString2(x)
Definition: c.h:289
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listPublications()

bool listPublications ( const char *  pattern)

Definition at line 6144 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command_d().

6145 {
6147  PGresult *res;
6148  printQueryOpt myopt = pset.popt;
6149  static const bool translate_columns[] = {false, false, false, false, false, false, false, false};
6150 
6151  if (pset.sversion < 100000)
6152  {
6153  char sverbuf[32];
6154 
6155  pg_log_error("The server (version %s) does not support publications.",
6157  sverbuf, sizeof(sverbuf)));
6158  return true;
6159  }
6160 
6161  initPQExpBuffer(&buf);
6162 
6163  printfPQExpBuffer(&buf,
6164  "SELECT pubname AS \"%s\",\n"
6165  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6166  " puballtables AS \"%s\",\n"
6167  " pubinsert AS \"%s\",\n"
6168  " pubupdate AS \"%s\",\n"
6169  " pubdelete AS \"%s\"",
6170  gettext_noop("Name"),
6171  gettext_noop("Owner"),
6172  gettext_noop("All tables"),
6173  gettext_noop("Inserts"),
6174  gettext_noop("Updates"),
6175  gettext_noop("Deletes"));
6176  if (pset.sversion >= 110000)
6177  appendPQExpBuffer(&buf,
6178  ",\n pubtruncate AS \"%s\"",
6179  gettext_noop("Truncates"));
6180  if (pset.sversion >= 130000)
6181  appendPQExpBuffer(&buf,
6182  ",\n pubviaroot AS \"%s\"",
6183  gettext_noop("Via root"));
6184 
6185  appendPQExpBufferStr(&buf,
6186  "\nFROM pg_catalog.pg_publication\n");
6187 
6188  processSQLNamePattern(pset.db, &buf, pattern, false, false,
6189  NULL, "pubname", NULL,
6190  NULL);
6191 
6192  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6193 
6194  res = PSQLexec(buf.data);
6195  termPQExpBuffer(&buf);
6196  if (!res)
6197  return false;
6198 
6199  myopt.nullPrint = NULL;
6200  myopt.title = _("List of publications");
6201  myopt.translate_header = true;
6202  myopt.translate_columns = translate_columns;
6203  myopt.n_translate_columns = lengthof(translate_columns);
6204 
6205  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6206 
6207  PQclear(res);
6208 
6209  return true;
6210 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:827
#define lengthof(array)
Definition: c.h:734
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:68
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3420
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:89
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:540

◆ listSchemas()

bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 5018 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

5019 {
5021  PGresult *res;
5022  printQueryOpt myopt = pset.popt;
5023 
5024  initPQExpBuffer(&buf);
5025  printfPQExpBuffer(&buf,
5026  "SELECT n.nspname AS \"%s\",\n"
5027  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5028  gettext_noop("Name"),
5029  gettext_noop("Owner"));
5030 
5031  if (verbose)
5032  {
5033  appendPQExpBufferStr(&buf, ",\n ");
5034  printACLColumn(&buf, "n.nspacl");
5035  appendPQExpBuffer(&buf,
5036  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5037  gettext_noop("Description"));
5038  }
5039 
5040  appendPQExpBufferStr(&buf,
5041  "\nFROM pg_catalog.pg_namespace n\n");
5042 
5043  if (!showSystem && !pattern)
5044  appendPQExpBufferStr(&buf,
5045  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5046 
5047  processSQLNamePattern(pset.db, &buf, pattern,
5048  !showSystem && !pattern, false,
5049  NULL, "n.nspname", NULL,
5050  NULL);
5051 
5052  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5053 
5054  res = PSQLexec(buf.data);
5055  termPQExpBuffer(&buf);
5056  if (!res)
5057  return false;
5058 
5059  myopt.nullPrint = NULL;
5060  myopt.title = _("List of schemas");
5061  myopt.translate_header = true;
5062 
5063  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5064 
5065  PQclear(res);
5066  return true;
5067 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:32
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1197
FILE * queryFout
Definition: settings.h:84