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 *pattern, bool verbose, bool showSystem)
 
bool describeTypes (const char *pattern, bool verbose, bool showSystem)
 
bool describeOperators (const char *pattern, 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 listEventTriggers (const char *pattern, bool verbose)
 
bool listPublications (const char *pattern)
 
bool describePublications (const char *pattern)
 
bool describeSubscriptions (const char *pattern, bool verbose)
 

Function Documentation

◆ describeAccessMethods()

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 148 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().

149 {
151  PGresult *res;
152  printQueryOpt myopt = pset.popt;
153  static const bool translate_columns[] = {false, true, false, false};
154 
155  if (pset.sversion < 90600)
156  {
157  char sverbuf[32];
158 
159  pg_log_error("The server (version %s) does not support access methods.",
161  sverbuf, sizeof(sverbuf)));
162  return true;
163  }
164 
165  initPQExpBuffer(&buf);
166 
167  printfPQExpBuffer(&buf,
168  "SELECT amname AS \"%s\",\n"
169  " CASE amtype"
170  " WHEN 'i' THEN '%s'"
171  " WHEN 't' THEN '%s'"
172  " END AS \"%s\"",
173  gettext_noop("Name"),
174  gettext_noop("Index"),
175  gettext_noop("Table"),
176  gettext_noop("Type"));
177 
178  if (verbose)
179  {
180  appendPQExpBuffer(&buf,
181  ",\n amhandler AS \"%s\",\n"
182  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
183  gettext_noop("Handler"),
184  gettext_noop("Description"));
185  }
186 
188  "\nFROM pg_catalog.pg_am\n");
189 
190  processSQLNamePattern(pset.db, &buf, pattern, false, false,
191  NULL, "amname", NULL,
192  NULL);
193 
194  appendPQExpBufferStr(&buf, "ORDER BY 1;");
195 
196  res = PSQLexec(buf.data);
197  termPQExpBuffer(&buf);
198  if (!res)
199  return false;
200 
201  myopt.nullPrint = NULL;
202  myopt.title = _("List of access methods");
203  myopt.translate_header = true;
204  myopt.translate_columns = translate_columns;
205  myopt.n_translate_columns = lengthof(translate_columns);
206 
207  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
208 
209  PQclear(res);
210  return true;
211 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
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:546

◆ describeAggregates()

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

Definition at line 62 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().

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

◆ describeFunctions()

bool describeFunctions ( const char *  functypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 314 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(), 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().

315 {
316  bool showAggregate = strchr(functypes, 'a') != NULL;
317  bool showNormal = strchr(functypes, 'n') != NULL;
318  bool showProcedure = strchr(functypes, 'p') != NULL;
319  bool showTrigger = strchr(functypes, 't') != NULL;
320  bool showWindow = strchr(functypes, 'w') != NULL;
321  bool have_where;
323  PGresult *res;
324  printQueryOpt myopt = pset.popt;
325  static const bool translate_columns[] = {false, false, false, false, true, true, true, false, true, false, false, false, false};
326 
327  /* No "Parallel" column before 9.6 */
328  static const bool translate_columns_pre_96[] = {false, false, false, false, true, true, false, true, false, false, false, false};
329 
330  if (strlen(functypes) != strspn(functypes, "anptwS+"))
331  {
332  pg_log_error("\\df only takes [anptwS+] as options");
333  return true;
334  }
335 
336  if (showProcedure && pset.sversion < 110000)
337  {
338  char sverbuf[32];
339 
340  pg_log_error("\\df does not take a \"%c\" option with server version %s",
341  'p',
343  sverbuf, sizeof(sverbuf)));
344  return true;
345  }
346 
347  if (showWindow && pset.sversion < 80400)
348  {
349  char sverbuf[32];
350 
351  pg_log_error("\\df does not take a \"%c\" option with server version %s",
352  'w',
354  sverbuf, sizeof(sverbuf)));
355  return true;
356  }
357 
358  if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
359  {
360  showAggregate = showNormal = showTrigger = true;
361  if (pset.sversion >= 110000)
362  showProcedure = true;
363  if (pset.sversion >= 80400)
364  showWindow = true;
365  }
366 
367  initPQExpBuffer(&buf);
368 
369  printfPQExpBuffer(&buf,
370  "SELECT n.nspname as \"%s\",\n"
371  " p.proname as \"%s\",\n",
372  gettext_noop("Schema"),
373  gettext_noop("Name"));
374 
375  if (pset.sversion >= 110000)
376  appendPQExpBuffer(&buf,
377  " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
378  " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
379  " CASE p.prokind\n"
380  " WHEN 'a' THEN '%s'\n"
381  " WHEN 'w' THEN '%s'\n"
382  " WHEN 'p' THEN '%s'\n"
383  " ELSE '%s'\n"
384  " END as \"%s\"",
385  gettext_noop("Result data type"),
386  gettext_noop("Argument data types"),
387  /* translator: "agg" is short for "aggregate" */
388  gettext_noop("agg"),
389  gettext_noop("window"),
390  gettext_noop("proc"),
391  gettext_noop("func"),
392  gettext_noop("Type"));
393  else if (pset.sversion >= 80400)
394  appendPQExpBuffer(&buf,
395  " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
396  " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
397  " CASE\n"
398  " WHEN p.proisagg THEN '%s'\n"
399  " WHEN p.proiswindow THEN '%s'\n"
400  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
401  " ELSE '%s'\n"
402  " END as \"%s\"",
403  gettext_noop("Result data type"),
404  gettext_noop("Argument data types"),
405  /* translator: "agg" is short for "aggregate" */
406  gettext_noop("agg"),
407  gettext_noop("window"),
408  gettext_noop("trigger"),
409  gettext_noop("func"),
410  gettext_noop("Type"));
411  else if (pset.sversion >= 80100)
412  appendPQExpBuffer(&buf,
413  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
414  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
415  " CASE WHEN proallargtypes IS NOT NULL THEN\n"
416  " pg_catalog.array_to_string(ARRAY(\n"
417  " SELECT\n"
418  " CASE\n"
419  " WHEN p.proargmodes[s.i] = 'i' THEN ''\n"
420  " WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n"
421  " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n"
422  " WHEN p.proargmodes[s.i] = 'v' THEN 'VARIADIC '\n"
423  " END ||\n"
424  " CASE\n"
425  " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n"
426  " ELSE p.proargnames[s.i] || ' '\n"
427  " END ||\n"
428  " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n"
429  " FROM\n"
430  " pg_catalog.generate_series(1, pg_catalog.array_upper(p.proallargtypes, 1)) AS s(i)\n"
431  " ), ', ')\n"
432  " ELSE\n"
433  " pg_catalog.array_to_string(ARRAY(\n"
434  " SELECT\n"
435  " CASE\n"
436  " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n"
437  " ELSE p.proargnames[s.i+1] || ' '\n"
438  " END ||\n"
439  " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
440  " FROM\n"
441  " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
442  " ), ', ')\n"
443  " END AS \"%s\",\n"
444  " CASE\n"
445  " WHEN p.proisagg THEN '%s'\n"
446  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
447  " ELSE '%s'\n"
448  " END AS \"%s\"",
449  gettext_noop("Result data type"),
450  gettext_noop("Argument data types"),
451  /* translator: "agg" is short for "aggregate" */
452  gettext_noop("agg"),
453  gettext_noop("trigger"),
454  gettext_noop("func"),
455  gettext_noop("Type"));
456  else
457  appendPQExpBuffer(&buf,
458  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
459  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
460  " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
461  " CASE\n"
462  " WHEN p.proisagg THEN '%s'\n"
463  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
464  " ELSE '%s'\n"
465  " END AS \"%s\"",
466  gettext_noop("Result data type"),
467  gettext_noop("Argument data types"),
468  /* translator: "agg" is short for "aggregate" */
469  gettext_noop("agg"),
470  gettext_noop("trigger"),
471  gettext_noop("func"),
472  gettext_noop("Type"));
473 
474  if (verbose)
475  {
476  appendPQExpBuffer(&buf,
477  ",\n CASE\n"
478  " WHEN p.provolatile = 'i' THEN '%s'\n"
479  " WHEN p.provolatile = 's' THEN '%s'\n"
480  " WHEN p.provolatile = 'v' THEN '%s'\n"
481  " END as \"%s\"",
482  gettext_noop("immutable"),
483  gettext_noop("stable"),
484  gettext_noop("volatile"),
485  gettext_noop("Volatility"));
486  if (pset.sversion >= 90600)
487  appendPQExpBuffer(&buf,
488  ",\n CASE\n"
489  " WHEN p.proparallel = 'r' THEN '%s'\n"
490  " WHEN p.proparallel = 's' THEN '%s'\n"
491  " WHEN p.proparallel = 'u' THEN '%s'\n"
492  " END as \"%s\"",
493  gettext_noop("restricted"),
494  gettext_noop("safe"),
495  gettext_noop("unsafe"),
496  gettext_noop("Parallel"));
497  appendPQExpBuffer(&buf,
498  ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
499  ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
500  gettext_noop("Owner"),
501  gettext_noop("definer"),
502  gettext_noop("invoker"),
503  gettext_noop("Security"));
504  appendPQExpBufferStr(&buf, ",\n ");
505  printACLColumn(&buf, "p.proacl");
506  appendPQExpBuffer(&buf,
507  ",\n l.lanname as \"%s\""
508  ",\n p.prosrc as \"%s\""
509  ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
510  gettext_noop("Language"),
511  gettext_noop("Source code"),
512  gettext_noop("Description"));
513  }
514 
516  "\nFROM pg_catalog.pg_proc p"
517  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
518 
519  if (verbose)
521  " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
522 
523  have_where = false;
524 
525  /* filter by function type, if requested */
526  if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
527  /* Do nothing */ ;
528  else if (showNormal)
529  {
530  if (!showAggregate)
531  {
532  if (have_where)
533  appendPQExpBufferStr(&buf, " AND ");
534  else
535  {
536  appendPQExpBufferStr(&buf, "WHERE ");
537  have_where = true;
538  }
539  if (pset.sversion >= 110000)
540  appendPQExpBufferStr(&buf, "p.prokind <> 'a'\n");
541  else
542  appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
543  }
544  if (!showProcedure && pset.sversion >= 110000)
545  {
546  if (have_where)
547  appendPQExpBufferStr(&buf, " AND ");
548  else
549  {
550  appendPQExpBufferStr(&buf, "WHERE ");
551  have_where = true;
552  }
553  appendPQExpBufferStr(&buf, "p.prokind <> 'p'\n");
554  }
555  if (!showTrigger)
556  {
557  if (have_where)
558  appendPQExpBufferStr(&buf, " AND ");
559  else
560  {
561  appendPQExpBufferStr(&buf, "WHERE ");
562  have_where = true;
563  }
564  appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
565  }
566  if (!showWindow && pset.sversion >= 80400)
567  {
568  if (have_where)
569  appendPQExpBufferStr(&buf, " AND ");
570  else
571  {
572  appendPQExpBufferStr(&buf, "WHERE ");
573  have_where = true;
574  }
575  if (pset.sversion >= 110000)
576  appendPQExpBufferStr(&buf, "p.prokind <> 'w'\n");
577  else
578  appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
579  }
580  }
581  else
582  {
583  bool needs_or = false;
584 
585  appendPQExpBufferStr(&buf, "WHERE (\n ");
586  have_where = true;
587  /* Note: at least one of these must be true ... */
588  if (showAggregate)
589  {
590  if (pset.sversion >= 110000)
591  appendPQExpBufferStr(&buf, "p.prokind = 'a'\n");
592  else
593  appendPQExpBufferStr(&buf, "p.proisagg\n");
594  needs_or = true;
595  }
596  if (showTrigger)
597  {
598  if (needs_or)
599  appendPQExpBufferStr(&buf, " OR ");
601  "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
602  needs_or = true;
603  }
604  if (showProcedure)
605  {
606  if (needs_or)
607  appendPQExpBufferStr(&buf, " OR ");
608  appendPQExpBufferStr(&buf, "p.prokind = 'p'\n");
609  needs_or = true;
610  }
611  if (showWindow)
612  {
613  if (needs_or)
614  appendPQExpBufferStr(&buf, " OR ");
615  if (pset.sversion >= 110000)
616  appendPQExpBufferStr(&buf, "p.prokind = 'w'\n");
617  else
618  appendPQExpBufferStr(&buf, "p.proiswindow\n");
619  needs_or = true;
620  }
621  appendPQExpBufferStr(&buf, " )\n");
622  }
623 
624  processSQLNamePattern(pset.db, &buf, pattern, have_where, false,
625  "n.nspname", "p.proname", NULL,
626  "pg_catalog.pg_function_is_visible(p.oid)");
627 
628  if (!showSystem && !pattern)
629  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
630  " AND n.nspname <> 'information_schema'\n");
631 
632  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
633 
634  res = PSQLexec(buf.data);
635  termPQExpBuffer(&buf);
636  if (!res)
637  return false;
638 
639  myopt.nullPrint = NULL;
640  myopt.title = _("List of functions");
641  myopt.translate_header = true;
642  if (pset.sversion >= 90600)
643  {
644  myopt.translate_columns = translate_columns;
645  myopt.n_translate_columns = lengthof(translate_columns);
646  }
647  else
648  {
649  myopt.translate_columns = translate_columns_pre_96;
650  myopt.n_translate_columns = lengthof(translate_columns_pre_96);
651  }
652 
653  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
654 
655  PQclear(res);
656  return true;
657 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
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:546

◆ describeOperators()

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

Definition at line 782 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, termPQExpBuffer(), printQueryOpt::title, and printQueryOpt::translate_header.

Referenced by exec_command_d().

783 {
785  PGresult *res;
786  printQueryOpt myopt = pset.popt;
787 
788  initPQExpBuffer(&buf);
789 
790  /*
791  * Note: before Postgres 9.1, we did not assign comments to any built-in
792  * operators, preferring to let the comment on the underlying function
793  * suffice. The coalesce() on the obj_description() calls below supports
794  * this convention by providing a fallback lookup of a comment on the
795  * operator's function. As of 9.1 there is a policy that every built-in
796  * operator should have a comment; so the coalesce() is no longer
797  * necessary so far as built-in operators are concerned. We keep it
798  * anyway, for now, because (1) third-party modules may still be following
799  * the old convention, and (2) we'd need to do it anyway when talking to a
800  * pre-9.1 server.
801  */
802 
803  printfPQExpBuffer(&buf,
804  "SELECT n.nspname as \"%s\",\n"
805  " o.oprname AS \"%s\",\n"
806  " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
807  " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
808  " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
809  gettext_noop("Schema"),
810  gettext_noop("Name"),
811  gettext_noop("Left arg type"),
812  gettext_noop("Right arg type"),
813  gettext_noop("Result type"));
814 
815  if (verbose)
816  appendPQExpBuffer(&buf,
817  " o.oprcode AS \"%s\",\n",
818  gettext_noop("Function"));
819 
820  appendPQExpBuffer(&buf,
821  " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
822  " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
823  "FROM pg_catalog.pg_operator o\n"
824  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
825  gettext_noop("Description"));
826 
827  if (!showSystem && !pattern)
828  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
829  " AND n.nspname <> 'information_schema'\n");
830 
831  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
832  "n.nspname", "o.oprname", NULL,
833  "pg_catalog.pg_operator_is_visible(o.oid)");
834 
835  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
836 
837  res = PSQLexec(buf.data);
838  termPQExpBuffer(&buf);
839  if (!res)
840  return false;
841 
842  myopt.nullPrint = NULL;
843  myopt.title = _("List of operators");
844  myopt.translate_header = true;
845 
846  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
847 
848  PQclear(res);
849  return true;
850 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ describePublications()

bool describePublications ( const char *  pattern)

Definition at line 5775 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().

5776 {
5778  int i;
5779  PGresult *res;
5780  bool has_pubtruncate;
5781 
5782  if (pset.sversion < 100000)
5783  {
5784  char sverbuf[32];
5785 
5786  pg_log_error("The server (version %s) does not support publications.",
5788  sverbuf, sizeof(sverbuf)));
5789  return true;
5790  }
5791 
5792  has_pubtruncate = (pset.sversion >= 110000);
5793 
5794  initPQExpBuffer(&buf);
5795 
5796  printfPQExpBuffer(&buf,
5797  "SELECT oid, pubname,\n"
5798  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
5799  " puballtables, pubinsert, pubupdate, pubdelete");
5800  if (has_pubtruncate)
5801  appendPQExpBufferStr(&buf,
5802  ", pubtruncate");
5803  appendPQExpBufferStr(&buf,
5804  "\nFROM pg_catalog.pg_publication\n");
5805 
5806  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5807  NULL, "pubname", NULL,
5808  NULL);
5809 
5810  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5811 
5812  res = PSQLexec(buf.data);
5813  if (!res)
5814  {
5815  termPQExpBuffer(&buf);
5816  return false;
5817  }
5818 
5819  if (PQntuples(res) == 0)
5820  {
5821  if (!pset.quiet)
5822  {
5823  if (pattern)
5824  pg_log_error("Did not find any publication named \"%s\".",
5825  pattern);
5826  else
5827  pg_log_error("Did not find any publications.");
5828  }
5829 
5830  termPQExpBuffer(&buf);
5831  PQclear(res);
5832  return false;
5833  }
5834 
5835  for (i = 0; i < PQntuples(res); i++)
5836  {
5837  const char align = 'l';
5838  int ncols = 5;
5839  int nrows = 1;
5840  int tables = 0;
5841  PGresult *tabres;
5842  char *pubid = PQgetvalue(res, i, 0);
5843  char *pubname = PQgetvalue(res, i, 1);
5844  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
5845  int j;
5846  PQExpBufferData title;
5847  printTableOpt myopt = pset.popt.topt;
5848  printTableContent cont;
5849 
5850  if (has_pubtruncate)
5851  ncols++;
5852 
5853  initPQExpBuffer(&title);
5854  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5855  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5856 
5857  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
5858  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
5859  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5860  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5861  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5862  if (has_pubtruncate)
5863  printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
5864 
5865  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
5866  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5867  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5868  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5869  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
5870  if (has_pubtruncate)
5871  printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
5872 
5873  if (!puballtables)
5874  {
5875  printfPQExpBuffer(&buf,
5876  "SELECT n.nspname, c.relname\n"
5877  "FROM pg_catalog.pg_class c,\n"
5878  " pg_catalog.pg_namespace n,\n"
5879  " pg_catalog.pg_publication_rel pr\n"
5880  "WHERE c.relnamespace = n.oid\n"
5881  " AND c.oid = pr.prrelid\n"
5882  " AND pr.prpubid = '%s'\n"
5883  "ORDER BY 1,2", pubid);
5884 
5885  tabres = PSQLexec(buf.data);
5886  if (!tabres)
5887  {
5888  printTableCleanup(&cont);
5889  PQclear(res);
5890  termPQExpBuffer(&buf);
5891  termPQExpBuffer(&title);
5892  return false;
5893  }
5894  else
5895  tables = PQntuples(tabres);
5896 
5897  if (tables > 0)
5898  printTableAddFooter(&cont, _("Tables:"));
5899 
5900  for (j = 0; j < tables; j++)
5901  {
5902  printfPQExpBuffer(&buf, " \"%s.%s\"",
5903  PQgetvalue(tabres, j, 0),
5904  PQgetvalue(tabres, j, 1));
5905 
5906  printTableAddFooter(&cont, buf.data);
5907  }
5908  PQclear(tabres);
5909  }
5910 
5911  printTable(&cont, pset.queryFout, false, pset.logfile);
5912  printTableCleanup(&cont);
5913 
5914  termPQExpBuffer(&title);
5915  }
5916 
5917  termPQExpBuffer(&buf);
5918  PQclear(res);
5919 
5920  return true;
5921 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
void printTableCleanup(printTableContent *const content)
Definition: print.c:3242
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
printTableOpt topt
Definition: print.h:167
#define gettext_noop(x)
Definition: c.h:1148
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:2769
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3111
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3151
static char * buf
Definition: pg_test_fsync.c:67
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3331
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3199
FILE * logfile
Definition: settings.h:115
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:3074
int i
#define _(x)
Definition: elog.c:87
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:546

◆ describeRoles()

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

Definition at line 3398 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().

3399 {
3401  PGresult *res;
3402  printTableContent cont;
3403  printTableOpt myopt = pset.popt.topt;
3404  int ncols = 3;
3405  int nrows = 0;
3406  int i;
3407  int conns;
3408  const char align = 'l';
3409  char **attr;
3410 
3411  myopt.default_footer = false;
3412 
3413  initPQExpBuffer(&buf);
3414 
3415  if (pset.sversion >= 80100)
3416  {
3417  printfPQExpBuffer(&buf,
3418  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3419  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3420  " r.rolconnlimit, r.rolvaliduntil,\n"
3421  " ARRAY(SELECT b.rolname\n"
3422  " FROM pg_catalog.pg_auth_members m\n"
3423  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3424  " WHERE m.member = r.oid) as memberof");
3425 
3426  if (verbose && pset.sversion >= 80200)
3427  {
3428  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3429  ncols++;
3430  }
3431  if (pset.sversion >= 90100)
3432  {
3433  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3434  }
3435 
3436  if (pset.sversion >= 90500)
3437  {
3438  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3439  }
3440 
3441  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3442 
3443  if (!showSystem && !pattern)
3444  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3445 
3446  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3447  NULL, "r.rolname", NULL, NULL);
3448  }
3449  else
3450  {
3451  printfPQExpBuffer(&buf,
3452  "SELECT u.usename AS rolname,\n"
3453  " u.usesuper AS rolsuper,\n"
3454  " true AS rolinherit, false AS rolcreaterole,\n"
3455  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3456  " -1 AS rolconnlimit,"
3457  " u.valuntil as rolvaliduntil,\n"
3458  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3459  "\nFROM pg_catalog.pg_user u\n");
3460 
3461  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3462  NULL, "u.usename", NULL, NULL);
3463  }
3464 
3465  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3466 
3467  res = PSQLexec(buf.data);
3468  if (!res)
3469  return false;
3470 
3471  nrows = PQntuples(res);
3472  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3473 
3474  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3475 
3476  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3477  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3478  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3479 
3480  if (verbose && pset.sversion >= 80200)
3481  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3482 
3483  for (i = 0; i < nrows; i++)
3484  {
3485  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3486 
3487  resetPQExpBuffer(&buf);
3488  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3489  add_role_attribute(&buf, _("Superuser"));
3490 
3491  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3492  add_role_attribute(&buf, _("No inheritance"));
3493 
3494  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3495  add_role_attribute(&buf, _("Create role"));
3496 
3497  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3498  add_role_attribute(&buf, _("Create DB"));
3499 
3500  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3501  add_role_attribute(&buf, _("Cannot login"));
3502 
3503  if (pset.sversion >= 90100)
3504  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3505  add_role_attribute(&buf, _("Replication"));
3506 
3507  if (pset.sversion >= 90500)
3508  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3509  add_role_attribute(&buf, _("Bypass RLS"));
3510 
3511  conns = atoi(PQgetvalue(res, i, 6));
3512  if (conns >= 0)
3513  {
3514  if (buf.len > 0)
3515  appendPQExpBufferChar(&buf, '\n');
3516 
3517  if (conns == 0)
3518  appendPQExpBufferStr(&buf, _("No connections"));
3519  else
3520  appendPQExpBuffer(&buf, ngettext("%d connection",
3521  "%d connections",
3522  conns),
3523  conns);
3524  }
3525 
3526  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3527  {
3528  if (buf.len > 0)
3529  appendPQExpBufferChar(&buf, '\n');
3530  appendPQExpBufferStr(&buf, _("Password valid until "));
3531  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3532  }
3533 
3534  attr[i] = pg_strdup(buf.data);
3535 
3536  printTableAddCell(&cont, attr[i], false, false);
3537 
3538  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3539 
3540  if (verbose && pset.sversion >= 80200)
3541  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3542  }
3543  termPQExpBuffer(&buf);
3544 
3545  printTable(&cont, pset.queryFout, false, pset.logfile);
3546  printTableCleanup(&cont);
3547 
3548  for (i = 0; i < nrows; i++)
3549  free(attr[i]);
3550  free(attr);
3551 
3552  PQclear(res);
3553  return true;
3554 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
void printTableCleanup(printTableContent *const content)
Definition: print.c:3242
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
printTableOpt topt
Definition: print.h:167
#define gettext_noop(x)
Definition: c.h:1148
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:2769
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3557
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3111
static PGconn ** conns
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3151
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
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:3331
static int verbose
#define ngettext(s, p, n)
Definition: c.h:1134
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define free(a)
Definition: header.h:65
bool default_footer
Definition: print.h:111
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:3074
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ describeSubscriptions()

bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 5930 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().

5931 {
5933  PGresult *res;
5934  printQueryOpt myopt = pset.popt;
5935  static const bool translate_columns[] = {false, false, false, false,
5936  false, false};
5937 
5938  if (pset.sversion < 100000)
5939  {
5940  char sverbuf[32];
5941 
5942  pg_log_error("The server (version %s) does not support subscriptions.",
5944  sverbuf, sizeof(sverbuf)));
5945  return true;
5946  }
5947 
5948  initPQExpBuffer(&buf);
5949 
5950  printfPQExpBuffer(&buf,
5951  "SELECT subname AS \"%s\"\n"
5952  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5953  ", subenabled AS \"%s\"\n"
5954  ", subpublications AS \"%s\"\n",
5955  gettext_noop("Name"),
5956  gettext_noop("Owner"),
5957  gettext_noop("Enabled"),
5958  gettext_noop("Publication"));
5959 
5960  if (verbose)
5961  {
5962  appendPQExpBuffer(&buf,
5963  ", subsynccommit AS \"%s\"\n"
5964  ", subconninfo AS \"%s\"\n",
5965  gettext_noop("Synchronous commit"),
5966  gettext_noop("Conninfo"));
5967  }
5968 
5969  /* Only display subscriptions in current database. */
5970  appendPQExpBufferStr(&buf,
5971  "FROM pg_catalog.pg_subscription\n"
5972  "WHERE subdbid = (SELECT oid\n"
5973  " FROM pg_catalog.pg_database\n"
5974  " WHERE datname = pg_catalog.current_database())");
5975 
5976  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5977  NULL, "subname", NULL,
5978  NULL);
5979 
5980  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5981 
5982  res = PSQLexec(buf.data);
5983  termPQExpBuffer(&buf);
5984  if (!res)
5985  return false;
5986 
5987  myopt.nullPrint = NULL;
5988  myopt.title = _("List of subscriptions");
5989  myopt.translate_header = true;
5990  myopt.translate_columns = translate_columns;
5991  myopt.n_translate_columns = lengthof(translate_columns);
5992 
5993  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5994 
5995  PQclear(res);
5996  return true;
5997 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
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:546

◆ describeTableDetails()

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

Definition at line 1366 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().

1367 {
1369  PGresult *res;
1370  int i;
1371 
1372  initPQExpBuffer(&buf);
1373 
1374  printfPQExpBuffer(&buf,
1375  "SELECT c.oid,\n"
1376  " n.nspname,\n"
1377  " c.relname\n"
1378  "FROM pg_catalog.pg_class c\n"
1379  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1380 
1381  if (!showSystem && !pattern)
1382  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1383  " AND n.nspname <> 'information_schema'\n");
1384 
1385  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1386  "n.nspname", "c.relname", NULL,
1387  "pg_catalog.pg_table_is_visible(c.oid)");
1388 
1389  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1390 
1391  res = PSQLexec(buf.data);
1392  termPQExpBuffer(&buf);
1393  if (!res)
1394  return false;
1395 
1396  if (PQntuples(res) == 0)
1397  {
1398  if (!pset.quiet)
1399  {
1400  if (pattern)
1401  pg_log_error("Did not find any relation named \"%s\".",
1402  pattern);
1403  else
1404  pg_log_error("Did not find any relations.");
1405  }
1406  PQclear(res);
1407  return false;
1408  }
1409 
1410  for (i = 0; i < PQntuples(res); i++)
1411  {
1412  const char *oid;
1413  const char *nspname;
1414  const char *relname;
1415 
1416  oid = PQgetvalue(res, i, 0);
1417  nspname = PQgetvalue(res, i, 1);
1418  relname = PQgetvalue(res, i, 2);
1419 
1420  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1421  {
1422  PQclear(res);
1423  return false;
1424  }
1425  if (cancel_pressed)
1426  {
1427  PQclear(res);
1428  return false;
1429  }
1430  }
1431 
1432  PQclear(res);
1433  return true;
1434 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
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:35
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
volatile bool cancel_pressed
Definition: print.c:44
static char * buf
Definition: pg_test_fsync.c:67
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1444
static int verbose
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:546

◆ describeTablespaces()

bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 218 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().

219 {
221  PGresult *res;
222  printQueryOpt myopt = pset.popt;
223 
224  if (pset.sversion < 80000)
225  {
226  char sverbuf[32];
227 
228  pg_log_info("The server (version %s) does not support tablespaces.",
230  sverbuf, sizeof(sverbuf)));
231  return true;
232  }
233 
234  initPQExpBuffer(&buf);
235 
236  if (pset.sversion >= 90200)
237  printfPQExpBuffer(&buf,
238  "SELECT spcname AS \"%s\",\n"
239  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
240  " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
241  gettext_noop("Name"),
242  gettext_noop("Owner"),
243  gettext_noop("Location"));
244  else
245  printfPQExpBuffer(&buf,
246  "SELECT spcname AS \"%s\",\n"
247  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
248  " spclocation AS \"%s\"",
249  gettext_noop("Name"),
250  gettext_noop("Owner"),
251  gettext_noop("Location"));
252 
253  if (verbose)
254  {
255  appendPQExpBufferStr(&buf, ",\n ");
256  printACLColumn(&buf, "spcacl");
257  }
258 
259  if (verbose && pset.sversion >= 90000)
260  appendPQExpBuffer(&buf,
261  ",\n spcoptions AS \"%s\"",
262  gettext_noop("Options"));
263 
264  if (verbose && pset.sversion >= 90200)
265  appendPQExpBuffer(&buf,
266  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"",
267  gettext_noop("Size"));
268 
269  if (verbose && pset.sversion >= 80200)
270  appendPQExpBuffer(&buf,
271  ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
272  gettext_noop("Description"));
273 
275  "\nFROM pg_catalog.pg_tablespace\n");
276 
277  processSQLNamePattern(pset.db, &buf, pattern, false, false,
278  NULL, "spcname", NULL,
279  NULL);
280 
281  appendPQExpBufferStr(&buf, "ORDER BY 1;");
282 
283  res = PSQLexec(buf.data);
284  termPQExpBuffer(&buf);
285  if (!res)
286  return false;
287 
288  myopt.nullPrint = NULL;
289  myopt.title = _("List of tablespaces");
290  myopt.translate_header = true;
291 
292  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
293 
294  PQclear(res);
295  return true;
296 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
#define pg_log_info(...)
Definition: logging.h:87
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:546

◆ describeTypes()

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

Definition at line 666 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, 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().

667 {
669  PGresult *res;
670  printQueryOpt myopt = pset.popt;
671 
672  initPQExpBuffer(&buf);
673 
674  printfPQExpBuffer(&buf,
675  "SELECT n.nspname as \"%s\",\n"
676  " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
677  gettext_noop("Schema"),
678  gettext_noop("Name"));
679  if (verbose)
680  appendPQExpBuffer(&buf,
681  " t.typname AS \"%s\",\n"
682  " CASE WHEN t.typrelid != 0\n"
683  " THEN CAST('tuple' AS pg_catalog.text)\n"
684  " WHEN t.typlen < 0\n"
685  " THEN CAST('var' AS pg_catalog.text)\n"
686  " ELSE CAST(t.typlen AS pg_catalog.text)\n"
687  " END AS \"%s\",\n",
688  gettext_noop("Internal name"),
689  gettext_noop("Size"));
690  if (verbose && pset.sversion >= 80300)
691  {
693  " pg_catalog.array_to_string(\n"
694  " ARRAY(\n"
695  " SELECT e.enumlabel\n"
696  " FROM pg_catalog.pg_enum e\n"
697  " WHERE e.enumtypid = t.oid\n");
698 
699  if (pset.sversion >= 90100)
701  " ORDER BY e.enumsortorder\n");
702  else
704  " ORDER BY e.oid\n");
705 
706  appendPQExpBuffer(&buf,
707  " ),\n"
708  " E'\\n'\n"
709  " ) AS \"%s\",\n",
710  gettext_noop("Elements"));
711  }
712  if (verbose)
713  {
714  appendPQExpBuffer(&buf,
715  " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
716  gettext_noop("Owner"));
717  }
718  if (verbose && pset.sversion >= 90200)
719  {
720  printACLColumn(&buf, "t.typacl");
721  appendPQExpBufferStr(&buf, ",\n ");
722  }
723 
724  appendPQExpBuffer(&buf,
725  " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
726  gettext_noop("Description"));
727 
728  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
729  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
730 
731  /*
732  * do not include complex types (typrelid!=0) unless they are standalone
733  * composite types
734  */
735  appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
736  appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
737  " FROM pg_catalog.pg_class c "
738  "WHERE c.oid = t.typrelid))\n");
739 
740  /*
741  * do not include array types (before 8.3 we have to use the assumption
742  * that their names start with underscore)
743  */
744  if (pset.sversion >= 80300)
745  appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
746  else
747  appendPQExpBufferStr(&buf, " AND t.typname !~ '^_'\n");
748 
749  if (!showSystem && !pattern)
750  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
751  " AND n.nspname <> 'information_schema'\n");
752 
753  /* Match name pattern against either internal or external name */
754  processSQLNamePattern(pset.db, &buf, pattern, true, false,
755  "n.nspname", "t.typname",
756  "pg_catalog.format_type(t.oid, NULL)",
757  "pg_catalog.pg_type_is_visible(t.oid)");
758 
759  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
760 
761  res = PSQLexec(buf.data);
762  termPQExpBuffer(&buf);
763  if (!res)
764  return false;
765 
766  myopt.nullPrint = NULL;
767  myopt.title = _("List of data types");
768  myopt.translate_header = true;
769 
770  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
771 
772  PQclear(res);
773  return true;
774 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
#define CppAsString2(x)
Definition: c.h:224
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listAllDbs()

bool listAllDbs ( const char *  pattern,
bool  verbose 
)

Definition at line 859 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().

860 {
861  PGresult *res;
863  printQueryOpt myopt = pset.popt;
864 
865  initPQExpBuffer(&buf);
866 
867  printfPQExpBuffer(&buf,
868  "SELECT d.datname as \"%s\",\n"
869  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
870  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
871  gettext_noop("Name"),
872  gettext_noop("Owner"),
873  gettext_noop("Encoding"));
874  if (pset.sversion >= 80400)
875  appendPQExpBuffer(&buf,
876  " d.datcollate as \"%s\",\n"
877  " d.datctype as \"%s\",\n",
878  gettext_noop("Collate"),
879  gettext_noop("Ctype"));
880  appendPQExpBufferStr(&buf, " ");
881  printACLColumn(&buf, "d.datacl");
882  if (verbose && pset.sversion >= 80200)
883  appendPQExpBuffer(&buf,
884  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
885  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
886  " ELSE 'No Access'\n"
887  " END as \"%s\"",
888  gettext_noop("Size"));
889  if (verbose && pset.sversion >= 80000)
890  appendPQExpBuffer(&buf,
891  ",\n t.spcname as \"%s\"",
892  gettext_noop("Tablespace"));
893  if (verbose && pset.sversion >= 80200)
894  appendPQExpBuffer(&buf,
895  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
896  gettext_noop("Description"));
898  "\nFROM pg_catalog.pg_database d\n");
899  if (verbose && pset.sversion >= 80000)
901  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
902 
903  if (pattern)
904  processSQLNamePattern(pset.db, &buf, pattern, false, false,
905  NULL, "d.datname", NULL, NULL);
906 
907  appendPQExpBufferStr(&buf, "ORDER BY 1;");
908  res = PSQLexec(buf.data);
909  termPQExpBuffer(&buf);
910  if (!res)
911  return false;
912 
913  myopt.nullPrint = NULL;
914  myopt.title = _("List of databases");
915  myopt.translate_header = true;
916 
917  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
918 
919  PQclear(res);
920  return true;
921 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listCasts()

bool listCasts ( const char *  pattern,
bool  verbose 
)

Definition at line 4361 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().

4362 {
4364  PGresult *res;
4365  printQueryOpt myopt = pset.popt;
4366  static const bool translate_columns[] = {false, false, false, true, false};
4367 
4368  initPQExpBuffer(&buf);
4369 
4370  printfPQExpBuffer(&buf,
4371  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4372  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4373  gettext_noop("Source type"),
4374  gettext_noop("Target type"));
4375 
4376  /*
4377  * We don't attempt to localize '(binary coercible)' or '(with inout)',
4378  * because there's too much risk of gettext translating a function name
4379  * that happens to match some string in the PO database.
4380  */
4381  if (pset.sversion >= 80400)
4382  appendPQExpBuffer(&buf,
4383  " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4384  " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4385  " ELSE p.proname\n"
4386  " END AS \"%s\",\n",
4387  COERCION_METHOD_BINARY,
4388  COERCION_METHOD_INOUT,
4389  gettext_noop("Function"));
4390  else
4391  appendPQExpBuffer(&buf,
4392  " CASE WHEN c.castfunc = 0 THEN '(binary coercible)'\n"
4393  " ELSE p.proname\n"
4394  " END AS \"%s\",\n",
4395  gettext_noop("Function"));
4396 
4397  appendPQExpBuffer(&buf,
4398  " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4399  " WHEN c.castcontext = '%c' THEN '%s'\n"
4400  " ELSE '%s'\n"
4401  " END AS \"%s\"",
4402  COERCION_CODE_EXPLICIT,
4403  gettext_noop("no"),
4404  COERCION_CODE_ASSIGNMENT,
4405  gettext_noop("in assignment"),
4406  gettext_noop("yes"),
4407  gettext_noop("Implicit?"));
4408 
4409  if (verbose)
4410  appendPQExpBuffer(&buf,
4411  ",\n d.description AS \"%s\"",
4412  gettext_noop("Description"));
4413 
4414  /*
4415  * We need a left join to pg_proc for binary casts; the others are just
4416  * paranoia.
4417  */
4418  appendPQExpBufferStr(&buf,
4419  "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4420  " ON c.castfunc = p.oid\n"
4421  " LEFT JOIN pg_catalog.pg_type ts\n"
4422  " ON c.castsource = ts.oid\n"
4423  " LEFT JOIN pg_catalog.pg_namespace ns\n"
4424  " ON ns.oid = ts.typnamespace\n"
4425  " LEFT JOIN pg_catalog.pg_type tt\n"
4426  " ON c.casttarget = tt.oid\n"
4427  " LEFT JOIN pg_catalog.pg_namespace nt\n"
4428  " ON nt.oid = tt.typnamespace\n");
4429 
4430  if (verbose)
4431  appendPQExpBufferStr(&buf,
4432  " LEFT JOIN pg_catalog.pg_description d\n"
4433  " ON d.classoid = c.tableoid AND d.objoid = "
4434  "c.oid AND d.objsubid = 0\n");
4435 
4436  appendPQExpBufferStr(&buf, "WHERE ( (true");
4437 
4438  /*
4439  * Match name pattern against either internal or external name of either
4440  * castsource or casttarget
4441  */
4442  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4443  "ns.nspname", "ts.typname",
4444  "pg_catalog.format_type(ts.oid, NULL)",
4445  "pg_catalog.pg_type_is_visible(ts.oid)");
4446 
4447  appendPQExpBufferStr(&buf, ") OR (true");
4448 
4449  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4450  "nt.nspname", "tt.typname",
4451  "pg_catalog.format_type(tt.oid, NULL)",
4452  "pg_catalog.pg_type_is_visible(tt.oid)");
4453 
4454  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
4455 
4456  res = PSQLexec(buf.data);
4457  termPQExpBuffer(&buf);
4458  if (!res)
4459  return false;
4460 
4461  myopt.nullPrint = NULL;
4462  myopt.title = _("List of casts");
4463  myopt.translate_header = true;
4464  myopt.translate_columns = translate_columns;
4465  myopt.n_translate_columns = lengthof(translate_columns);
4466 
4467  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4468 
4469  PQclear(res);
4470  return true;
4471 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listCollations()

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

Definition at line 4479 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().

4480 {
4482  PGresult *res;
4483  printQueryOpt myopt = pset.popt;
4484  static const bool translate_columns[] = {false, false, false, false, false, true, false};
4485 
4486  if (pset.sversion < 90100)
4487  {
4488  char sverbuf[32];
4489 
4490  pg_log_error("The server (version %s) does not support collations.",
4492  sverbuf, sizeof(sverbuf)));
4493  return true;
4494  }
4495 
4496  initPQExpBuffer(&buf);
4497 
4498  printfPQExpBuffer(&buf,
4499  "SELECT n.nspname AS \"%s\",\n"
4500  " c.collname AS \"%s\",\n"
4501  " c.collcollate AS \"%s\",\n"
4502  " c.collctype AS \"%s\"",
4503  gettext_noop("Schema"),
4504  gettext_noop("Name"),
4505  gettext_noop("Collate"),
4506  gettext_noop("Ctype"));
4507 
4508  if (pset.sversion >= 100000)
4509  appendPQExpBuffer(&buf,
4510  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
4511  gettext_noop("Provider"));
4512  else
4513  appendPQExpBuffer(&buf,
4514  ",\n 'libc' AS \"%s\"",
4515  gettext_noop("Provider"));
4516 
4517  if (pset.sversion >= 120000)
4518  appendPQExpBuffer(&buf,
4519  ",\n CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4520  gettext_noop("yes"), gettext_noop("no"),
4521  gettext_noop("Deterministic?"));
4522  else
4523  appendPQExpBuffer(&buf,
4524  ",\n '%s' AS \"%s\"",
4525  gettext_noop("yes"),
4526  gettext_noop("Deterministic?"));
4527 
4528  if (verbose)
4529  appendPQExpBuffer(&buf,
4530  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4531  gettext_noop("Description"));
4532 
4533  appendPQExpBufferStr(&buf,
4534  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4535  "WHERE n.oid = c.collnamespace\n");
4536 
4537  if (!showSystem && !pattern)
4538  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4539  " AND n.nspname <> 'information_schema'\n");
4540 
4541  /*
4542  * Hide collations that aren't usable in the current database's encoding.
4543  * If you think to change this, note that pg_collation_is_visible rejects
4544  * unusable collations, so you will need to hack name pattern processing
4545  * somehow to avoid inconsistent behavior.
4546  */
4547  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4548 
4549  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4550  "n.nspname", "c.collname", NULL,
4551  "pg_catalog.pg_collation_is_visible(c.oid)");
4552 
4553  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4554 
4555  res = PSQLexec(buf.data);
4556  termPQExpBuffer(&buf);
4557  if (!res)
4558  return false;
4559 
4560  myopt.nullPrint = NULL;
4561  myopt.title = _("List of collations");
4562  myopt.translate_header = true;
4563  myopt.translate_columns = translate_columns;
4564  myopt.n_translate_columns = lengthof(translate_columns);
4565 
4566  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4567 
4568  PQclear(res);
4569  return true;
4570 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
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:546

◆ listConversions()

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

Definition at line 4219 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().

4220 {
4222  PGresult *res;
4223  printQueryOpt myopt = pset.popt;
4224  static const bool translate_columns[] =
4225  {false, false, false, false, true, false};
4226 
4227  initPQExpBuffer(&buf);
4228 
4229  printfPQExpBuffer(&buf,
4230  "SELECT n.nspname AS \"%s\",\n"
4231  " c.conname AS \"%s\",\n"
4232  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4233  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4234  " CASE WHEN c.condefault THEN '%s'\n"
4235  " ELSE '%s' END AS \"%s\"",
4236  gettext_noop("Schema"),
4237  gettext_noop("Name"),
4238  gettext_noop("Source"),
4239  gettext_noop("Destination"),
4240  gettext_noop("yes"), gettext_noop("no"),
4241  gettext_noop("Default?"));
4242 
4243  if (verbose)
4244  appendPQExpBuffer(&buf,
4245  ",\n d.description AS \"%s\"",
4246  gettext_noop("Description"));
4247 
4248  appendPQExpBufferStr(&buf,
4249  "\nFROM pg_catalog.pg_conversion c\n"
4250  " JOIN pg_catalog.pg_namespace n "
4251  "ON n.oid = c.connamespace\n");
4252 
4253  if (verbose)
4254  appendPQExpBufferStr(&buf,
4255  "LEFT JOIN pg_catalog.pg_description d "
4256  "ON d.classoid = c.tableoid\n"
4257  " AND d.objoid = c.oid "
4258  "AND d.objsubid = 0\n");
4259 
4260  appendPQExpBufferStr(&buf, "WHERE true\n");
4261 
4262  if (!showSystem && !pattern)
4263  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4264  " AND n.nspname <> 'information_schema'\n");
4265 
4266  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4267  "n.nspname", "c.conname", NULL,
4268  "pg_catalog.pg_conversion_is_visible(c.oid)");
4269 
4270  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4271 
4272  res = PSQLexec(buf.data);
4273  termPQExpBuffer(&buf);
4274  if (!res)
4275  return false;
4276 
4277  myopt.nullPrint = NULL;
4278  myopt.title = _("List of conversions");
4279  myopt.translate_header = true;
4280  myopt.translate_columns = translate_columns;
4281  myopt.n_translate_columns = lengthof(translate_columns);
4282 
4283  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4284 
4285  PQclear(res);
4286  return true;
4287 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listDbRoleSettings()

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

Definition at line 3569 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().

3570 {
3572  PGresult *res;
3573  printQueryOpt myopt = pset.popt;
3574  bool havewhere;
3575 
3576  if (pset.sversion < 90000)
3577  {
3578  char sverbuf[32];
3579 
3580  pg_log_error("The server (version %s) does not support per-database role settings.",
3582  sverbuf, sizeof(sverbuf)));
3583  return true;
3584  }
3585 
3586  initPQExpBuffer(&buf);
3587 
3588  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3589  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3590  "FROM pg_catalog.pg_db_role_setting s\n"
3591  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3592  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3593  gettext_noop("Role"),
3594  gettext_noop("Database"),
3595  gettext_noop("Settings"));
3596  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3597  NULL, "r.rolname", NULL, NULL);
3598  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3599  NULL, "d.datname", NULL, NULL);
3600  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3601 
3602  res = PSQLexec(buf.data);
3603  termPQExpBuffer(&buf);
3604  if (!res)
3605  return false;
3606 
3607  /*
3608  * Most functions in this file are content to print an empty table when
3609  * there are no matching objects. We intentionally deviate from that
3610  * here, but only in !quiet mode, because of the possibility that the user
3611  * is confused about what the two pattern arguments mean.
3612  */
3613  if (PQntuples(res) == 0 && !pset.quiet)
3614  {
3615  if (pattern && pattern2)
3616  pg_log_error("Did not find any settings for role \"%s\" and database \"%s\".",
3617  pattern, pattern2);
3618  else if (pattern)
3619  pg_log_error("Did not find any settings for role \"%s\".",
3620  pattern);
3621  else
3622  pg_log_error("Did not find any settings.");
3623  }
3624  else
3625  {
3626  myopt.nullPrint = NULL;
3627  myopt.title = _("List of settings");
3628  myopt.translate_header = true;
3629 
3630  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3631  }
3632 
3633  PQclear(res);
3634  return true;
3635 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:2769
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
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:546

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1089 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().

1090 {
1092  PGresult *res;
1093  printQueryOpt myopt = pset.popt;
1094  static const bool translate_columns[] = {false, false, true, false};
1095 
1096  if (pset.sversion < 90000)
1097  {
1098  char sverbuf[32];
1099 
1100  pg_log_error("The server (version %s) does not support altering default privileges.",
1102  sverbuf, sizeof(sverbuf)));
1103  return true;
1104  }
1105 
1106  initPQExpBuffer(&buf);
1107 
1108  printfPQExpBuffer(&buf,
1109  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1110  " n.nspname AS \"%s\",\n"
1111  " 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"
1112  " ",
1113  gettext_noop("Owner"),
1114  gettext_noop("Schema"),
1115  DEFACLOBJ_RELATION,
1116  gettext_noop("table"),
1117  DEFACLOBJ_SEQUENCE,
1118  gettext_noop("sequence"),
1119  DEFACLOBJ_FUNCTION,
1120  gettext_noop("function"),
1121  DEFACLOBJ_TYPE,
1122  gettext_noop("type"),
1123  DEFACLOBJ_NAMESPACE,
1124  gettext_noop("schema"),
1125  gettext_noop("Type"));
1126 
1127  printACLColumn(&buf, "d.defaclacl");
1128 
1129  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1130  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1131 
1132  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1133  NULL,
1134  "n.nspname",
1135  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1136  NULL);
1137 
1138  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1139 
1140  res = PSQLexec(buf.data);
1141  if (!res)
1142  {
1143  termPQExpBuffer(&buf);
1144  return false;
1145  }
1146 
1147  myopt.nullPrint = NULL;
1148  printfPQExpBuffer(&buf, _("Default access privileges"));
1149  myopt.title = buf.data;
1150  myopt.translate_header = true;
1151  myopt.translate_columns = translate_columns;
1152  myopt.n_translate_columns = lengthof(translate_columns);
1153 
1154  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1155 
1156  termPQExpBuffer(&buf);
1157  PQclear(res);
1158  return true;
1159 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
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:546

◆ listDomains()

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

Definition at line 4133 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().

4134 {
4136  PGresult *res;
4137  printQueryOpt myopt = pset.popt;
4138 
4139  initPQExpBuffer(&buf);
4140 
4141  printfPQExpBuffer(&buf,
4142  "SELECT n.nspname as \"%s\",\n"
4143  " t.typname as \"%s\",\n"
4144  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
4145  gettext_noop("Schema"),
4146  gettext_noop("Name"),
4147  gettext_noop("Type"));
4148 
4149  if (pset.sversion >= 90100)
4150  appendPQExpBuffer(&buf,
4151  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4152  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
4153  gettext_noop("Collation"));
4154  appendPQExpBuffer(&buf,
4155  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4156  " t.typdefault as \"%s\",\n"
4157  " pg_catalog.array_to_string(ARRAY(\n"
4158  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4159  " ), ' ') as \"%s\"",
4160  gettext_noop("Nullable"),
4161  gettext_noop("Default"),
4162  gettext_noop("Check"));
4163 
4164  if (verbose)
4165  {
4166  if (pset.sversion >= 90200)
4167  {
4168  appendPQExpBufferStr(&buf, ",\n ");
4169  printACLColumn(&buf, "t.typacl");
4170  }
4171  appendPQExpBuffer(&buf,
4172  ",\n d.description as \"%s\"",
4173  gettext_noop("Description"));
4174  }
4175 
4176  appendPQExpBufferStr(&buf,
4177  "\nFROM pg_catalog.pg_type t\n"
4178  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4179 
4180  if (verbose)
4181  appendPQExpBufferStr(&buf,
4182  " LEFT JOIN pg_catalog.pg_description d "
4183  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4184  "AND d.objsubid = 0\n");
4185 
4186  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
4187 
4188  if (!showSystem && !pattern)
4189  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4190  " AND n.nspname <> 'information_schema'\n");
4191 
4192  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4193  "n.nspname", "t.typname", NULL,
4194  "pg_catalog.pg_type_is_visible(t.oid)");
4195 
4196  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4197 
4198  res = PSQLexec(buf.data);
4199  termPQExpBuffer(&buf);
4200  if (!res)
4201  return false;
4202 
4203  myopt.nullPrint = NULL;
4204  myopt.title = _("List of domains");
4205  myopt.translate_header = true;
4206 
4207  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4208 
4209  PQclear(res);
4210  return true;
4211 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listEventTriggers()

bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 4295 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().

4296 {
4298  PGresult *res;
4299  printQueryOpt myopt = pset.popt;
4300  static const bool translate_columns[] =
4301  {false, false, false, true, false, false, false};
4302 
4303  initPQExpBuffer(&buf);
4304 
4305  printfPQExpBuffer(&buf,
4306  "SELECT evtname as \"%s\", "
4307  "evtevent as \"%s\", "
4308  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4309  " case evtenabled when 'O' then '%s'"
4310  " when 'R' then '%s'"
4311  " when 'A' then '%s'"
4312  " when 'D' then '%s' end as \"%s\",\n"
4313  " e.evtfoid::pg_catalog.regproc as \"%s\", "
4314  "pg_catalog.array_to_string(array(select x"
4315  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4316  gettext_noop("Name"),
4317  gettext_noop("Event"),
4318  gettext_noop("Owner"),
4319  gettext_noop("enabled"),
4320  gettext_noop("replica"),
4321  gettext_noop("always"),
4322  gettext_noop("disabled"),
4323  gettext_noop("Enabled"),
4324  gettext_noop("Function"),
4325  gettext_noop("Tags"));
4326  if (verbose)
4327  appendPQExpBuffer(&buf,
4328  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4329  gettext_noop("Description"));
4330  appendPQExpBufferStr(&buf,
4331  "\nFROM pg_catalog.pg_event_trigger e ");
4332 
4333  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4334  NULL, "evtname", NULL, NULL);
4335 
4336  appendPQExpBufferStr(&buf, "ORDER BY 1");
4337 
4338  res = PSQLexec(buf.data);
4339  termPQExpBuffer(&buf);
4340  if (!res)
4341  return false;
4342 
4343  myopt.nullPrint = NULL;
4344  myopt.title = _("List of event triggers");
4345  myopt.translate_header = true;
4346  myopt.translate_columns = translate_columns;
4347  myopt.n_translate_columns = lengthof(translate_columns);
4348 
4349  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4350 
4351  PQclear(res);
4352  return true;
4353 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listExtensionContents()

bool listExtensionContents ( const char *  pattern)

Definition at line 5591 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().

5592 {
5594  PGresult *res;
5595  int i;
5596 
5597  if (pset.sversion < 90100)
5598  {
5599  char sverbuf[32];
5600 
5601  pg_log_error("The server (version %s) does not support extensions.",
5603  sverbuf, sizeof(sverbuf)));
5604  return true;
5605  }
5606 
5607  initPQExpBuffer(&buf);
5608  printfPQExpBuffer(&buf,
5609  "SELECT e.extname, e.oid\n"
5610  "FROM pg_catalog.pg_extension e\n");
5611 
5612  processSQLNamePattern(pset.db, &buf, pattern,
5613  false, false,
5614  NULL, "e.extname", NULL,
5615  NULL);
5616 
5617  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5618 
5619  res = PSQLexec(buf.data);
5620  termPQExpBuffer(&buf);
5621  if (!res)
5622  return false;
5623 
5624  if (PQntuples(res) == 0)
5625  {
5626  if (!pset.quiet)
5627  {
5628  if (pattern)
5629  pg_log_error("Did not find any extension named \"%s\".",
5630  pattern);
5631  else
5632  pg_log_error("Did not find any extensions.");
5633  }
5634  PQclear(res);
5635  return false;
5636  }
5637 
5638  for (i = 0; i < PQntuples(res); i++)
5639  {
5640  const char *extname;
5641  const char *oid;
5642 
5643  extname = PQgetvalue(res, i, 0);
5644  oid = PQgetvalue(res, i, 1);
5645 
5646  if (!listOneExtensionContents(extname, oid))
5647  {
5648  PQclear(res);
5649  return false;
5650  }
5651  if (cancel_pressed)
5652  {
5653  PQclear(res);
5654  return false;
5655  }
5656  }
5657 
5658  PQclear(res);
5659  return true;
5660 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
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:2769
volatile bool cancel_pressed
Definition: print.c:44
static char * buf
Definition: pg_test_fsync.c:67
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5663
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:546

◆ listExtensions()

bool listExtensions ( const char *  pattern)

Definition at line 5534 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().

5535 {
5537  PGresult *res;
5538  printQueryOpt myopt = pset.popt;
5539 
5540  if (pset.sversion < 90100)
5541  {
5542  char sverbuf[32];
5543 
5544  pg_log_error("The server (version %s) does not support extensions.",
5546  sverbuf, sizeof(sverbuf)));
5547  return true;
5548  }
5549 
5550  initPQExpBuffer(&buf);
5551  printfPQExpBuffer(&buf,
5552  "SELECT e.extname AS \"%s\", "
5553  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
5554  "FROM pg_catalog.pg_extension e "
5555  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
5556  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
5557  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
5558  gettext_noop("Name"),
5559  gettext_noop("Version"),
5560  gettext_noop("Schema"),
5561  gettext_noop("Description"));
5562 
5563  processSQLNamePattern(pset.db, &buf, pattern,
5564  false, false,
5565  NULL, "e.extname", NULL,
5566  NULL);
5567 
5568  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5569 
5570  res = PSQLexec(buf.data);
5571  termPQExpBuffer(&buf);
5572  if (!res)
5573  return false;
5574 
5575  myopt.nullPrint = NULL;
5576  myopt.title = _("List of installed extensions");
5577  myopt.translate_header = true;
5578 
5579  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5580 
5581  PQclear(res);
5582  return true;
5583 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
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:546

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 5230 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().

5231 {
5233  PGresult *res;
5234  printQueryOpt myopt = pset.popt;
5235 
5236  if (pset.sversion < 80400)
5237  {
5238  char sverbuf[32];
5239 
5240  pg_log_error("The server (version %s) does not support foreign-data wrappers.",
5242  sverbuf, sizeof(sverbuf)));
5243  return true;
5244  }
5245 
5246  initPQExpBuffer(&buf);
5247  printfPQExpBuffer(&buf,
5248  "SELECT fdw.fdwname AS \"%s\",\n"
5249  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
5250  gettext_noop("Name"),
5251  gettext_noop("Owner"));
5252  if (pset.sversion >= 90100)
5253  appendPQExpBuffer(&buf,
5254  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
5255  gettext_noop("Handler"));
5256  appendPQExpBuffer(&buf,
5257  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5258  gettext_noop("Validator"));
5259 
5260  if (verbose)
5261  {
5262  appendPQExpBufferStr(&buf, ",\n ");
5263  printACLColumn(&buf, "fdwacl");
5264  appendPQExpBuffer(&buf,
5265  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5266  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5267  " pg_catalog.quote_ident(option_name) || ' ' || "
5268  " pg_catalog.quote_literal(option_value) FROM "
5269  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5270  " END AS \"%s\"",
5271  gettext_noop("FDW options"));
5272 
5273  if (pset.sversion >= 90100)
5274  appendPQExpBuffer(&buf,
5275  ",\n d.description AS \"%s\" ",
5276  gettext_noop("Description"));
5277  }
5278 
5279  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
5280 
5281  if (verbose && pset.sversion >= 90100)
5282  appendPQExpBufferStr(&buf,
5283  "LEFT JOIN pg_catalog.pg_description d\n"
5284  " ON d.classoid = fdw.tableoid "
5285  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5286 
5287  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5288  NULL, "fdwname", NULL, NULL);
5289 
5290  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5291 
5292  res = PSQLexec(buf.data);
5293  termPQExpBuffer(&buf);
5294  if (!res)
5295  return false;
5296 
5297  myopt.nullPrint = NULL;
5298  myopt.title = _("List of foreign-data wrappers");
5299  myopt.translate_header = true;
5300 
5301  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5302 
5303  PQclear(res);
5304  return true;
5305 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
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:546

◆ listForeignServers()

bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 5313 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().

5314 {
5316  PGresult *res;
5317  printQueryOpt myopt = pset.popt;
5318 
5319  if (pset.sversion < 80400)
5320  {
5321  char sverbuf[32];
5322 
5323  pg_log_error("The server (version %s) does not support foreign servers.",
5325  sverbuf, sizeof(sverbuf)));
5326  return true;
5327  }
5328 
5329  initPQExpBuffer(&buf);
5330  printfPQExpBuffer(&buf,
5331  "SELECT s.srvname AS \"%s\",\n"
5332  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5333  " f.fdwname AS \"%s\"",
5334  gettext_noop("Name"),
5335  gettext_noop("Owner"),
5336  gettext_noop("Foreign-data wrapper"));
5337 
5338  if (verbose)
5339  {
5340  appendPQExpBufferStr(&buf, ",\n ");
5341  printACLColumn(&buf, "s.srvacl");
5342  appendPQExpBuffer(&buf,
5343  ",\n"
5344  " s.srvtype AS \"%s\",\n"
5345  " s.srvversion AS \"%s\",\n"
5346  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5347  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5348  " pg_catalog.quote_ident(option_name) || ' ' || "
5349  " pg_catalog.quote_literal(option_value) FROM "
5350  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
5351  " END AS \"%s\",\n"
5352  " d.description AS \"%s\"",
5353  gettext_noop("Type"),
5354  gettext_noop("Version"),
5355  gettext_noop("FDW options"),
5356  gettext_noop("Description"));
5357  }
5358 
5359  appendPQExpBufferStr(&buf,
5360  "\nFROM pg_catalog.pg_foreign_server s\n"
5361  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
5362 
5363  if (verbose)
5364  appendPQExpBufferStr(&buf,
5365  "LEFT JOIN pg_catalog.pg_description d\n "
5366  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
5367  "AND d.objsubid = 0\n");
5368 
5369  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5370  NULL, "s.srvname", NULL, NULL);
5371 
5372  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5373 
5374  res = PSQLexec(buf.data);
5375  termPQExpBuffer(&buf);
5376  if (!res)
5377  return false;
5378 
5379  myopt.nullPrint = NULL;
5380  myopt.title = _("List of foreign servers");
5381  myopt.translate_header = true;
5382 
5383  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5384 
5385  PQclear(res);
5386  return true;
5387 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
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:546

◆ listForeignTables()

bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 5456 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().

5457 {
5459  PGresult *res;
5460  printQueryOpt myopt = pset.popt;
5461 
5462  if (pset.sversion < 90100)
5463  {
5464  char sverbuf[32];
5465 
5466  pg_log_error("The server (version %s) does not support foreign tables.",
5468  sverbuf, sizeof(sverbuf)));
5469  return true;
5470  }
5471 
5472  initPQExpBuffer(&buf);
5473  printfPQExpBuffer(&buf,
5474  "SELECT n.nspname AS \"%s\",\n"
5475  " c.relname AS \"%s\",\n"
5476  " s.srvname AS \"%s\"",
5477  gettext_noop("Schema"),
5478  gettext_noop("Table"),
5479  gettext_noop("Server"));
5480 
5481  if (verbose)
5482  appendPQExpBuffer(&buf,
5483  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
5484  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5485  " pg_catalog.quote_ident(option_name) || ' ' || "
5486  " pg_catalog.quote_literal(option_value) FROM "
5487  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
5488  " END AS \"%s\",\n"
5489  " d.description AS \"%s\"",
5490  gettext_noop("FDW options"),
5491  gettext_noop("Description"));
5492 
5493  appendPQExpBufferStr(&buf,
5494  "\nFROM pg_catalog.pg_foreign_table ft\n"
5495  " INNER JOIN pg_catalog.pg_class c"
5496  " ON c.oid = ft.ftrelid\n"
5497  " INNER JOIN pg_catalog.pg_namespace n"
5498  " ON n.oid = c.relnamespace\n"
5499  " INNER JOIN pg_catalog.pg_foreign_server s"
5500  " ON s.oid = ft.ftserver\n");
5501  if (verbose)
5502  appendPQExpBufferStr(&buf,
5503  " LEFT JOIN pg_catalog.pg_description d\n"
5504  " ON d.classoid = c.tableoid AND "
5505  "d.objoid = c.oid AND d.objsubid = 0\n");
5506 
5507  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5508  "n.nspname", "c.relname", NULL,
5509  "pg_catalog.pg_table_is_visible(c.oid)");
5510 
5511  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5512 
5513  res = PSQLexec(buf.data);
5514  termPQExpBuffer(&buf);
5515  if (!res)
5516  return false;
5517 
5518  myopt.nullPrint = NULL;
5519  myopt.title = _("List of foreign tables");
5520  myopt.translate_header = true;
5521 
5522  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5523 
5524  PQclear(res);
5525  return true;
5526 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
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:546

◆ listLanguages()

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

Definition at line 4058 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().

4059 {
4061  PGresult *res;
4062  printQueryOpt myopt = pset.popt;
4063 
4064  initPQExpBuffer(&buf);
4065 
4066  printfPQExpBuffer(&buf,
4067  "SELECT l.lanname AS \"%s\",\n",
4068  gettext_noop("Name"));
4069  if (pset.sversion >= 80300)
4070  appendPQExpBuffer(&buf,
4071  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
4072  gettext_noop("Owner"));
4073 
4074  appendPQExpBuffer(&buf,
4075  " l.lanpltrusted AS \"%s\"",
4076  gettext_noop("Trusted"));
4077 
4078  if (verbose)
4079  {
4080  appendPQExpBuffer(&buf,
4081  ",\n NOT l.lanispl AS \"%s\",\n"
4082  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4083  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n ",
4084  gettext_noop("Internal language"),
4085  gettext_noop("Call handler"),
4086  gettext_noop("Validator"));
4087  if (pset.sversion >= 90000)
4088  appendPQExpBuffer(&buf, "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4089  gettext_noop("Inline handler"));
4090  printACLColumn(&buf, "l.lanacl");
4091  }
4092 
4093  appendPQExpBuffer(&buf,
4094  ",\n d.description AS \"%s\""
4095  "\nFROM pg_catalog.pg_language l\n"
4096  "LEFT JOIN pg_catalog.pg_description d\n"
4097  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4098  " AND d.objsubid = 0\n",
4099  gettext_noop("Description"));
4100 
4101  if (pattern)
4102  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4103  NULL, "l.lanname", NULL, NULL);
4104 
4105  if (!showSystem && !pattern)
4106  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
4107 
4108 
4109  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4110 
4111  res = PSQLexec(buf.data);
4112  termPQExpBuffer(&buf);
4113  if (!res)
4114  return false;
4115 
4116  myopt.nullPrint = NULL;
4117  myopt.title = _("List of languages");
4118  myopt.translate_header = true;
4119 
4120  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4121 
4122  PQclear(res);
4123  return true;
4124 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listPartitionedTables()

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

Definition at line 3854 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().

3855 {
3856  bool showTables = strchr(reltypes, 't') != NULL;
3857  bool showIndexes = strchr(reltypes, 'i') != NULL;
3858  bool showNested = strchr(reltypes, 'n') != NULL;
3860  PQExpBufferData title;
3861  PGresult *res;
3862  printQueryOpt myopt = pset.popt;
3863  bool translate_columns[] = {false, false, false, false, false, false, false, false, false};
3864  const char *tabletitle;
3865  bool mixed_output = false;
3866 
3867  /*
3868  * Note: Declarative table partitioning is only supported as of Pg 10.0.
3869  */
3870  if (pset.sversion < 100000)
3871  {
3872  char sverbuf[32];
3873 
3874  pg_log_error("The server (version %s) does not support declarative table partitioning.",
3876  sverbuf, sizeof(sverbuf)));
3877  return true;
3878  }
3879 
3880  /* If no relation kind was selected, show them all */
3881  if (!showTables && !showIndexes)
3882  showTables = showIndexes = true;
3883 
3884  if (showIndexes && !showTables)
3885  tabletitle = _("List of partitioned indexes"); /* \dPi */
3886  else if (showTables && !showIndexes)
3887  tabletitle = _("List of partitioned tables"); /* \dPt */
3888  else
3889  {
3890  /* show all kinds */
3891  tabletitle = _("List of partitioned relations");
3892  mixed_output = true;
3893  }
3894 
3895  initPQExpBuffer(&buf);
3896 
3897  printfPQExpBuffer(&buf,
3898  "SELECT n.nspname as \"%s\",\n"
3899  " c.relname as \"%s\",\n"
3900  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3901  gettext_noop("Schema"),
3902  gettext_noop("Name"),
3903  gettext_noop("Owner"));
3904 
3905  if (mixed_output)
3906  {
3907  appendPQExpBuffer(&buf,
3908  ",\n CASE c.relkind"
3909  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3910  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
3911  " END as \"%s\"",
3912  gettext_noop("partitioned table"),
3913  gettext_noop("partitioned index"),
3914  gettext_noop("Type"));
3915 
3916  translate_columns[3] = true;
3917  }
3918 
3919  if (showNested || pattern)
3920  appendPQExpBuffer(&buf,
3921  ",\n inh.inhparent::regclass as \"%s\"",
3922  gettext_noop("Parent name"));
3923 
3924  if (showIndexes)
3925  appendPQExpBuffer(&buf,
3926  ",\n c2.oid::regclass as \"%s\"",
3927  gettext_noop("Table"));
3928 
3929  if (verbose)
3930  {
3931  if (showNested)
3932  {
3933  appendPQExpBuffer(&buf,
3934  ",\n s.dps as \"%s\"",
3935  gettext_noop("Leaf partition size"));
3936  appendPQExpBuffer(&buf,
3937  ",\n s.tps as \"%s\"",
3938  gettext_noop("Total size"));
3939  }
3940  else
3941  /* Sizes of all partitions are considered in this case. */
3942  appendPQExpBuffer(&buf,
3943  ",\n s.tps as \"%s\"",
3944  gettext_noop("Total size"));
3945 
3946  appendPQExpBuffer(&buf,
3947  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3948  gettext_noop("Description"));
3949  }
3950 
3951  appendPQExpBufferStr(&buf,
3952  "\nFROM pg_catalog.pg_class c"
3953  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3954 
3955  if (showIndexes)
3956  appendPQExpBufferStr(&buf,
3957  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3958  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3959 
3960  if (showNested || pattern)
3961  appendPQExpBufferStr(&buf,
3962  "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
3963 
3964  if (verbose)
3965  {
3966  if (pset.sversion < 120000)
3967  {
3968  appendPQExpBufferStr(&buf,
3969  ",\n LATERAL (WITH RECURSIVE d\n"
3970  " AS (SELECT inhrelid AS oid, 1 AS level\n"
3971  " FROM pg_catalog.pg_inherits\n"
3972  " WHERE inhparent = c.oid\n"
3973  " UNION ALL\n"
3974  " SELECT inhrelid, level + 1\n"
3975  " FROM pg_catalog.pg_inherits i\n"
3976  " JOIN d ON i.inhparent = d.oid)\n"
3977  " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
3978  "d.oid))) AS tps,\n"
3979  " pg_catalog.pg_size_pretty(sum("
3980  "\n CASE WHEN d.level = 1"
3981  " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
3982  " FROM d) s");
3983  }
3984  else
3985  {
3986  /* PostgreSQL 12 has pg_partition_tree function */
3987  appendPQExpBufferStr(&buf,
3988  ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
3989  "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
3990  "\n THEN pg_catalog.pg_table_size(ppt.relid)"
3991  " ELSE 0 END)) AS dps"
3992  ",\n pg_catalog.pg_size_pretty(sum("
3993  "pg_catalog.pg_table_size(ppt.relid))) AS tps"
3994  "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
3995  }
3996  }
3997 
3998  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3999  if (showTables)
4000  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
4001  if (showIndexes)
4002  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
4003  appendPQExpBufferStr(&buf, "''"); /* dummy */
4004  appendPQExpBufferStr(&buf, ")\n");
4005 
4006  appendPQExpBufferStr(&buf, !showNested && !pattern ?
4007  " AND NOT c.relispartition\n" : "");
4008 
4009  if (!pattern)
4010  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4011  " AND n.nspname <> 'information_schema'\n");
4012 
4013  /*
4014  * TOAST objects are suppressed unconditionally. Since we don't provide
4015  * any way to select RELKIND_TOASTVALUE above, we would never show toast
4016  * tables in any case; it seems a bit confusing to allow their indexes to
4017  * be shown. Use plain \d if you really need to look at a TOAST
4018  * table/index.
4019  */
4020  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
4021 
4022  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4023  "n.nspname", "c.relname", NULL,
4024  "pg_catalog.pg_table_is_visible(c.oid)");
4025 
4026  appendPQExpBuffer(&buf, "ORDER BY \"Schema\", %s%s\"Name\";",
4027  mixed_output ? "\"Type\" DESC, " : "",
4028  showNested || pattern ? "\"Parent name\" NULLS FIRST, " : "");
4029 
4030  res = PSQLexec(buf.data);
4031  termPQExpBuffer(&buf);
4032  if (!res)
4033  return false;
4034 
4035  initPQExpBuffer(&title);
4036  appendPQExpBufferStr(&title, tabletitle);
4037 
4038  myopt.nullPrint = NULL;
4039  myopt.title = title.data;
4040  myopt.translate_header = true;
4041  myopt.translate_columns = translate_columns;
4042  myopt.n_translate_columns = lengthof(translate_columns);
4043 
4044  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4045 
4046  termPQExpBuffer(&title);
4047 
4048  PQclear(res);
4049  return true;
4050 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
#define CppAsString2(x)
Definition: c.h:224
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
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:546

◆ listPublications()

bool listPublications ( const char *  pattern)

Definition at line 5704 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().

5705 {
5707  PGresult *res;
5708  printQueryOpt myopt = pset.popt;
5709  static const bool translate_columns[] = {false, false, false, false, false, false, false};
5710 
5711  if (pset.sversion < 100000)
5712  {
5713  char sverbuf[32];
5714 
5715  pg_log_error("The server (version %s) does not support publications.",
5717  sverbuf, sizeof(sverbuf)));
5718  return true;
5719  }
5720 
5721  initPQExpBuffer(&buf);
5722 
5723  printfPQExpBuffer(&buf,
5724  "SELECT pubname AS \"%s\",\n"
5725  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5726  " puballtables AS \"%s\",\n"
5727  " pubinsert AS \"%s\",\n"
5728  " pubupdate AS \"%s\",\n"
5729  " pubdelete AS \"%s\"",
5730  gettext_noop("Name"),
5731  gettext_noop("Owner"),
5732  gettext_noop("All tables"),
5733  gettext_noop("Inserts"),
5734  gettext_noop("Updates"),
5735  gettext_noop("Deletes"));
5736  if (pset.sversion >= 110000)
5737  appendPQExpBuffer(&buf,
5738  ",\n pubtruncate AS \"%s\"",
5739  gettext_noop("Truncates"));
5740 
5741  appendPQExpBufferStr(&buf,
5742  "\nFROM pg_catalog.pg_publication\n");
5743 
5744  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5745  NULL, "pubname", NULL,
5746  NULL);
5747 
5748  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5749 
5750  res = PSQLexec(buf.data);
5751  termPQExpBuffer(&buf);
5752  if (!res)
5753  return false;
5754 
5755  myopt.nullPrint = NULL;
5756  myopt.title = _("List of publications");
5757  myopt.translate_header = true;
5758  myopt.translate_columns = translate_columns;
5759  myopt.n_translate_columns = lengthof(translate_columns);
5760 
5761  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5762 
5763  PQclear(res);
5764 
5765  return true;
5766 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
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:546

◆ listSchemas()

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

Definition at line 4578 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().

4579 {
4581  PGresult *res;
4582  printQueryOpt myopt = pset.popt;
4583 
4584  initPQExpBuffer(&buf);
4585  printfPQExpBuffer(&buf,
4586  "SELECT n.nspname AS \"%s\",\n"
4587  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4588  gettext_noop("Name"),
4589  gettext_noop("Owner"));
4590 
4591  if (verbose)
4592  {
4593  appendPQExpBufferStr(&buf, ",\n ");
4594  printACLColumn(&buf, "n.nspacl");
4595  appendPQExpBuffer(&buf,
4596  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4597  gettext_noop("Description"));
4598  }
4599 
4600  appendPQExpBufferStr(&buf,
4601  "\nFROM pg_catalog.pg_namespace n\n");
4602 
4603  if (!showSystem && !pattern)
4604  appendPQExpBufferStr(&buf,
4605  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
4606 
4607  processSQLNamePattern(pset.db, &buf, pattern,
4608  !showSystem && !pattern, false,
4609  NULL, "n.nspname", NULL,
4610  NULL);
4611 
4612  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4613 
4614  res = PSQLexec(buf.data);
4615  termPQExpBuffer(&buf);
4616  if (!res)
4617  return false;
4618 
4619  myopt.nullPrint = NULL;
4620  myopt.title = _("List of schemas");
4621  myopt.translate_header = true;
4622 
4623  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4624 
4625  PQclear(res);
4626  return true;
4627 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
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:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6007
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listTables()

bool listTables ( const char *  tabtypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3653 of file describe.c.

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

Referenced by exec_command_d().

3654 {
3655  bool showTables = strchr(tabtypes, 't') != NULL;
3656  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3657  bool showViews = strchr(tabtypes, 'v') != NULL;
3658  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3659  bool showSeq = strchr(tabtypes, 's') != NULL;
3660  bool showForeign = strchr(tabtypes, 'E') != NULL;
3661 
3663  PGresult *res;
3664  printQueryOpt myopt = pset.popt;
3665  int cols_so_far;
3666  bool translate_columns[] = {false, false, true, false, false, false, false, false};
3667 
3668  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3669  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3670  showTables = showViews = showMatViews = showSeq = showForeign = true;
3671 
3672  initPQExpBuffer(&buf);
3673 
3674  /*
3675  * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
3676  * it here for backwards compatibility.
3677  */
3678  printfPQExpBuffer(&buf,
3679  "SELECT n.nspname as \"%s\",\n"
3680  " c.relname as \"%s\",\n"
3681  " CASE c.relkind"
3682  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3683  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3684  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3685  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3686  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3687  " WHEN 's' THEN '%s'"
3688  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3689  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3690  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
3691  " END as \"%s\",\n"
3692  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3693  gettext_noop("Schema"),
3694  gettext_noop("Name"),
3695  gettext_noop("table"),
3696  gettext_noop("view"),
3697  gettext_noop("materialized view"),
3698  gettext_noop("index"),
3699  gettext_noop("sequence"),
3700  gettext_noop("special"),
3701  gettext_noop("foreign table"),
3702  gettext_noop("partitioned table"),
3703  gettext_noop("partitioned index"),
3704  gettext_noop("Type"),
3705  gettext_noop("Owner"));
3706  cols_so_far = 4;
3707 
3708  if (showIndexes)
3709  {
3710  appendPQExpBuffer(&buf,
3711  ",\n c2.relname as \"%s\"",
3712  gettext_noop("Table"));
3713  cols_so_far++;
3714  }
3715 
3716  if (verbose)
3717  {
3718  /*
3719  * Show whether a relation is permanent, temporary, or unlogged. Like
3720  * describeOneTableDetails(), we consider that persistence emerged in
3721  * v9.1, even though related concepts existed before.
3722  */
3723  if (pset.sversion >= 90100)
3724  {
3725  appendPQExpBuffer(&buf,
3726  ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3727  gettext_noop("permanent"),
3728  gettext_noop("temporary"),
3729  gettext_noop("unlogged"),
3730  gettext_noop("Persistence"));
3731  translate_columns[cols_so_far] = true;
3732  }
3733 
3734  /*
3735  * We don't bother to count cols_so_far below here, as there's no need
3736  * to; this might change with future additions to the output columns.
3737  */
3738 
3739  /*
3740  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3741  * size of a table, including FSM, VM and TOAST tables.
3742  */
3743  if (pset.sversion >= 90000)
3744  appendPQExpBuffer(&buf,
3745  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3746  gettext_noop("Size"));
3747  else if (pset.sversion >= 80100)
3748  appendPQExpBuffer(&buf,
3749  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3750  gettext_noop("Size"));
3751 
3752  appendPQExpBuffer(&buf,
3753  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3754  gettext_noop("Description"));
3755  }
3756 
3757  appendPQExpBufferStr(&buf,
3758  "\nFROM pg_catalog.pg_class c"
3759  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3760  if (showIndexes)
3761  appendPQExpBufferStr(&buf,
3762  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3763  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3764 
3765  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3766  if (showTables)
3767  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
3768  CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
3769  if (showViews)
3770  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
3771  if (showMatViews)
3772  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_MATVIEW) ",");
3773  if (showIndexes)
3774  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_INDEX) ","
3775  CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
3776  if (showSeq)
3777  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ",");
3778  if (showSystem || pattern)
3779  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3780  if (showForeign)
3781  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ",");
3782 
3783  appendPQExpBufferStr(&buf, "''"); /* dummy */
3784  appendPQExpBufferStr(&buf, ")\n");
3785 
3786  if (!showSystem && !pattern)
3787  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3788  " AND n.nspname <> 'information_schema'\n");
3789 
3790  /*
3791  * TOAST objects are suppressed unconditionally. Since we don't provide
3792  * any way to select RELKIND_TOASTVALUE above, we would never show toast
3793  * tables in any case; it seems a bit confusing to allow their indexes to
3794  * be shown. Use plain \d if you really need to look at a TOAST
3795  * table/index.
3796  */
3797  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3798 
3799  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3800  "n.nspname", "c.relname", NULL,
3801  "pg_catalog.pg_table_is_visible(c.oid)");
3802 
3803  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3804 
3805  res = PSQLexec(buf.data);
3806  termPQExpBuffer(&buf);
3807  if (!res)
3808  return false;
3809 
3810  /*
3811  * Most functions in this file are content to print an empty table when
3812  * there are no matching objects. We intentionally deviate from that
3813  * here, but only in !quiet mode, for historical reasons.
3814  */
3815  if (PQntuples(res) == 0 && !pset.quiet)
3816  {
3817  if (pattern)
3818  pg_log_error("Did not find any relation named \"%s\".",
3819  pattern);
3820  else
3821  pg_log_error("Did not find any relations.");
3822  }
3823  else
3824  {
3825  myopt.nullPrint = NULL;
3826  myopt.title = _("List of relations");
3827  myopt.translate_header = true;
3828  myopt.translate_columns = translate_columns;
3829  myopt.n_translate_columns = lengthof(translate_columns);
3830 
3831  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3832  }
3833 
3834  PQclear(res);
3835  return true;
3836 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:669
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
#define CppAsString2(x)
Definition: c.h:224
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:174
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
const bool * translate_columns
Definition: print.h:172
#define _(x)
Definition: elog.c:87
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:546

◆ listTSConfigs()

bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

Definition at line 5024 of file describe.c.

References _, appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), listTSConfigsVerbose(), _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().

5025 {
5027  PGresult *res;
5028  printQueryOpt myopt = pset.popt;
5029 
5030  if (pset.sversion < 80300)
5031  {
5032  char sverbuf[32];
5033 
5034  pg_log_error("The server (version %s) does not support full text search.",
5036  sverbuf, sizeof(sverbuf)));
5037  return true;
5038  }
5039 
5040  if (verbose)
5041  return listTSConfigsVerbose(pattern);
5042 
5043  initPQExpBuffer(&buf);
5044 
5045  printfPQExpBuffer(&buf,
5046  "SELECT\n"
5047  " n.nspname as \"%s\",\n"
5048  " c.cfgname as \"%s\",\n"
5049  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5050  "FROM pg_catalog.pg_ts_config c\n"
5051  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5052  gettext_noop("Schema"),
5053  gettext_noop("Name"),
5054  gettext_noop("Description")
5055  );
5056 
5057  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5058  "n.nspname", "c.cfgname", NULL,
5059  "pg_catalog.pg_ts_config_is_visible(c.oid)");
5060 
5061  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5062 
5063  res = PSQLexec(buf.data);
5064  termPQExpBuffer(&buf);
5065  if (!res)
5066  return false;
5067 
5068  myopt.nullPrint = NULL;
5069  myopt.title = _("List of text search configurations");
5070  myopt.translate_header = true;
5071 
5072  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5073 
5074  PQclear(res);
5075  return true;
5076 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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 bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:5079
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
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:546

◆ listTSDictionaries()

bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 4882 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().

4883 {
4885  PGresult *res;
4886  printQueryOpt myopt = pset.popt;
4887 
4888  if (pset.sversion < 80300)
4889  {
4890  char sverbuf[32];
4891 
4892  pg_log_error("The server (version %s) does not support full text search.",
4894  sverbuf, sizeof(sverbuf)));
4895  return true;
4896  }
4897 
4898  initPQExpBuffer(&buf);
4899 
4900  printfPQExpBuffer(&buf,
4901  "SELECT\n"
4902  " n.nspname as \"%s\",\n"
4903  " d.dictname as \"%s\",\n",
4904  gettext_noop("Schema"),
4905  gettext_noop("Name"));
4906 
4907  if (verbose)
4908  {
4909  appendPQExpBuffer(&buf,
4910  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
4911  " pg_catalog.pg_ts_template t\n"
4912  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
4913  " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
4914  " d.dictinitoption as \"%s\",\n",
4915  gettext_noop("Template"),
4916  gettext_noop("Init options"));
4917  }
4918 
4919  appendPQExpBuffer(&buf,
4920  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
4921  gettext_noop("Description"));
4922 
4923  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
4924  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
4925 
4926  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4927  "n.nspname", "d.dictname", NULL,
4928  "pg_catalog.pg_ts_dict_is_visible(d.oid)");
4929 
4930  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4931 
4932  res = PSQLexec(buf.data);
4933  termPQExpBuffer(&buf);
4934  if (!res)
4935  return false;
4936 
4937  myopt.nullPrint = NULL;
4938  myopt.title = _("List of text search dictionaries");
4939  myopt.translate_header = true;
4940 
4941  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4942 
4943  PQclear(res);
4944  return true;
4945 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
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:546

◆ listTSParsers()

bool listTSParsers ( const char *  pattern,
bool  verbose 
)

Definition at line 4635 of file describe.c.

References _, appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), listTSParsersVerbose(), _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().

4636 {
4638  PGresult *res;
4639  printQueryOpt myopt = pset.popt;
4640 
4641  if (pset.sversion < 80300)
4642  {
4643  char sverbuf[32];
4644 
4645  pg_log_error("The server (version %s) does not support full text search.",
4647  sverbuf, sizeof(sverbuf)));
4648  return true;
4649  }
4650 
4651  if (verbose)
4652  return listTSParsersVerbose(pattern);
4653 
4654  initPQExpBuffer(&buf);
4655 
4656  printfPQExpBuffer(&buf,
4657  "SELECT\n"
4658  " n.nspname as \"%s\",\n"
4659  " p.prsname as \"%s\",\n"
4660  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
4661  "FROM pg_catalog.pg_ts_parser p\n"
4662  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
4663  gettext_noop("Schema"),
4664  gettext_noop("Name"),
4665  gettext_noop("Description")
4666  );
4667 
4668  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4669  "n.nspname", "p.prsname", NULL,
4670  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
4671 
4672  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4673 
4674  res = PSQLexec(buf.data);
4675  termPQExpBuffer(&buf);
4676  if (!res)
4677  return false;
4678 
4679  myopt.nullPrint = NULL;
4680  myopt.title = _("List of text search parsers");
4681  myopt.translate_header = true;
4682 
4683  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4684 
4685  PQclear(res);
4686  return true;
4687 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:4693
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
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:546

◆ listTSTemplates()

bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

Definition at line 4953 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().

4954 {
4956  PGresult *res;
4957  printQueryOpt myopt = pset.popt;
4958 
4959  if (pset.sversion < 80300)
4960  {
4961  char sverbuf[32];
4962 
4963  pg_log_error("The server (version %s) does not support full text search.",
4965  sverbuf, sizeof(sverbuf)));
4966  return true;
4967  }
4968 
4969  initPQExpBuffer(&buf);
4970 
4971  if (verbose)
4972  printfPQExpBuffer(&buf,
4973  "SELECT\n"
4974  " n.nspname AS \"%s\",\n"
4975  " t.tmplname AS \"%s\",\n"
4976  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4977  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4978  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4979  gettext_noop("Schema"),
4980  gettext_noop("Name"),
4981  gettext_noop("Init"),
4982  gettext_noop("Lexize"),
4983  gettext_noop("Description"));
4984  else
4985  printfPQExpBuffer(&buf,
4986  "SELECT\n"
4987  " n.nspname AS \"%s\",\n"
4988  " t.tmplname AS \"%s\",\n"
4989  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4990  gettext_noop("Schema"),
4991  gettext_noop("Name"),
4992  gettext_noop("Description"));
4993 
4994  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4995  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4996 
4997  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4998  "n.nspname", "t.tmplname", NULL,
4999  "pg_catalog.pg_ts_template_is_visible(t.oid)");
5000 
5001  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5002 
5003  res = PSQLexec(buf.data);
5004  termPQExpBuffer(&buf);
5005  if (!res)
5006  return false;
5007 
5008  myopt.nullPrint = NULL;
5009  myopt.title = _("List of text search templates");
5010  myopt.translate_header = true;
5011 
5012  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5013 
5014  PQclear(res);
5015  return true;
5016 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3434
#define _(x)
Definition: elog.c:87
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:546

◆ listUserMappings()

bool listUserMappings ( const char *  pattern,
bool  verbose 
)

Definition at line 5395 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().

5396 {
5398  PGresult *res;
5399  printQueryOpt myopt = pset.popt;
5400 
5401  if (pset.sversion < 80400)
5402  {
5403  char sverbuf[32];
5404 
5405  pg_log_error("The server (version %s) does not support user mappings.",
5407  sverbuf, sizeof(sverbuf)));
5408  return true;
5409  }
5410 
5411  initPQExpBuffer(&buf);
5412  printfPQExpBuffer(&buf,
5413  "SELECT um.srvname AS \"%s\",\n"
5414  " um.usename AS \"%s\"",
5415  gettext_noop("Server"),
5416  gettext_noop("User name"));
5417 
5418  if (verbose)
5419  appendPQExpBuffer(&buf,
5420  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
5421  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5422  " pg_catalog.quote_ident(option_name) || ' ' || "
5423  " pg_catalog.quote_literal(option_value) FROM "
5424  " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
5425  " END AS \"%s\"",
5426  gettext_noop("FDW options"));
5427 
5428  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
5429 
5430  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5431  NULL, "um.srvname", "um.usename", NULL);
5432 
5433  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5434 
5435  res = PSQLexec(buf.data);
5436  termPQExpBuffer(&buf);
5437  if (!res)
5438  return false;
5439 
5440  myopt.nullPrint = NULL;
5441  myopt.title = _("List of user mappings");
5442  myopt.translate_header = true;
5443 
5444  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5445 
5446  PQclear(res);
5447  return true;
5448 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1148
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:67
bool translate_header
Definition: print.h:171
static int verbose
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:169
printQueryOpt popt
Definition: settings.h:91