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

Go to the source code of this file.

Functions

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

Function Documentation

◆ describeAccessMethods()

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 139 of file describe.c.

140 {
142  PGresult *res;
143  printQueryOpt myopt = pset.popt;
144  static const bool translate_columns[] = {false, true, false, false};
145 
146  if (pset.sversion < 90600)
147  {
148  char sverbuf[32];
149 
150  pg_log_error("The server (version %s) does not support access methods.",
152  sverbuf, sizeof(sverbuf)));
153  return true;
154  }
155 
157 
159  "SELECT amname AS \"%s\",\n"
160  " CASE amtype"
161  " WHEN 'i' THEN '%s'"
162  " WHEN 't' THEN '%s'"
163  " END AS \"%s\"",
164  gettext_noop("Name"),
165  gettext_noop("Index"),
166  gettext_noop("Table"),
167  gettext_noop("Type"));
168 
169  if (verbose)
170  {
172  ",\n amhandler AS \"%s\",\n"
173  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
174  gettext_noop("Handler"),
175  gettext_noop("Description"));
176  }
177 
179  "\nFROM pg_catalog.pg_am\n");
180 
181  if (!validateSQLNamePattern(&buf, pattern, false, false,
182  NULL, "amname", NULL,
183  NULL,
184  NULL, 1))
185  return false;
186 
187  appendPQExpBufferStr(&buf, "ORDER BY 1;");
188 
189  res = PSQLexec(buf.data);
191  if (!res)
192  return false;
193 
194  myopt.nullPrint = NULL;
195  myopt.title = _("List of access methods");
196  myopt.translate_header = true;
197  myopt.translate_columns = translate_columns;
198  myopt.n_translate_columns = lengthof(translate_columns);
199 
200  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
201 
202  PQclear(res);
203  return true;
204 }
PGresult * PSQLexec(const char *query)
Definition: common.c:556
#define gettext_noop(x)
Definition: c.h:1194
#define lengthof(array)
Definition: c.h:734
static bool validateSQLNamePattern(PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, bool *added_clause, int maxparts)
Definition: describe.c:5999
#define _(x)
Definition: elog.c:89
void PQclear(PGresult *res)
Definition: fe-exec.c:718
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3490
#define pg_log_error(...)
Definition: logging.h:106
static int verbose
static char * buf
Definition: pg_test_fsync.c:67
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
PsqlSettings pset
Definition: startup.c:32
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
printQueryOpt popt
Definition: settings.h:91
FILE * logfile
Definition: settings.h:116
FILE * queryFout
Definition: settings.h:84
const bool * translate_columns
Definition: print.h:174
char * nullPrint
Definition: print.h:170
char * title
Definition: print.h:171
bool translate_header
Definition: print.h:173
int n_translate_columns
Definition: print.h:176

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

Referenced by exec_command_d().

◆ describeAggregates()

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

Definition at line 71 of file describe.c.

72 {
74  PGresult *res;
75  printQueryOpt myopt = pset.popt;
76 
78 
80  "SELECT n.nspname as \"%s\",\n"
81  " p.proname AS \"%s\",\n"
82  " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n"
83  " CASE WHEN p.pronargs = 0\n"
84  " THEN CAST('*' AS pg_catalog.text)\n"
85  " ELSE pg_catalog.pg_get_function_arguments(p.oid)\n"
86  " END AS \"%s\",\n",
87  gettext_noop("Schema"),
88  gettext_noop("Name"),
89  gettext_noop("Result data type"),
90  gettext_noop("Argument data types"));
91 
92  if (pset.sversion >= 110000)
94  " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
95  "FROM pg_catalog.pg_proc p\n"
96  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
97  "WHERE p.prokind = 'a'\n",
98  gettext_noop("Description"));
99  else
101  " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
102  "FROM pg_catalog.pg_proc p\n"
103  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
104  "WHERE p.proisagg\n",
105  gettext_noop("Description"));
106 
107  if (!showSystem && !pattern)
108  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
109  " AND n.nspname <> 'information_schema'\n");
110 
111  if (!validateSQLNamePattern(&buf, pattern, true, false,
112  "n.nspname", "p.proname", NULL,
113  "pg_catalog.pg_function_is_visible(p.oid)",
114  NULL, 3))
115  return false;
116 
117  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
118 
119  res = PSQLexec(buf.data);
121  if (!res)
122  return false;
123 
124  myopt.nullPrint = NULL;
125  myopt.title = _("List of aggregate functions");
126  myopt.translate_header = true;
127 
128  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
129 
130  PQclear(res);
131  return true;
132 }

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

Referenced by exec_command_d().

◆ describeConfigurationParameters()

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

Definition at line 4428 of file describe.c.

4430 {
4432  PGresult *res;
4433  printQueryOpt myopt = pset.popt;
4434 
4435  initPQExpBuffer(&buf);
4437  "SELECT s.name AS \"%s\", "
4438  "pg_catalog.current_setting(s.name) AS \"%s\"",
4439  gettext_noop("Parameter"),
4440  gettext_noop("Value"));
4441 
4442  if (verbose)
4443  {
4445  ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4446  gettext_noop("Type"),
4447  gettext_noop("Context"));
4448  if (pset.sversion >= 150000)
4449  printACLColumn(&buf, "p.paracl");
4450  else
4451  appendPQExpBuffer(&buf, "NULL AS \"%s\"",
4452  gettext_noop("Access privileges"));
4453  }
4454 
4455  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_settings s\n");
4456 
4457  if (verbose && pset.sversion >= 150000)
4459  " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4460  " ON pg_catalog.lower(s.name) = p.parname\n");
4461 
4462  if (pattern)
4463  processSQLNamePattern(pset.db, &buf, pattern,
4464  false, false,
4465  NULL, "pg_catalog.lower(s.name)", NULL,
4466  NULL, NULL, NULL);
4467  else
4468  appendPQExpBufferStr(&buf, "WHERE s.source <> 'default' AND\n"
4469  " s.setting IS DISTINCT FROM s.boot_val\n");
4470 
4471  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4472 
4473  res = PSQLexec(buf.data);
4474  termPQExpBuffer(&buf);
4475  if (!res)
4476  return false;
4477 
4478  myopt.nullPrint = NULL;
4479  if (pattern)
4480  myopt.title = _("List of configuration parameters");
4481  else
4482  myopt.title = _("List of non-default configuration parameters");
4483  myopt.translate_header = true;
4484 
4485  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4486 
4487  PQclear(res);
4488  return true;
4489 }
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6452
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, PQExpBuffer dbnamebuf, int *dotcnt)
Definition: string_utils.c:893
PGconn * db
Definition: settings.h:82

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

Referenced by exec_command_d().

◆ describeFunctions()

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

Definition at line 282 of file describe.c.

285 {
286  bool showAggregate = strchr(functypes, 'a') != NULL;
287  bool showNormal = strchr(functypes, 'n') != NULL;
288  bool showProcedure = strchr(functypes, 'p') != NULL;
289  bool showTrigger = strchr(functypes, 't') != NULL;
290  bool showWindow = strchr(functypes, 'w') != NULL;
291  bool have_where;
293  PGresult *res;
294  printQueryOpt myopt = pset.popt;
295  static const bool translate_columns[] = {false, false, false, false, true, true, true, false, true, false, false, false, false};
296 
297  /* No "Parallel" column before 9.6 */
298  static const bool translate_columns_pre_96[] = {false, false, false, false, true, true, false, true, false, false, false, false};
299 
300  if (strlen(functypes) != strspn(functypes, "anptwS+"))
301  {
302  pg_log_error("\\df only takes [anptwS+] as options");
303  return true;
304  }
305 
306  if (showProcedure && pset.sversion < 110000)
307  {
308  char sverbuf[32];
309 
310  pg_log_error("\\df does not take a \"%c\" option with server version %s",
311  'p',
313  sverbuf, sizeof(sverbuf)));
314  return true;
315  }
316 
317  if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
318  {
319  showAggregate = showNormal = showTrigger = showWindow = true;
320  if (pset.sversion >= 110000)
321  showProcedure = true;
322  }
323 
325 
327  "SELECT n.nspname as \"%s\",\n"
328  " p.proname as \"%s\",\n",
329  gettext_noop("Schema"),
330  gettext_noop("Name"));
331 
332  if (pset.sversion >= 110000)
334  " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
335  " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
336  " CASE p.prokind\n"
337  " WHEN 'a' THEN '%s'\n"
338  " WHEN 'w' THEN '%s'\n"
339  " WHEN 'p' THEN '%s'\n"
340  " ELSE '%s'\n"
341  " END as \"%s\"",
342  gettext_noop("Result data type"),
343  gettext_noop("Argument data types"),
344  /* translator: "agg" is short for "aggregate" */
345  gettext_noop("agg"),
346  gettext_noop("window"),
347  gettext_noop("proc"),
348  gettext_noop("func"),
349  gettext_noop("Type"));
350  else
352  " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
353  " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
354  " CASE\n"
355  " WHEN p.proisagg THEN '%s'\n"
356  " WHEN p.proiswindow THEN '%s'\n"
357  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
358  " ELSE '%s'\n"
359  " END as \"%s\"",
360  gettext_noop("Result data type"),
361  gettext_noop("Argument data types"),
362  /* translator: "agg" is short for "aggregate" */
363  gettext_noop("agg"),
364  gettext_noop("window"),
365  gettext_noop("trigger"),
366  gettext_noop("func"),
367  gettext_noop("Type"));
368 
369  if (verbose)
370  {
372  ",\n CASE\n"
373  " WHEN p.provolatile = 'i' THEN '%s'\n"
374  " WHEN p.provolatile = 's' THEN '%s'\n"
375  " WHEN p.provolatile = 'v' THEN '%s'\n"
376  " END as \"%s\"",
377  gettext_noop("immutable"),
378  gettext_noop("stable"),
379  gettext_noop("volatile"),
380  gettext_noop("Volatility"));
381  if (pset.sversion >= 90600)
383  ",\n CASE\n"
384  " WHEN p.proparallel = 'r' THEN '%s'\n"
385  " WHEN p.proparallel = 's' THEN '%s'\n"
386  " WHEN p.proparallel = 'u' THEN '%s'\n"
387  " END as \"%s\"",
388  gettext_noop("restricted"),
389  gettext_noop("safe"),
390  gettext_noop("unsafe"),
391  gettext_noop("Parallel"));
393  ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
394  ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
395  gettext_noop("Owner"),
396  gettext_noop("definer"),
397  gettext_noop("invoker"),
398  gettext_noop("Security"));
399  appendPQExpBufferStr(&buf, ",\n ");
400  printACLColumn(&buf, "p.proacl");
402  ",\n l.lanname as \"%s\"",
403  gettext_noop("Language"));
404  if (pset.sversion >= 140000)
406  ",\n COALESCE(pg_catalog.pg_get_function_sqlbody(p.oid), p.prosrc) as \"%s\"",
407  gettext_noop("Source code"));
408  else
410  ",\n p.prosrc as \"%s\"",
411  gettext_noop("Source code"));
413  ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
414  gettext_noop("Description"));
415  }
416 
418  "\nFROM pg_catalog.pg_proc p"
419  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
420 
421  for (int i = 0; i < num_arg_patterns; i++)
422  {
424  " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
425  " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
426  i, i, i, i, i, i);
427  }
428 
429  if (verbose)
431  " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
432 
433  have_where = false;
434 
435  /* filter by function type, if requested */
436  if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
437  /* Do nothing */ ;
438  else if (showNormal)
439  {
440  if (!showAggregate)
441  {
442  if (have_where)
443  appendPQExpBufferStr(&buf, " AND ");
444  else
445  {
446  appendPQExpBufferStr(&buf, "WHERE ");
447  have_where = true;
448  }
449  if (pset.sversion >= 110000)
450  appendPQExpBufferStr(&buf, "p.prokind <> 'a'\n");
451  else
452  appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
453  }
454  if (!showProcedure && pset.sversion >= 110000)
455  {
456  if (have_where)
457  appendPQExpBufferStr(&buf, " AND ");
458  else
459  {
460  appendPQExpBufferStr(&buf, "WHERE ");
461  have_where = true;
462  }
463  appendPQExpBufferStr(&buf, "p.prokind <> 'p'\n");
464  }
465  if (!showTrigger)
466  {
467  if (have_where)
468  appendPQExpBufferStr(&buf, " AND ");
469  else
470  {
471  appendPQExpBufferStr(&buf, "WHERE ");
472  have_where = true;
473  }
474  appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
475  }
476  if (!showWindow)
477  {
478  if (have_where)
479  appendPQExpBufferStr(&buf, " AND ");
480  else
481  {
482  appendPQExpBufferStr(&buf, "WHERE ");
483  have_where = true;
484  }
485  if (pset.sversion >= 110000)
486  appendPQExpBufferStr(&buf, "p.prokind <> 'w'\n");
487  else
488  appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
489  }
490  }
491  else
492  {
493  bool needs_or = false;
494 
495  appendPQExpBufferStr(&buf, "WHERE (\n ");
496  have_where = true;
497  /* Note: at least one of these must be true ... */
498  if (showAggregate)
499  {
500  if (pset.sversion >= 110000)
501  appendPQExpBufferStr(&buf, "p.prokind = 'a'\n");
502  else
503  appendPQExpBufferStr(&buf, "p.proisagg\n");
504  needs_or = true;
505  }
506  if (showTrigger)
507  {
508  if (needs_or)
509  appendPQExpBufferStr(&buf, " OR ");
511  "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
512  needs_or = true;
513  }
514  if (showProcedure)
515  {
516  if (needs_or)
517  appendPQExpBufferStr(&buf, " OR ");
518  appendPQExpBufferStr(&buf, "p.prokind = 'p'\n");
519  needs_or = true;
520  }
521  if (showWindow)
522  {
523  if (needs_or)
524  appendPQExpBufferStr(&buf, " OR ");
525  if (pset.sversion >= 110000)
526  appendPQExpBufferStr(&buf, "p.prokind = 'w'\n");
527  else
528  appendPQExpBufferStr(&buf, "p.proiswindow\n");
529  }
530  appendPQExpBufferStr(&buf, " )\n");
531  }
532 
533  if (!validateSQLNamePattern(&buf, func_pattern, have_where, false,
534  "n.nspname", "p.proname", NULL,
535  "pg_catalog.pg_function_is_visible(p.oid)",
536  NULL, 3))
537  return false;
538 
539  for (int i = 0; i < num_arg_patterns; i++)
540  {
541  if (strcmp(arg_patterns[i], "-") != 0)
542  {
543  /*
544  * Match type-name patterns against either internal or external
545  * name, like \dT. Unlike \dT, there seems no reason to
546  * discriminate against arrays or composite types.
547  */
548  char nspname[64];
549  char typname[64];
550  char ft[64];
551  char tiv[64];
552 
553  snprintf(nspname, sizeof(nspname), "nt%d.nspname", i);
554  snprintf(typname, sizeof(typname), "t%d.typname", i);
555  snprintf(ft, sizeof(ft),
556  "pg_catalog.format_type(t%d.oid, NULL)", i);
557  snprintf(tiv, sizeof(tiv),
558  "pg_catalog.pg_type_is_visible(t%d.oid)", i);
560  map_typename_pattern(arg_patterns[i]),
561  true, false,
562  nspname, typname, ft, tiv,
563  NULL, 3))
564  return false;
565  }
566  else
567  {
568  /* "-" pattern specifies no such parameter */
569  appendPQExpBuffer(&buf, " AND t%d.typname IS NULL\n", i);
570  }
571  }
572 
573  if (!showSystem && !func_pattern)
574  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
575  " AND n.nspname <> 'information_schema'\n");
576 
577  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
578 
579  res = PSQLexec(buf.data);
581  if (!res)
582  return false;
583 
584  myopt.nullPrint = NULL;
585  myopt.title = _("List of functions");
586  myopt.translate_header = true;
587  if (pset.sversion >= 90600)
588  {
589  myopt.translate_columns = translate_columns;
590  myopt.n_translate_columns = lengthof(translate_columns);
591  }
592  else
593  {
594  myopt.translate_columns = translate_columns_pre_96;
595  myopt.n_translate_columns = lengthof(translate_columns_pre_96);
596  }
597 
598  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
599 
600  PQclear(res);
601  return true;
602 }
static const char * map_typename_pattern(const char *pattern)
Definition: describe.c:714
int i
Definition: isn.c:73
NameData typname
Definition: pg_type.h:41
#define snprintf
Definition: port.h:225

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

Referenced by exec_command_dfo().

◆ describeOperators()

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

Definition at line 764 of file describe.c.

767 {
769  PGresult *res;
770  printQueryOpt myopt = pset.popt;
771 
773 
774  /*
775  * Note: before Postgres 9.1, we did not assign comments to any built-in
776  * operators, preferring to let the comment on the underlying function
777  * suffice. The coalesce() on the obj_description() calls below supports
778  * this convention by providing a fallback lookup of a comment on the
779  * operator's function. Since 9.1 there is a policy that every built-in
780  * operator should have a comment; so the coalesce() is no longer
781  * necessary so far as built-in operators are concerned. We keep it
782  * anyway, for now, because third-party modules may still be following the
783  * old convention.
784  *
785  * The support for postfix operators in this query is dead code as of
786  * Postgres 14, but we need to keep it for as long as we support talking
787  * to pre-v14 servers.
788  */
789 
791  "SELECT n.nspname as \"%s\",\n"
792  " o.oprname AS \"%s\",\n"
793  " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
794  " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
795  " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
796  gettext_noop("Schema"),
797  gettext_noop("Name"),
798  gettext_noop("Left arg type"),
799  gettext_noop("Right arg type"),
800  gettext_noop("Result type"));
801 
802  if (verbose)
804  " o.oprcode AS \"%s\",\n",
805  gettext_noop("Function"));
806 
808  " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
809  " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
810  "FROM pg_catalog.pg_operator o\n"
811  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
812  gettext_noop("Description"));
813 
814  if (num_arg_patterns >= 2)
815  {
816  num_arg_patterns = 2; /* ignore any additional arguments */
818  " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
819  " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
820  " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
821  " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
822  }
823  else if (num_arg_patterns == 1)
824  {
826  " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
827  " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
828  }
829 
830  if (!showSystem && !oper_pattern)
831  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
832  " AND n.nspname <> 'information_schema'\n");
833 
834  if (!validateSQLNamePattern(&buf, oper_pattern,
835  !showSystem && !oper_pattern, true,
836  "n.nspname", "o.oprname", NULL,
837  "pg_catalog.pg_operator_is_visible(o.oid)",
838  NULL, 3))
839  return false;
840 
841  if (num_arg_patterns == 1)
842  appendPQExpBufferStr(&buf, " AND o.oprleft = 0\n");
843 
844  for (int i = 0; i < num_arg_patterns; i++)
845  {
846  if (strcmp(arg_patterns[i], "-") != 0)
847  {
848  /*
849  * Match type-name patterns against either internal or external
850  * name, like \dT. Unlike \dT, there seems no reason to
851  * discriminate against arrays or composite types.
852  */
853  char nspname[64];
854  char typname[64];
855  char ft[64];
856  char tiv[64];
857 
858  snprintf(nspname, sizeof(nspname), "nt%d.nspname", i);
859  snprintf(typname, sizeof(typname), "t%d.typname", i);
860  snprintf(ft, sizeof(ft),
861  "pg_catalog.format_type(t%d.oid, NULL)", i);
862  snprintf(tiv, sizeof(tiv),
863  "pg_catalog.pg_type_is_visible(t%d.oid)", i);
865  map_typename_pattern(arg_patterns[i]),
866  true, false,
867  nspname, typname, ft, tiv,
868  NULL, 3))
869  return false;
870  }
871  else
872  {
873  /* "-" pattern specifies no such parameter */
874  appendPQExpBuffer(&buf, " AND t%d.typname IS NULL\n", i);
875  }
876  }
877 
878  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
879 
880  res = PSQLexec(buf.data);
882  if (!res)
883  return false;
884 
885  myopt.nullPrint = NULL;
886  myopt.title = _("List of operators");
887  myopt.translate_header = true;
888 
889  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
890 
891  PQclear(res);
892  return true;
893 }

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

Referenced by exec_command_dfo().

◆ describePublications()

bool describePublications ( const char *  pattern)

Definition at line 6168 of file describe.c.

6169 {
6171  int i;
6172  PGresult *res;
6173  bool has_pubtruncate;
6174  bool has_pubviaroot;
6175 
6176  PQExpBufferData title;
6177  printTableContent cont;
6178 
6179  if (pset.sversion < 100000)
6180  {
6181  char sverbuf[32];
6182 
6183  pg_log_error("The server (version %s) does not support publications.",
6185  sverbuf, sizeof(sverbuf)));
6186  return true;
6187  }
6188 
6189  has_pubtruncate = (pset.sversion >= 110000);
6190  has_pubviaroot = (pset.sversion >= 130000);
6191 
6192  initPQExpBuffer(&buf);
6193 
6195  "SELECT oid, pubname,\n"
6196  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6197  " puballtables, pubinsert, pubupdate, pubdelete");
6198  if (has_pubtruncate)
6200  ", pubtruncate");
6201  if (has_pubviaroot)
6203  ", pubviaroot");
6205  "\nFROM pg_catalog.pg_publication\n");
6206 
6207  if (!validateSQLNamePattern(&buf, pattern, false, false,
6208  NULL, "pubname", NULL,
6209  NULL,
6210  NULL, 1))
6211  return false;
6212 
6213  appendPQExpBufferStr(&buf, "ORDER BY 2;");
6214 
6215  res = PSQLexec(buf.data);
6216  if (!res)
6217  {
6218  termPQExpBuffer(&buf);
6219  return false;
6220  }
6221 
6222  if (PQntuples(res) == 0)
6223  {
6224  if (!pset.quiet)
6225  {
6226  if (pattern)
6227  pg_log_error("Did not find any publication named \"%s\".",
6228  pattern);
6229  else
6230  pg_log_error("Did not find any publications.");
6231  }
6232 
6233  termPQExpBuffer(&buf);
6234  PQclear(res);
6235  return false;
6236  }
6237 
6238  for (i = 0; i < PQntuples(res); i++)
6239  {
6240  const char align = 'l';
6241  int ncols = 5;
6242  int nrows = 1;
6243  char *pubid = PQgetvalue(res, i, 0);
6244  char *pubname = PQgetvalue(res, i, 1);
6245  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
6246  printTableOpt myopt = pset.popt.topt;
6247 
6248  if (has_pubtruncate)
6249  ncols++;
6250  if (has_pubviaroot)
6251  ncols++;
6252 
6253  initPQExpBuffer(&title);
6254  printfPQExpBuffer(&title, _("Publication %s"), pubname);
6255  printTableInit(&cont, &myopt, title.data, ncols, nrows);
6256 
6257  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
6258  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
6259  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
6260  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
6261  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
6262  if (has_pubtruncate)
6263  printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
6264  if (has_pubviaroot)
6265  printTableAddHeader(&cont, gettext_noop("Via root"), true, align);
6266 
6267  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
6268  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
6269  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
6270  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
6271  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
6272  if (has_pubtruncate)
6273  printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
6274  if (has_pubviaroot)
6275  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
6276 
6277  if (!puballtables)
6278  {
6279  /* Get the tables for the specified publication */
6281  "SELECT n.nspname, c.relname");
6282  if (pset.sversion >= 150000)
6283  {
6285  ", pg_get_expr(pr.prqual, c.oid)");
6287  ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6288  " pg_catalog.array_to_string("
6289  " ARRAY(SELECT attname\n"
6290  " FROM\n"
6291  " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6292  " pg_catalog.pg_attribute\n"
6293  " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6294  " ELSE NULL END)");
6295  }
6296  else
6298  ", NULL, NULL");
6300  "\nFROM pg_catalog.pg_class c,\n"
6301  " pg_catalog.pg_namespace n,\n"
6302  " pg_catalog.pg_publication_rel pr\n"
6303  "WHERE c.relnamespace = n.oid\n"
6304  " AND c.oid = pr.prrelid\n"
6305  " AND pr.prpubid = '%s'\n"
6306  "ORDER BY 1,2", pubid);
6307  if (!addFooterToPublicationDesc(&buf, _("Tables:"), false, &cont))
6308  goto error_return;
6309 
6310  if (pset.sversion >= 150000)
6311  {
6312  /* Get the schemas for the specified publication */
6314  "SELECT n.nspname\n"
6315  "FROM pg_catalog.pg_namespace n\n"
6316  " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6317  "WHERE pn.pnpubid = '%s'\n"
6318  "ORDER BY 1", pubid);
6319  if (!addFooterToPublicationDesc(&buf, _("Tables from schemas:"),
6320  true, &cont))
6321  goto error_return;
6322  }
6323  }
6324 
6325  printTable(&cont, pset.queryFout, false, pset.logfile);
6326  printTableCleanup(&cont);
6327 
6328  termPQExpBuffer(&title);
6329  }
6330 
6331  termPQExpBuffer(&buf);
6332  PQclear(res);
6333 
6334  return true;
6335 
6336 error_return:
6337  printTableCleanup(&cont);
6338  PQclear(res);
6339  termPQExpBuffer(&buf);
6340  termPQExpBuffer(&title);
6341  return false;
6342 }
static bool addFooterToPublicationDesc(PQExpBuffer buf, const char *footermsg, bool as_schema, printTableContent *const cont)
Definition: describe.c:6122
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3340
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3735
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3127
void printTableCleanup(printTableContent *const content)
Definition: print.c:3295
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3204
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3384
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3164
printTableOpt topt
Definition: print.h:169

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

Referenced by exec_command_d().

◆ describeRoles()

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

Definition at line 3574 of file describe.c.

3575 {
3577  PGresult *res;
3578  printTableContent cont;
3579  printTableOpt myopt = pset.popt.topt;
3580  int ncols = 3;
3581  int nrows = 0;
3582  int i;
3583  int conns;
3584  const char align = 'l';
3585  char **attr;
3586 
3587  myopt.default_footer = false;
3588 
3589  initPQExpBuffer(&buf);
3590 
3592  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3593  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3594  " r.rolconnlimit, r.rolvaliduntil,\n"
3595  " ARRAY(SELECT b.rolname\n"
3596  " FROM pg_catalog.pg_auth_members m\n"
3597  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3598  " WHERE m.member = r.oid) as memberof");
3599 
3600  if (verbose)
3601  {
3602  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3603  ncols++;
3604  }
3605  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3606 
3607  if (pset.sversion >= 90500)
3608  {
3609  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3610  }
3611 
3612  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3613 
3614  if (!showSystem && !pattern)
3615  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3616 
3617  if (!validateSQLNamePattern(&buf, pattern, false, false,
3618  NULL, "r.rolname", NULL, NULL,
3619  NULL, 1))
3620  return false;
3621 
3622  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3623 
3624  res = PSQLexec(buf.data);
3625  if (!res)
3626  return false;
3627 
3628  nrows = PQntuples(res);
3629  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3630 
3631  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3632 
3633  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3634  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3635  /* ignores implicit memberships from superuser & pg_database_owner */
3636  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3637 
3638  if (verbose)
3639  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3640 
3641  for (i = 0; i < nrows; i++)
3642  {
3643  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3644 
3646  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3647  add_role_attribute(&buf, _("Superuser"));
3648 
3649  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3650  add_role_attribute(&buf, _("No inheritance"));
3651 
3652  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3653  add_role_attribute(&buf, _("Create role"));
3654 
3655  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3656  add_role_attribute(&buf, _("Create DB"));
3657 
3658  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3659  add_role_attribute(&buf, _("Cannot login"));
3660 
3661  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3662  add_role_attribute(&buf, _("Replication"));
3663 
3664  if (pset.sversion >= 90500)
3665  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3666  add_role_attribute(&buf, _("Bypass RLS"));
3667 
3668  conns = atoi(PQgetvalue(res, i, 6));
3669  if (conns >= 0)
3670  {
3671  if (buf.len > 0)
3672  appendPQExpBufferChar(&buf, '\n');
3673 
3674  if (conns == 0)
3675  appendPQExpBufferStr(&buf, _("No connections"));
3676  else
3677  appendPQExpBuffer(&buf, ngettext("%d connection",
3678  "%d connections",
3679  conns),
3680  conns);
3681  }
3682 
3683  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3684  {
3685  if (buf.len > 0)
3686  appendPQExpBufferChar(&buf, '\n');
3687  appendPQExpBufferStr(&buf, _("Password valid until "));
3689  }
3690 
3691  attr[i] = pg_strdup(buf.data);
3692 
3693  printTableAddCell(&cont, attr[i], false, false);
3694 
3695  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3696 
3697  if (verbose)
3698  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3699  }
3700  termPQExpBuffer(&buf);
3701 
3702  printTable(&cont, pset.queryFout, false, pset.logfile);
3703  printTableCleanup(&cont);
3704 
3705  for (i = 0; i < nrows; i++)
3706  free(attr[i]);
3707  free(attr);
3708 
3709  PQclear(res);
3710  return true;
3711 }
#define ngettext(s, p, n)
Definition: c.h:1179
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3714
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
static IsoConnInfo * conns
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
bool default_footer
Definition: print.h:113

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

Referenced by exec_command_d().

◆ describeSubscriptions()

bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 6351 of file describe.c.

6352 {
6354  PGresult *res;
6355  printQueryOpt myopt = pset.popt;
6356  static const bool translate_columns[] = {false, false, false, false,
6357  false, false, false, false, false, false, false};
6358 
6359  if (pset.sversion < 100000)
6360  {
6361  char sverbuf[32];
6362 
6363  pg_log_error("The server (version %s) does not support subscriptions.",
6365  sverbuf, sizeof(sverbuf)));
6366  return true;
6367  }
6368 
6369  initPQExpBuffer(&buf);
6370 
6372  "SELECT subname AS \"%s\"\n"
6373  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6374  ", subenabled AS \"%s\"\n"
6375  ", subpublications AS \"%s\"\n",
6376  gettext_noop("Name"),
6377  gettext_noop("Owner"),
6378  gettext_noop("Enabled"),
6379  gettext_noop("Publication"));
6380 
6381  if (verbose)
6382  {
6383  /* Binary mode and streaming are only supported in v14 and higher */
6384  if (pset.sversion >= 140000)
6386  ", subbinary AS \"%s\"\n"
6387  ", substream AS \"%s\"\n",
6388  gettext_noop("Binary"),
6389  gettext_noop("Streaming"));
6390 
6391  /* Two_phase and disable_on_error are only supported in v15 and higher */
6392  if (pset.sversion >= 150000)
6394  ", subtwophasestate AS \"%s\"\n"
6395  ", subdisableonerr AS \"%s\"\n",
6396  gettext_noop("Two-phase commit"),
6397  gettext_noop("Disable on error"));
6398 
6400  ", subsynccommit AS \"%s\"\n"
6401  ", subconninfo AS \"%s\"\n",
6402  gettext_noop("Synchronous commit"),
6403  gettext_noop("Conninfo"));
6404 
6405  /* Skip LSN is only supported in v15 and higher */
6406  if (pset.sversion >= 150000)
6408  ", subskiplsn AS \"%s\"\n",
6409  gettext_noop("Skip LSN"));
6410  }
6411 
6412  /* Only display subscriptions in current database. */
6414  "FROM pg_catalog.pg_subscription\n"
6415  "WHERE subdbid = (SELECT oid\n"
6416  " FROM pg_catalog.pg_database\n"
6417  " WHERE datname = pg_catalog.current_database())");
6418 
6419  if (!validateSQLNamePattern(&buf, pattern, true, false,
6420  NULL, "subname", NULL,
6421  NULL,
6422  NULL, 1))
6423  return false;
6424 
6425  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6426 
6427  res = PSQLexec(buf.data);
6428  termPQExpBuffer(&buf);
6429  if (!res)
6430  return false;
6431 
6432  myopt.nullPrint = NULL;
6433  myopt.title = _("List of subscriptions");
6434  myopt.translate_header = true;
6435  myopt.translate_columns = translate_columns;
6436  myopt.n_translate_columns = lengthof(translate_columns);
6437 
6438  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6439 
6440  PQclear(res);
6441  return true;
6442 }

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

Referenced by exec_command_d().

◆ describeTableDetails()

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

Definition at line 1408 of file describe.c.

1409 {
1411  PGresult *res;
1412  int i;
1413 
1414  initPQExpBuffer(&buf);
1415 
1417  "SELECT c.oid,\n"
1418  " n.nspname,\n"
1419  " c.relname\n"
1420  "FROM pg_catalog.pg_class c\n"
1421  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1422 
1423  if (!showSystem && !pattern)
1424  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1425  " AND n.nspname <> 'information_schema'\n");
1426 
1427  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1428  "n.nspname", "c.relname", NULL,
1429  "pg_catalog.pg_table_is_visible(c.oid)",
1430  NULL, 3))
1431  return false;
1432 
1433  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1434 
1435  res = PSQLexec(buf.data);
1436  termPQExpBuffer(&buf);
1437  if (!res)
1438  return false;
1439 
1440  if (PQntuples(res) == 0)
1441  {
1442  if (!pset.quiet)
1443  {
1444  if (pattern)
1445  pg_log_error("Did not find any relation named \"%s\".",
1446  pattern);
1447  else
1448  pg_log_error("Did not find any relations.");
1449  }
1450  PQclear(res);
1451  return false;
1452  }
1453 
1454  for (i = 0; i < PQntuples(res); i++)
1455  {
1456  const char *oid;
1457  const char *nspname;
1458  const char *relname;
1459 
1460  oid = PQgetvalue(res, i, 0);
1461  nspname = PQgetvalue(res, i, 1);
1462  relname = PQgetvalue(res, i, 2);
1463 
1464  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1465  {
1466  PQclear(res);
1467  return false;
1468  }
1469  if (cancel_pressed)
1470  {
1471  PQclear(res);
1472  return false;
1473  }
1474  }
1475 
1476  PQclear(res);
1477  return true;
1478 }
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1488
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
NameData relname
Definition: pg_class.h:38

References appendPQExpBufferStr(), buf, cancel_pressed, describeOneTableDetails(), i, initPQExpBuffer(), pg_log_error, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), pset, PSQLexec(), _psqlSettings::quiet, relname, res, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ describeTablespaces()

bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 211 of file describe.c.

212 {
214  PGresult *res;
215  printQueryOpt myopt = pset.popt;
216 
218 
220  "SELECT spcname AS \"%s\",\n"
221  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
222  " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
223  gettext_noop("Name"),
224  gettext_noop("Owner"),
225  gettext_noop("Location"));
226 
227  if (verbose)
228  {
229  appendPQExpBufferStr(&buf, ",\n ");
230  printACLColumn(&buf, "spcacl");
232  ",\n spcoptions AS \"%s\""
233  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
234  ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
235  gettext_noop("Options"),
236  gettext_noop("Size"),
237  gettext_noop("Description"));
238  }
239 
241  "\nFROM pg_catalog.pg_tablespace\n");
242 
243  if (!validateSQLNamePattern(&buf, pattern, false, false,
244  NULL, "spcname", NULL,
245  NULL,
246  NULL, 1))
247  return false;
248 
249  appendPQExpBufferStr(&buf, "ORDER BY 1;");
250 
251  res = PSQLexec(buf.data);
253  if (!res)
254  return false;
255 
256  myopt.nullPrint = NULL;
257  myopt.title = _("List of tablespaces");
258  myopt.translate_header = true;
259 
260  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
261 
262  PQclear(res);
263  return true;
264 }

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

Referenced by exec_command_d().

◆ describeTypes()

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

Definition at line 611 of file describe.c.

612 {
614  PGresult *res;
615  printQueryOpt myopt = pset.popt;
616 
618 
620  "SELECT n.nspname as \"%s\",\n"
621  " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
622  gettext_noop("Schema"),
623  gettext_noop("Name"));
624  if (verbose)
625  {
627  " t.typname AS \"%s\",\n"
628  " CASE WHEN t.typrelid != 0\n"
629  " THEN CAST('tuple' AS pg_catalog.text)\n"
630  " WHEN t.typlen < 0\n"
631  " THEN CAST('var' AS pg_catalog.text)\n"
632  " ELSE CAST(t.typlen AS pg_catalog.text)\n"
633  " END AS \"%s\",\n"
634  " pg_catalog.array_to_string(\n"
635  " ARRAY(\n"
636  " SELECT e.enumlabel\n"
637  " FROM pg_catalog.pg_enum e\n"
638  " WHERE e.enumtypid = t.oid\n"
639  " ORDER BY e.enumsortorder\n"
640  " ),\n"
641  " E'\\n'\n"
642  " ) AS \"%s\",\n"
643  " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
644  gettext_noop("Internal name"),
645  gettext_noop("Size"),
646  gettext_noop("Elements"),
647  gettext_noop("Owner"));
648  printACLColumn(&buf, "t.typacl");
649  appendPQExpBufferStr(&buf, ",\n ");
650  }
651 
653  " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
654  gettext_noop("Description"));
655 
656  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
657  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
658 
659  /*
660  * do not include complex types (typrelid!=0) unless they are standalone
661  * composite types
662  */
663  appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
664  appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
665  " FROM pg_catalog.pg_class c "
666  "WHERE c.oid = t.typrelid))\n");
667 
668  /*
669  * do not include array types unless the pattern contains []
670  */
671  if (pattern == NULL || strstr(pattern, "[]") == NULL)
672  appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
673 
674  if (!showSystem && !pattern)
675  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
676  " AND n.nspname <> 'information_schema'\n");
677 
678  /* Match name pattern against either internal or external name */
680  true, false,
681  "n.nspname", "t.typname",
682  "pg_catalog.format_type(t.oid, NULL)",
683  "pg_catalog.pg_type_is_visible(t.oid)",
684  NULL, 3))
685  return false;
686 
687  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
688 
689  res = PSQLexec(buf.data);
691  if (!res)
692  return false;
693 
694  myopt.nullPrint = NULL;
695  myopt.title = _("List of data types");
696  myopt.translate_header = true;
697 
698  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
699 
700  PQclear(res);
701  return true;
702 }
#define CppAsString2(x)
Definition: c.h:289

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, map_typename_pattern(), printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listAllDbs()

bool listAllDbs ( const char *  pattern,
bool  verbose 
)

Definition at line 902 of file describe.c.

903 {
904  PGresult *res;
906  printQueryOpt myopt = pset.popt;
907 
909 
911  "SELECT d.datname as \"%s\",\n"
912  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
913  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n"
914  " d.datcollate as \"%s\",\n"
915  " d.datctype as \"%s\",\n",
916  gettext_noop("Name"),
917  gettext_noop("Owner"),
918  gettext_noop("Encoding"),
919  gettext_noop("Collate"),
920  gettext_noop("Ctype"));
921  if (pset.sversion >= 150000)
923  " d.daticulocale as \"%s\",\n"
924  " CASE d.datlocprovider WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
925  gettext_noop("ICU Locale"),
926  gettext_noop("Locale Provider"));
927  else
929  " NULL as \"%s\",\n"
930  " 'libc' AS \"%s\",\n",
931  gettext_noop("ICU Locale"),
932  gettext_noop("Locale Provider"));
933  appendPQExpBufferStr(&buf, " ");
934  printACLColumn(&buf, "d.datacl");
935  if (verbose)
937  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
938  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
939  " ELSE 'No Access'\n"
940  " END as \"%s\""
941  ",\n t.spcname as \"%s\""
942  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
943  gettext_noop("Size"),
944  gettext_noop("Tablespace"),
945  gettext_noop("Description"));
947  "\nFROM pg_catalog.pg_database d\n");
948  if (verbose)
950  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
951 
952  if (pattern)
953  if (!validateSQLNamePattern(&buf, pattern, false, false,
954  NULL, "d.datname", NULL, NULL,
955  NULL, 1))
956  return false;
957 
958  appendPQExpBufferStr(&buf, "ORDER BY 1;");
959  res = PSQLexec(buf.data);
961  if (!res)
962  return false;
963 
964  myopt.nullPrint = NULL;
965  myopt.title = _("List of databases");
966  myopt.translate_header = true;
967 
968  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
969 
970  PQclear(res);
971  return true;
972 }

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

Referenced by exec_command_list(), and main().

◆ listCasts()

bool listCasts ( const char *  pattern,
bool  verbose 
)

Definition at line 4669 of file describe.c.

4670 {
4672  PGresult *res;
4673  printQueryOpt myopt = pset.popt;
4674  static const bool translate_columns[] = {false, false, false, true, false};
4675 
4676  initPQExpBuffer(&buf);
4677 
4679  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4680  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4681  gettext_noop("Source type"),
4682  gettext_noop("Target type"));
4683 
4684  /*
4685  * We don't attempt to localize '(binary coercible)' or '(with inout)',
4686  * because there's too much risk of gettext translating a function name
4687  * that happens to match some string in the PO database.
4688  */
4690  " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4691  " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4692  " ELSE p.proname\n"
4693  " END AS \"%s\",\n",
4694  COERCION_METHOD_BINARY,
4695  COERCION_METHOD_INOUT,
4696  gettext_noop("Function"));
4697 
4699  " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4700  " WHEN c.castcontext = '%c' THEN '%s'\n"
4701  " ELSE '%s'\n"
4702  " END AS \"%s\"",
4703  COERCION_CODE_EXPLICIT,
4704  gettext_noop("no"),
4705  COERCION_CODE_ASSIGNMENT,
4706  gettext_noop("in assignment"),
4707  gettext_noop("yes"),
4708  gettext_noop("Implicit?"));
4709 
4710  if (verbose)
4712  ",\n d.description AS \"%s\"",
4713  gettext_noop("Description"));
4714 
4715  /*
4716  * We need a left join to pg_proc for binary casts; the others are just
4717  * paranoia.
4718  */
4720  "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4721  " ON c.castfunc = p.oid\n"
4722  " LEFT JOIN pg_catalog.pg_type ts\n"
4723  " ON c.castsource = ts.oid\n"
4724  " LEFT JOIN pg_catalog.pg_namespace ns\n"
4725  " ON ns.oid = ts.typnamespace\n"
4726  " LEFT JOIN pg_catalog.pg_type tt\n"
4727  " ON c.casttarget = tt.oid\n"
4728  " LEFT JOIN pg_catalog.pg_namespace nt\n"
4729  " ON nt.oid = tt.typnamespace\n");
4730 
4731  if (verbose)
4733  " LEFT JOIN pg_catalog.pg_description d\n"
4734  " ON d.classoid = c.tableoid AND d.objoid = "
4735  "c.oid AND d.objsubid = 0\n");
4736 
4737  appendPQExpBufferStr(&buf, "WHERE ( (true");
4738 
4739  /*
4740  * Match name pattern against either internal or external name of either
4741  * castsource or casttarget
4742  */
4743  if (!validateSQLNamePattern(&buf, pattern, true, false,
4744  "ns.nspname", "ts.typname",
4745  "pg_catalog.format_type(ts.oid, NULL)",
4746  "pg_catalog.pg_type_is_visible(ts.oid)",
4747  NULL, 3))
4748  return false;
4749 
4750  appendPQExpBufferStr(&buf, ") OR (true");
4751 
4752  if (!validateSQLNamePattern(&buf, pattern, true, false,
4753  "nt.nspname", "tt.typname",
4754  "pg_catalog.format_type(tt.oid, NULL)",
4755  "pg_catalog.pg_type_is_visible(tt.oid)",
4756  NULL, 3))
4757  return false;
4758 
4759  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
4760 
4761  res = PSQLexec(buf.data);
4762  termPQExpBuffer(&buf);
4763  if (!res)
4764  return false;
4765 
4766  myopt.nullPrint = NULL;
4767  myopt.title = _("List of casts");
4768  myopt.translate_header = true;
4769  myopt.translate_columns = translate_columns;
4770  myopt.n_translate_columns = lengthof(translate_columns);
4771 
4772  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4773 
4774  PQclear(res);
4775  return true;
4776 }

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

Referenced by exec_command_d().

◆ listCollations()

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

Definition at line 4784 of file describe.c.

4785 {
4787  PGresult *res;
4788  printQueryOpt myopt = pset.popt;
4789  static const bool translate_columns[] = {false, false, false, false, false, false, true, false};
4790 
4791  initPQExpBuffer(&buf);
4792 
4794  "SELECT n.nspname AS \"%s\",\n"
4795  " c.collname AS \"%s\",\n"
4796  " c.collcollate AS \"%s\",\n"
4797  " c.collctype AS \"%s\"",
4798  gettext_noop("Schema"),
4799  gettext_noop("Name"),
4800  gettext_noop("Collate"),
4801  gettext_noop("Ctype"));
4802 
4803  if (pset.sversion >= 150000)
4805  ",\n c.colliculocale AS \"%s\"",
4806  gettext_noop("ICU Locale"));
4807  else
4809  ",\n c.collcollate AS \"%s\"",
4810  gettext_noop("ICU Locale"));
4811 
4812  if (pset.sversion >= 100000)
4814  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
4815  gettext_noop("Provider"));
4816  else
4818  ",\n 'libc' AS \"%s\"",
4819  gettext_noop("Provider"));
4820 
4821  if (pset.sversion >= 120000)
4823  ",\n CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4824  gettext_noop("yes"), gettext_noop("no"),
4825  gettext_noop("Deterministic?"));
4826  else
4828  ",\n '%s' AS \"%s\"",
4829  gettext_noop("yes"),
4830  gettext_noop("Deterministic?"));
4831 
4832  if (verbose)
4834  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4835  gettext_noop("Description"));
4836 
4838  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4839  "WHERE n.oid = c.collnamespace\n");
4840 
4841  if (!showSystem && !pattern)
4842  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4843  " AND n.nspname <> 'information_schema'\n");
4844 
4845  /*
4846  * Hide collations that aren't usable in the current database's encoding.
4847  * If you think to change this, note that pg_collation_is_visible rejects
4848  * unusable collations, so you will need to hack name pattern processing
4849  * somehow to avoid inconsistent behavior.
4850  */
4851  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4852 
4853  if (!validateSQLNamePattern(&buf, pattern, true, false,
4854  "n.nspname", "c.collname", NULL,
4855  "pg_catalog.pg_collation_is_visible(c.oid)",
4856  NULL, 3))
4857  return false;
4858 
4859  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4860 
4861  res = PSQLexec(buf.data);
4862  termPQExpBuffer(&buf);
4863  if (!res)
4864  return false;
4865 
4866  myopt.nullPrint = NULL;
4867  myopt.title = _("List of collations");
4868  myopt.translate_header = true;
4869  myopt.translate_columns = translate_columns;
4870  myopt.n_translate_columns = lengthof(translate_columns);
4871 
4872  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4873 
4874  PQclear(res);
4875  return true;
4876 }

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

Referenced by exec_command_d().

◆ listConversions()

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

Definition at line 4350 of file describe.c.

4351 {
4353  PGresult *res;
4354  printQueryOpt myopt = pset.popt;
4355  static const bool translate_columns[] =
4356  {false, false, false, false, true, false};
4357 
4358  initPQExpBuffer(&buf);
4359 
4361  "SELECT n.nspname AS \"%s\",\n"
4362  " c.conname AS \"%s\",\n"
4363  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4364  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4365  " CASE WHEN c.condefault THEN '%s'\n"
4366  " ELSE '%s' END AS \"%s\"",
4367  gettext_noop("Schema"),
4368  gettext_noop("Name"),
4369  gettext_noop("Source"),
4370  gettext_noop("Destination"),
4371  gettext_noop("yes"), gettext_noop("no"),
4372  gettext_noop("Default?"));
4373 
4374  if (verbose)
4376  ",\n d.description AS \"%s\"",
4377  gettext_noop("Description"));
4378 
4380  "\nFROM pg_catalog.pg_conversion c\n"
4381  " JOIN pg_catalog.pg_namespace n "
4382  "ON n.oid = c.connamespace\n");
4383 
4384  if (verbose)
4386  "LEFT JOIN pg_catalog.pg_description d "
4387  "ON d.classoid = c.tableoid\n"
4388  " AND d.objoid = c.oid "
4389  "AND d.objsubid = 0\n");
4390 
4391  appendPQExpBufferStr(&buf, "WHERE true\n");
4392 
4393  if (!showSystem && !pattern)
4394  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4395  " AND n.nspname <> 'information_schema'\n");
4396 
4397  if (!validateSQLNamePattern(&buf, pattern, true, false,
4398  "n.nspname", "c.conname", NULL,
4399  "pg_catalog.pg_conversion_is_visible(c.oid)",
4400  NULL, 3))
4401  return false;
4402 
4403  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4404 
4405  res = PSQLexec(buf.data);
4406  termPQExpBuffer(&buf);
4407  if (!res)
4408  return false;
4409 
4410  myopt.nullPrint = NULL;
4411  myopt.title = _("List of conversions");
4412  myopt.translate_header = true;
4413  myopt.translate_columns = translate_columns;
4414  myopt.n_translate_columns = lengthof(translate_columns);
4415 
4416  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4417 
4418  PQclear(res);
4419  return true;
4420 }

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

Referenced by exec_command_d().

◆ listDbRoleSettings()

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

Definition at line 3726 of file describe.c.

3727 {
3729  PGresult *res;
3730  printQueryOpt myopt = pset.popt;
3731  bool havewhere;
3732 
3733  initPQExpBuffer(&buf);
3734 
3735  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3736  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3737  "FROM pg_catalog.pg_db_role_setting s\n"
3738  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3739  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3740  gettext_noop("Role"),
3741  gettext_noop("Database"),
3742  gettext_noop("Settings"));
3743  if (!validateSQLNamePattern(&buf, pattern, false, false,
3744  NULL, "r.rolname", NULL, NULL, &havewhere, 1))
3745  return false;
3746  if (!validateSQLNamePattern(&buf, pattern2, havewhere, false,
3747  NULL, "d.datname", NULL, NULL,
3748  NULL, 1))
3749  return false;
3750  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3751 
3752  res = PSQLexec(buf.data);
3753  termPQExpBuffer(&buf);
3754  if (!res)
3755  return false;
3756 
3757  /*
3758  * Most functions in this file are content to print an empty table when
3759  * there are no matching objects. We intentionally deviate from that
3760  * here, but only in !quiet mode, because of the possibility that the user
3761  * is confused about what the two pattern arguments mean.
3762  */
3763  if (PQntuples(res) == 0 && !pset.quiet)
3764  {
3765  if (pattern && pattern2)
3766  pg_log_error("Did not find any settings for role \"%s\" and database \"%s\".",
3767  pattern, pattern2);
3768  else if (pattern)
3769  pg_log_error("Did not find any settings for role \"%s\".",
3770  pattern);
3771  else
3772  pg_log_error("Did not find any settings.");
3773  }
3774  else
3775  {
3776  myopt.nullPrint = NULL;
3777  myopt.title = _("List of settings");
3778  myopt.translate_header = true;
3779 
3780  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3781  }
3782 
3783  PQclear(res);
3784  return true;
3785 }

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_log_error, _psqlSettings::popt, PQclear(), PQntuples(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::quiet, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1141 of file describe.c.

1142 {
1144  PGresult *res;
1145  printQueryOpt myopt = pset.popt;
1146  static const bool translate_columns[] = {false, false, true, false};
1147 
1148  initPQExpBuffer(&buf);
1149 
1151  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1152  " n.nspname AS \"%s\",\n"
1153  " 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"
1154  " ",
1155  gettext_noop("Owner"),
1156  gettext_noop("Schema"),
1157  DEFACLOBJ_RELATION,
1158  gettext_noop("table"),
1159  DEFACLOBJ_SEQUENCE,
1160  gettext_noop("sequence"),
1161  DEFACLOBJ_FUNCTION,
1162  gettext_noop("function"),
1163  DEFACLOBJ_TYPE,
1164  gettext_noop("type"),
1165  DEFACLOBJ_NAMESPACE,
1166  gettext_noop("schema"),
1167  gettext_noop("Type"));
1168 
1169  printACLColumn(&buf, "d.defaclacl");
1170 
1171  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1172  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1173 
1174  if (!validateSQLNamePattern(&buf, pattern, false, false,
1175  NULL,
1176  "n.nspname",
1177  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1178  NULL,
1179  NULL, 3))
1180  return false;
1181 
1182  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1183 
1184  res = PSQLexec(buf.data);
1185  if (!res)
1186  {
1187  termPQExpBuffer(&buf);
1188  return false;
1189  }
1190 
1191  myopt.nullPrint = NULL;
1192  printfPQExpBuffer(&buf, _("Default access privileges"));
1193  myopt.title = buf.data;
1194  myopt.translate_header = true;
1195  myopt.translate_columns = translate_columns;
1196  myopt.n_translate_columns = lengthof(translate_columns);
1197 
1198  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1199 
1200  termPQExpBuffer(&buf);
1201  PQclear(res);
1202  return true;
1203 }

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listDomains()

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

Definition at line 4269 of file describe.c.

4270 {
4272  PGresult *res;
4273  printQueryOpt myopt = pset.popt;
4274 
4275  initPQExpBuffer(&buf);
4276 
4278  "SELECT n.nspname as \"%s\",\n"
4279  " t.typname as \"%s\",\n"
4280  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4281  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4282  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4283  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4284  " t.typdefault as \"%s\",\n"
4285  " pg_catalog.array_to_string(ARRAY(\n"
4286  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4287  " ), ' ') as \"%s\"",
4288  gettext_noop("Schema"),
4289  gettext_noop("Name"),
4290  gettext_noop("Type"),
4291  gettext_noop("Collation"),
4292  gettext_noop("Nullable"),
4293  gettext_noop("Default"),
4294  gettext_noop("Check"));
4295 
4296  if (verbose)
4297  {
4298  appendPQExpBufferStr(&buf, ",\n ");
4299  printACLColumn(&buf, "t.typacl");
4301  ",\n d.description as \"%s\"",
4302  gettext_noop("Description"));
4303  }
4304 
4306  "\nFROM pg_catalog.pg_type t\n"
4307  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4308 
4309  if (verbose)
4311  " LEFT JOIN pg_catalog.pg_description d "
4312  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4313  "AND d.objsubid = 0\n");
4314 
4315  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
4316 
4317  if (!showSystem && !pattern)
4318  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4319  " AND n.nspname <> 'information_schema'\n");
4320 
4321  if (!validateSQLNamePattern(&buf, pattern, true, false,
4322  "n.nspname", "t.typname", NULL,
4323  "pg_catalog.pg_type_is_visible(t.oid)",
4324  NULL, 3))
4325  return false;
4326 
4327  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4328 
4329  res = PSQLexec(buf.data);
4330  termPQExpBuffer(&buf);
4331  if (!res)
4332  return false;
4333 
4334  myopt.nullPrint = NULL;
4335  myopt.title = _("List of domains");
4336  myopt.translate_header = true;
4337 
4338  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4339 
4340  PQclear(res);
4341  return true;
4342 }

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

Referenced by exec_command_d().

◆ listEventTriggers()

bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 4497 of file describe.c.

4498 {
4500  PGresult *res;
4501  printQueryOpt myopt = pset.popt;
4502  static const bool translate_columns[] =
4503  {false, false, false, true, false, false, false};
4504 
4505  if (pset.sversion < 90300)
4506  {
4507  char sverbuf[32];
4508 
4509  pg_log_error("The server (version %s) does not support event triggers.",
4511  sverbuf, sizeof(sverbuf)));
4512  return true;
4513  }
4514 
4515  initPQExpBuffer(&buf);
4516 
4518  "SELECT evtname as \"%s\", "
4519  "evtevent as \"%s\", "
4520  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4521  " case evtenabled when 'O' then '%s'"
4522  " when 'R' then '%s'"
4523  " when 'A' then '%s'"
4524  " when 'D' then '%s' end as \"%s\",\n"
4525  " e.evtfoid::pg_catalog.regproc as \"%s\", "
4526  "pg_catalog.array_to_string(array(select x"
4527  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4528  gettext_noop("Name"),
4529  gettext_noop("Event"),
4530  gettext_noop("Owner"),
4531  gettext_noop("enabled"),
4532  gettext_noop("replica"),
4533  gettext_noop("always"),
4534  gettext_noop("disabled"),
4535  gettext_noop("Enabled"),
4536  gettext_noop("Function"),
4537  gettext_noop("Tags"));
4538  if (verbose)
4540  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4541  gettext_noop("Description"));
4543  "\nFROM pg_catalog.pg_event_trigger e ");
4544 
4545  if (!validateSQLNamePattern(&buf, pattern, false, false,
4546  NULL, "evtname", NULL, NULL,
4547  NULL, 1))
4548  return false;
4549 
4550  appendPQExpBufferStr(&buf, "ORDER BY 1");
4551 
4552  res = PSQLexec(buf.data);
4553  termPQExpBuffer(&buf);
4554  if (!res)
4555  return false;
4556 
4557  myopt.nullPrint = NULL;
4558  myopt.title = _("List of event triggers");
4559  myopt.translate_header = true;
4560  myopt.translate_columns = translate_columns;
4561  myopt.n_translate_columns = lengthof(translate_columns);
4562 
4563  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4564 
4565  PQclear(res);
4566  return true;
4567 }

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

Referenced by exec_command_d().

◆ listExtendedStats()

bool listExtendedStats ( const char *  pattern)

Definition at line 4575 of file describe.c.

4576 {
4578  PGresult *res;
4579  printQueryOpt myopt = pset.popt;
4580 
4581  if (pset.sversion < 100000)
4582  {
4583  char sverbuf[32];
4584 
4585  pg_log_error("The server (version %s) does not support extended statistics.",
4587  sverbuf, sizeof(sverbuf)));
4588  return true;
4589  }
4590 
4591  initPQExpBuffer(&buf);
4593  "SELECT \n"
4594  "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4595  "es.stxname AS \"%s\", \n",
4596  gettext_noop("Schema"),
4597  gettext_noop("Name"));
4598 
4599  if (pset.sversion >= 140000)
4601  "pg_catalog.format('%%s FROM %%s', \n"
4602  " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4603  " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4604  gettext_noop("Definition"));
4605  else
4607  "pg_catalog.format('%%s FROM %%s', \n"
4608  " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4609  " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4610  " JOIN pg_catalog.pg_attribute a \n"
4611  " ON (es.stxrelid = a.attrelid \n"
4612  " AND a.attnum = s.attnum \n"
4613  " AND NOT a.attisdropped)), \n"
4614  "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4615  gettext_noop("Definition"));
4616 
4618  ",\nCASE WHEN 'd' = any(es.stxkind) THEN 'defined' \n"
4619  "END AS \"%s\", \n"
4620  "CASE WHEN 'f' = any(es.stxkind) THEN 'defined' \n"
4621  "END AS \"%s\"",
4622  gettext_noop("Ndistinct"),
4623  gettext_noop("Dependencies"));
4624 
4625  /*
4626  * Include the MCV statistics kind.
4627  */
4628  if (pset.sversion >= 120000)
4629  {
4631  ",\nCASE WHEN 'm' = any(es.stxkind) THEN 'defined' \n"
4632  "END AS \"%s\" ",
4633  gettext_noop("MCV"));
4634  }
4635 
4637  " \nFROM pg_catalog.pg_statistic_ext es \n");
4638 
4639  if (!validateSQLNamePattern(&buf, pattern,
4640  false, false,
4641  "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text", "es.stxname",
4642  NULL, "pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4643  NULL, 3))
4644  return false;
4645 
4646  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4647 
4648  res = PSQLexec(buf.data);
4649  termPQExpBuffer(&buf);
4650  if (!res)
4651  return false;
4652 
4653  myopt.nullPrint = NULL;
4654  myopt.title = _("List of extended statistics");
4655  myopt.translate_header = true;
4656 
4657  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4658 
4659  PQclear(res);
4660  return true;
4661 }

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

Referenced by exec_command_d().

◆ listExtensionContents()

bool listExtensionContents ( const char *  pattern)

Definition at line 5890 of file describe.c.

5891 {
5893  PGresult *res;
5894  int i;
5895 
5896  initPQExpBuffer(&buf);
5898  "SELECT e.extname, e.oid\n"
5899  "FROM pg_catalog.pg_extension e\n");
5900 
5901  if (!validateSQLNamePattern(&buf, pattern,
5902  false, false,
5903  NULL, "e.extname", NULL,
5904  NULL,
5905  NULL, 1))
5906  return false;
5907 
5908  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5909 
5910  res = PSQLexec(buf.data);
5911  termPQExpBuffer(&buf);
5912  if (!res)
5913  return false;
5914 
5915  if (PQntuples(res) == 0)
5916  {
5917  if (!pset.quiet)
5918  {
5919  if (pattern)
5920  pg_log_error("Did not find any extension named \"%s\".",
5921  pattern);
5922  else
5923  pg_log_error("Did not find any extensions.");
5924  }
5925  PQclear(res);
5926  return false;
5927  }
5928 
5929  for (i = 0; i < PQntuples(res); i++)
5930  {
5931  const char *extname;
5932  const char *oid;
5933 
5934  extname = PQgetvalue(res, i, 0);
5935  oid = PQgetvalue(res, i, 1);
5936 
5937  if (!listOneExtensionContents(extname, oid))
5938  {
5939  PQclear(res);
5940  return false;
5941  }
5942  if (cancel_pressed)
5943  {
5944  PQclear(res);
5945  return false;
5946  }
5947  }
5948 
5949  PQclear(res);
5950  return true;
5951 }
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5954

References appendPQExpBufferStr(), buf, cancel_pressed, i, initPQExpBuffer(), listOneExtensionContents(), pg_log_error, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), pset, PSQLexec(), _psqlSettings::quiet, res, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listExtensions()

bool listExtensions ( const char *  pattern)

Definition at line 5841 of file describe.c.

5842 {
5844  PGresult *res;
5845  printQueryOpt myopt = pset.popt;
5846 
5847  initPQExpBuffer(&buf);
5849  "SELECT e.extname AS \"%s\", "
5850  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
5851  "FROM pg_catalog.pg_extension e "
5852  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
5853  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
5854  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
5855  gettext_noop("Name"),
5856  gettext_noop("Version"),
5857  gettext_noop("Schema"),
5858  gettext_noop("Description"));
5859 
5860  if (!validateSQLNamePattern(&buf, pattern,
5861  false, false,
5862  NULL, "e.extname", NULL,
5863  NULL,
5864  NULL, 1))
5865  return false;
5866 
5867  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5868 
5869  res = PSQLexec(buf.data);
5870  termPQExpBuffer(&buf);
5871  if (!res)
5872  return false;
5873 
5874  myopt.nullPrint = NULL;
5875  myopt.title = _("List of installed extensions");
5876  myopt.translate_header = true;
5877 
5878  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5879 
5880  PQclear(res);
5881  return true;
5882 }

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 5575 of file describe.c.

5576 {
5578  PGresult *res;
5579  printQueryOpt myopt = pset.popt;
5580 
5581  initPQExpBuffer(&buf);
5583  "SELECT fdw.fdwname AS \"%s\",\n"
5584  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5585  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5586  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5587  gettext_noop("Name"),
5588  gettext_noop("Owner"),
5589  gettext_noop("Handler"),
5590  gettext_noop("Validator"));
5591 
5592  if (verbose)
5593  {
5594  appendPQExpBufferStr(&buf, ",\n ");
5595  printACLColumn(&buf, "fdwacl");
5597  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5598  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5599  " pg_catalog.quote_ident(option_name) || ' ' || "
5600  " pg_catalog.quote_literal(option_value) FROM "
5601  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5602  " END AS \"%s\""
5603  ",\n d.description AS \"%s\" ",
5604  gettext_noop("FDW options"),
5605  gettext_noop("Description"));
5606  }
5607 
5608  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
5609 
5610  if (verbose)
5612  "LEFT JOIN pg_catalog.pg_description d\n"
5613  " ON d.classoid = fdw.tableoid "
5614  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5615 
5616  if (!validateSQLNamePattern(&buf, pattern, false, false,
5617  NULL, "fdwname", NULL, NULL,
5618  NULL, 1))
5619  return false;
5620 
5621  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5622 
5623  res = PSQLexec(buf.data);
5624  termPQExpBuffer(&buf);
5625  if (!res)
5626  return false;
5627 
5628  myopt.nullPrint = NULL;
5629  myopt.title = _("List of foreign-data wrappers");
5630  myopt.translate_header = true;
5631 
5632  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5633 
5634  PQclear(res);
5635  return true;
5636 }

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

Referenced by exec_command_d().

◆ listForeignServers()

bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 5644 of file describe.c.

5645 {
5647  PGresult *res;
5648  printQueryOpt myopt = pset.popt;
5649 
5650  initPQExpBuffer(&buf);
5652  "SELECT s.srvname AS \"%s\",\n"
5653  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5654  " f.fdwname AS \"%s\"",
5655  gettext_noop("Name"),
5656  gettext_noop("Owner"),
5657  gettext_noop("Foreign-data wrapper"));
5658 
5659  if (verbose)
5660  {
5661  appendPQExpBufferStr(&buf, ",\n ");
5662  printACLColumn(&buf, "s.srvacl");
5664  ",\n"
5665  " s.srvtype AS \"%s\",\n"
5666  " s.srvversion AS \"%s\",\n"
5667  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5668  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5669  " pg_catalog.quote_ident(option_name) || ' ' || "
5670  " pg_catalog.quote_literal(option_value) FROM "
5671  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
5672  " END AS \"%s\",\n"
5673  " d.description AS \"%s\"",
5674  gettext_noop("Type"),
5675  gettext_noop("Version"),
5676  gettext_noop("FDW options"),
5677  gettext_noop("Description"));
5678  }
5679 
5681  "\nFROM pg_catalog.pg_foreign_server s\n"
5682  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
5683 
5684  if (verbose)
5686  "LEFT JOIN pg_catalog.pg_description d\n "
5687  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
5688  "AND d.objsubid = 0\n");
5689 
5690  if (!validateSQLNamePattern(&buf, pattern, false, false,
5691  NULL, "s.srvname", NULL, NULL,
5692  NULL, 1))
5693  return false;
5694 
5695  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5696 
5697  res = PSQLexec(buf.data);
5698  termPQExpBuffer(&buf);
5699  if (!res)
5700  return false;
5701 
5702  myopt.nullPrint = NULL;
5703  myopt.title = _("List of foreign servers");
5704  myopt.translate_header = true;
5705 
5706  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5707 
5708  PQclear(res);
5709  return true;
5710 }

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

Referenced by exec_command_d().

◆ listForeignTables()

bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 5771 of file describe.c.

5772 {
5774  PGresult *res;
5775  printQueryOpt myopt = pset.popt;
5776 
5777  initPQExpBuffer(&buf);
5779  "SELECT n.nspname AS \"%s\",\n"
5780  " c.relname AS \"%s\",\n"
5781  " s.srvname AS \"%s\"",
5782  gettext_noop("Schema"),
5783  gettext_noop("Table"),
5784  gettext_noop("Server"));
5785 
5786  if (verbose)
5788  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
5789  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5790  " pg_catalog.quote_ident(option_name) || ' ' || "
5791  " pg_catalog.quote_literal(option_value) FROM "
5792  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
5793  " END AS \"%s\",\n"
5794  " d.description AS \"%s\"",
5795  gettext_noop("FDW options"),
5796  gettext_noop("Description"));
5797 
5799  "\nFROM pg_catalog.pg_foreign_table ft\n"
5800  " INNER JOIN pg_catalog.pg_class c"
5801  " ON c.oid = ft.ftrelid\n"
5802  " INNER JOIN pg_catalog.pg_namespace n"
5803  " ON n.oid = c.relnamespace\n"
5804  " INNER JOIN pg_catalog.pg_foreign_server s"
5805  " ON s.oid = ft.ftserver\n");
5806  if (verbose)
5808  " LEFT JOIN pg_catalog.pg_description d\n"
5809  " ON d.classoid = c.tableoid AND "
5810  "d.objoid = c.oid AND d.objsubid = 0\n");
5811 
5812  if (!validateSQLNamePattern(&buf, pattern, false, false,
5813  "n.nspname", "c.relname", NULL,
5814  "pg_catalog.pg_table_is_visible(c.oid)",
5815  NULL, 3))
5816  return false;
5817 
5818  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5819 
5820  res = PSQLexec(buf.data);
5821  termPQExpBuffer(&buf);
5822  if (!res)
5823  return false;
5824 
5825  myopt.nullPrint = NULL;
5826  myopt.title = _("List of foreign tables");
5827  myopt.translate_header = true;
5828 
5829  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5830 
5831  PQclear(res);
5832  return true;
5833 }

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listLanguages()

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

Definition at line 4197 of file describe.c.

4198 {
4200  PGresult *res;
4201  printQueryOpt myopt = pset.popt;
4202 
4203  initPQExpBuffer(&buf);
4204 
4206  "SELECT l.lanname AS \"%s\",\n"
4207  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4208  " l.lanpltrusted AS \"%s\"",
4209  gettext_noop("Name"),
4210  gettext_noop("Owner"),
4211  gettext_noop("Trusted"));
4212 
4213  if (verbose)
4214  {
4216  ",\n NOT l.lanispl AS \"%s\",\n"
4217  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4218  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4219  "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4220  gettext_noop("Internal language"),
4221  gettext_noop("Call handler"),
4222  gettext_noop("Validator"),
4223  gettext_noop("Inline handler"));
4224  printACLColumn(&buf, "l.lanacl");
4225  }
4226 
4228  ",\n d.description AS \"%s\""
4229  "\nFROM pg_catalog.pg_language l\n"
4230  "LEFT JOIN pg_catalog.pg_description d\n"
4231  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4232  " AND d.objsubid = 0\n",
4233  gettext_noop("Description"));
4234 
4235  if (pattern)
4236  if (!validateSQLNamePattern(&buf, pattern, false, false,
4237  NULL, "l.lanname", NULL, NULL,
4238  NULL, 2))
4239  return false;
4240 
4241  if (!showSystem && !pattern)
4242  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
4243 
4244 
4245  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4246 
4247  res = PSQLexec(buf.data);
4248  termPQExpBuffer(&buf);
4249  if (!res)
4250  return false;
4251 
4252  myopt.nullPrint = NULL;
4253  myopt.title = _("List of languages");
4254  myopt.translate_header = true;
4255 
4256  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4257 
4258  PQclear(res);
4259  return true;
4260 }

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

Referenced by exec_command_d().

◆ listLargeObjects()

bool listLargeObjects ( bool  verbose)

Definition at line 6823 of file describe.c.

6824 {
6826  PGresult *res;
6827  printQueryOpt myopt = pset.popt;
6828 
6829  initPQExpBuffer(&buf);
6830 
6832  "SELECT oid as \"%s\",\n"
6833  " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
6834  gettext_noop("ID"),
6835  gettext_noop("Owner"));
6836 
6837  if (verbose)
6838  {
6839  printACLColumn(&buf, "lomacl");
6840  appendPQExpBufferStr(&buf, ",\n ");
6841  }
6842 
6844  "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
6845  "FROM pg_catalog.pg_largeobject_metadata\n"
6846  "ORDER BY oid",
6847  gettext_noop("Description"));
6848 
6849  res = PSQLexec(buf.data);
6850  termPQExpBuffer(&buf);
6851  if (!res)
6852  return false;
6853 
6854  myopt.nullPrint = NULL;
6855  myopt.title = _("Large objects");
6856  myopt.translate_header = true;
6857 
6858  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6859 
6860  PQclear(res);
6861  return true;
6862 }

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

Referenced by exec_command_d(), and exec_command_lo().

◆ listOperatorClasses()

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

Definition at line 6466 of file describe.c.

6468 {
6470  PGresult *res;
6471  printQueryOpt myopt = pset.popt;
6472  bool have_where = false;
6473  static const bool translate_columns[] = {false, false, false, false, false, false, false};
6474 
6475  initPQExpBuffer(&buf);
6476 
6478  "SELECT\n"
6479  " am.amname AS \"%s\",\n"
6480  " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6481  " CASE\n"
6482  " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6483  " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6484  " ELSE NULL\n"
6485  " END AS \"%s\",\n"
6486  " CASE\n"
6487  " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6488  " THEN pg_catalog.format('%%I', c.opcname)\n"
6489  " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6490  " END AS \"%s\",\n"
6491  " (CASE WHEN c.opcdefault\n"
6492  " THEN '%s'\n"
6493  " ELSE '%s'\n"
6494  " END) AS \"%s\"",
6495  gettext_noop("AM"),
6496  gettext_noop("Input type"),
6497  gettext_noop("Storage type"),
6498  gettext_noop("Operator class"),
6499  gettext_noop("yes"),
6500  gettext_noop("no"),
6501  gettext_noop("Default?"));
6502  if (verbose)
6504  ",\n CASE\n"
6505  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6506  " THEN pg_catalog.format('%%I', of.opfname)\n"
6507  " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
6508  " END AS \"%s\",\n"
6509  " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6510  gettext_noop("Operator family"),
6511  gettext_noop("Owner"));
6513  "\nFROM pg_catalog.pg_opclass c\n"
6514  " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6515  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6516  " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6517  " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
6518  if (verbose)
6520  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6521  " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6522 
6523  if (access_method_pattern)
6524  if (!validateSQLNamePattern(&buf, access_method_pattern,
6525  false, false, NULL, "am.amname", NULL, NULL,
6526  &have_where, 1))
6527  return false;
6528  if (type_pattern)
6529  {
6530  /* Match type name pattern against either internal or external name */
6531  if (!validateSQLNamePattern(&buf, type_pattern, have_where, false,
6532  "tn.nspname", "t.typname",
6533  "pg_catalog.format_type(t.oid, NULL)",
6534  "pg_catalog.pg_type_is_visible(t.oid)",
6535  NULL, 3))
6536  return false;
6537  }
6538 
6539  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
6540  res = PSQLexec(buf.data);
6541  termPQExpBuffer(&buf);
6542  if (!res)
6543  return false;
6544 
6545  myopt.nullPrint = NULL;
6546  myopt.title = _("List of operator classes");
6547  myopt.translate_header = true;
6548  myopt.translate_columns = translate_columns;
6549  myopt.n_translate_columns = lengthof(translate_columns);
6550 
6551  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6552 
6553  PQclear(res);
6554  return true;
6555 }

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

Referenced by exec_command_d().

◆ listOperatorFamilies()

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

Definition at line 6564 of file describe.c.

6566 {
6568  PGresult *res;
6569  printQueryOpt myopt = pset.popt;
6570  bool have_where = false;
6571  static const bool translate_columns[] = {false, false, false, false};
6572 
6573  initPQExpBuffer(&buf);
6574 
6576  "SELECT\n"
6577  " am.amname AS \"%s\",\n"
6578  " CASE\n"
6579  " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
6580  " THEN pg_catalog.format('%%I', f.opfname)\n"
6581  " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
6582  " END AS \"%s\",\n"
6583  " (SELECT\n"
6584  " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
6585  " FROM pg_catalog.pg_opclass oc\n"
6586  " WHERE oc.opcfamily = f.oid) \"%s\"",
6587  gettext_noop("AM"),
6588  gettext_noop("Operator family"),
6589  gettext_noop("Applicable types"));
6590  if (verbose)
6592  ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
6593  gettext_noop("Owner"));
6595  "\nFROM pg_catalog.pg_opfamily f\n"
6596  " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
6597  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
6598 
6599  if (access_method_pattern)
6600  if (!validateSQLNamePattern(&buf, access_method_pattern,
6601  false, false, NULL, "am.amname", NULL, NULL,
6602  &have_where, 1))
6603  return false;
6604  if (type_pattern)
6605  {
6607  " %s EXISTS (\n"
6608  " SELECT 1\n"
6609  " FROM pg_catalog.pg_type t\n"
6610  " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
6611  " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
6612  " WHERE oc.opcfamily = f.oid\n",
6613  have_where ? "AND" : "WHERE");
6614  /* Match type name pattern against either internal or external name */
6615  if (!validateSQLNamePattern(&buf, type_pattern, true, false,
6616  "tn.nspname", "t.typname",
6617  "pg_catalog.format_type(t.oid, NULL)",
6618  "pg_catalog.pg_type_is_visible(t.oid)",
6619  NULL, 3))
6620  return false;
6621  appendPQExpBufferStr(&buf, " )\n");
6622  }
6623 
6624  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6625  res = PSQLexec(buf.data);
6626  termPQExpBuffer(&buf);
6627  if (!res)
6628  return false;
6629 
6630  myopt.nullPrint = NULL;
6631  myopt.title = _("List of operator families");
6632  myopt.translate_header = true;
6633  myopt.translate_columns = translate_columns;
6634  myopt.n_translate_columns = lengthof(translate_columns);
6635 
6636  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6637 
6638  PQclear(res);
6639  return true;
6640 }

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

Referenced by exec_command_d().

◆ listOpFamilyFunctions()

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

Definition at line 6741 of file describe.c.

6743 {
6745  PGresult *res;
6746  printQueryOpt myopt = pset.popt;
6747  bool have_where = false;
6748  static const bool translate_columns[] = {false, false, false, false, false, false};
6749 
6750  initPQExpBuffer(&buf);
6751 
6753  "SELECT\n"
6754  " am.amname AS \"%s\",\n"
6755  " CASE\n"
6756  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6757  " THEN pg_catalog.format('%%I', of.opfname)\n"
6758  " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
6759  " END AS \"%s\",\n"
6760  " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
6761  " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
6762  " ap.amprocnum AS \"%s\"\n",
6763  gettext_noop("AM"),
6764  gettext_noop("Operator family"),
6765  gettext_noop("Registered left type"),
6766  gettext_noop("Registered right type"),
6767  gettext_noop("Number"));
6768 
6769  if (!verbose)
6771  ", p.proname AS \"%s\"\n",
6772  gettext_noop("Function"));
6773  else
6775  ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
6776  gettext_noop("Function"));
6777 
6779  "FROM pg_catalog.pg_amproc ap\n"
6780  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
6781  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
6782  " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
6783  " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
6784 
6785  if (access_method_pattern)
6786  if (!validateSQLNamePattern(&buf, access_method_pattern,
6787  false, false, NULL, "am.amname",
6788  NULL, NULL,
6789  &have_where, 1))
6790  return false;
6791  if (family_pattern)
6792  if (!validateSQLNamePattern(&buf, family_pattern, have_where, false,
6793  "ns.nspname", "of.opfname", NULL, NULL,
6794  NULL, 3))
6795  return false;
6796 
6797  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6798  " ap.amproclefttype = ap.amprocrighttype DESC,\n"
6799  " 3, 4, 5;");
6800 
6801  res = PSQLexec(buf.data);
6802  termPQExpBuffer(&buf);
6803  if (!res)
6804  return false;
6805 
6806  myopt.nullPrint = NULL;
6807  myopt.title = _("List of support functions of operator families");
6808  myopt.translate_header = true;
6809  myopt.translate_columns = translate_columns;
6810  myopt.n_translate_columns = lengthof(translate_columns);
6811 
6812  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6813 
6814  PQclear(res);
6815  return true;
6816 }

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

Referenced by exec_command_d().

◆ listOpFamilyOperators()

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

Definition at line 6650 of file describe.c.

6652 {
6654  PGresult *res;
6655  printQueryOpt myopt = pset.popt;
6656  bool have_where = false;
6657 
6658  static const bool translate_columns[] = {false, false, false, false, false, false};
6659 
6660  initPQExpBuffer(&buf);
6661 
6663  "SELECT\n"
6664  " am.amname AS \"%s\",\n"
6665  " CASE\n"
6666  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6667  " THEN pg_catalog.format('%%I', of.opfname)\n"
6668  " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
6669  " END AS \"%s\",\n"
6670  " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
6671  " o.amopstrategy AS \"%s\",\n"
6672  " CASE o.amoppurpose\n"
6673  " WHEN 'o' THEN '%s'\n"
6674  " WHEN 's' THEN '%s'\n"
6675  " END AS \"%s\"\n",
6676  gettext_noop("AM"),
6677  gettext_noop("Operator family"),
6678  gettext_noop("Operator"),
6679  gettext_noop("Strategy"),
6680  gettext_noop("ordering"),
6681  gettext_noop("search"),
6682  gettext_noop("Purpose"));
6683 
6684  if (verbose)
6686  ", ofs.opfname AS \"%s\"\n",
6687  gettext_noop("Sort opfamily"));
6689  "FROM pg_catalog.pg_amop o\n"
6690  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
6691  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
6692  " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
6693  if (verbose)
6695  " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n");
6696 
6697  if (access_method_pattern)
6698  if (!validateSQLNamePattern(&buf, access_method_pattern,
6699  false, false, NULL, "am.amname",
6700  NULL, NULL,
6701  &have_where, 1))
6702  return false;
6703 
6704  if (family_pattern)
6705  if (!validateSQLNamePattern(&buf, family_pattern, have_where, false,
6706  "nsf.nspname", "of.opfname", NULL, NULL,
6707  NULL, 3))
6708  return false;
6709 
6710  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6711  " o.amoplefttype = o.amoprighttype DESC,\n"
6712  " pg_catalog.format_type(o.amoplefttype, NULL),\n"
6713  " pg_catalog.format_type(o.amoprighttype, NULL),\n"
6714  " o.amopstrategy;");
6715 
6716  res = PSQLexec(buf.data);
6717  termPQExpBuffer(&buf);
6718  if (!res)
6719  return false;
6720 
6721  myopt.nullPrint = NULL;
6722  myopt.title = _("List of operators of operator families");
6723  myopt.translate_header = true;
6724  myopt.translate_columns = translate_columns;
6725  myopt.n_translate_columns = lengthof(translate_columns);
6726 
6727  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6728 
6729  PQclear(res);
6730  return true;
6731 }

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

Referenced by exec_command_d().

◆ listPartitionedTables()

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

Definition at line 3999 of file describe.c.

4000 {
4001  bool showTables = strchr(reltypes, 't') != NULL;
4002  bool showIndexes = strchr(reltypes, 'i') != NULL;
4003  bool showNested = strchr(reltypes, 'n') != NULL;
4005  PQExpBufferData title;
4006  PGresult *res;
4007  printQueryOpt myopt = pset.popt;
4008  bool translate_columns[] = {false, false, false, false, false, false, false, false, false};
4009  const char *tabletitle;
4010  bool mixed_output = false;
4011 
4012  /*
4013  * Note: Declarative table partitioning is only supported as of Pg 10.0.
4014  */
4015  if (pset.sversion < 100000)
4016  {
4017  char sverbuf[32];
4018 
4019  pg_log_error("The server (version %s) does not support declarative table partitioning.",
4021  sverbuf, sizeof(sverbuf)));
4022  return true;
4023  }
4024 
4025  /* If no relation kind was selected, show them all */
4026  if (!showTables && !showIndexes)
4027  showTables = showIndexes = true;
4028 
4029  if (showIndexes && !showTables)
4030  tabletitle = _("List of partitioned indexes"); /* \dPi */
4031  else if (showTables && !showIndexes)
4032  tabletitle = _("List of partitioned tables"); /* \dPt */
4033  else
4034  {
4035  /* show all kinds */
4036  tabletitle = _("List of partitioned relations");
4037  mixed_output = true;
4038  }
4039 
4040  initPQExpBuffer(&buf);
4041 
4043  "SELECT n.nspname as \"%s\",\n"
4044  " c.relname as \"%s\",\n"
4045  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4046  gettext_noop("Schema"),
4047  gettext_noop("Name"),
4048  gettext_noop("Owner"));
4049 
4050  if (mixed_output)
4051  {
4053  ",\n CASE c.relkind"
4054  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
4055  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
4056  " END as \"%s\"",
4057  gettext_noop("partitioned table"),
4058  gettext_noop("partitioned index"),
4059  gettext_noop("Type"));
4060 
4061  translate_columns[3] = true;
4062  }
4063 
4064  if (showNested || pattern)
4066  ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4067  gettext_noop("Parent name"));
4068 
4069  if (showIndexes)
4071  ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4072  gettext_noop("Table"));
4073 
4074  if (verbose)
4075  {
4076  if (showNested)
4077  {
4079  ",\n s.dps as \"%s\"",
4080  gettext_noop("Leaf partition size"));
4082  ",\n s.tps as \"%s\"",
4083  gettext_noop("Total size"));
4084  }
4085  else
4086  /* Sizes of all partitions are considered in this case. */
4088  ",\n s.tps as \"%s\"",
4089  gettext_noop("Total size"));
4090 
4092  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4093  gettext_noop("Description"));
4094  }
4095 
4097  "\nFROM pg_catalog.pg_class c"
4098  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4099 
4100  if (showIndexes)
4102  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4103  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4104 
4105  if (showNested || pattern)
4107  "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4108 
4109  if (verbose)
4110  {
4111  if (pset.sversion < 120000)
4112  {
4114  ",\n LATERAL (WITH RECURSIVE d\n"
4115  " AS (SELECT inhrelid AS oid, 1 AS level\n"
4116  " FROM pg_catalog.pg_inherits\n"
4117  " WHERE inhparent = c.oid\n"
4118  " UNION ALL\n"
4119  " SELECT inhrelid, level + 1\n"
4120  " FROM pg_catalog.pg_inherits i\n"
4121  " JOIN d ON i.inhparent = d.oid)\n"
4122  " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4123  "d.oid))) AS tps,\n"
4124  " pg_catalog.pg_size_pretty(sum("
4125  "\n CASE WHEN d.level = 1"
4126  " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4127  " FROM d) s");
4128  }
4129  else
4130  {
4131  /* PostgreSQL 12 has pg_partition_tree function */
4133  ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4134  "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4135  "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4136  " ELSE 0 END)) AS dps"
4137  ",\n pg_catalog.pg_size_pretty(sum("
4138  "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4139  "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4140  }
4141  }
4142 
4143  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4144  if (showTables)
4145  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
4146  if (showIndexes)
4147  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
4148  appendPQExpBufferStr(&buf, "''"); /* dummy */
4149  appendPQExpBufferStr(&buf, ")\n");
4150 
4151  appendPQExpBufferStr(&buf, !showNested && !pattern ?
4152  " AND NOT c.relispartition\n" : "");
4153 
4154  if (!pattern)
4155  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4156  " AND n.nspname !~ '^pg_toast'\n"
4157  " AND n.nspname <> 'information_schema'\n");
4158 
4159  if (!validateSQLNamePattern(&buf, pattern, true, false,
4160  "n.nspname", "c.relname", NULL,
4161  "pg_catalog.pg_table_is_visible(c.oid)",
4162  NULL, 3))
4163  return false;
4164 
4165  appendPQExpBuffer(&buf, "ORDER BY \"Schema\", %s%s\"Name\";",
4166  mixed_output ? "\"Type\" DESC, " : "",
4167  showNested || pattern ? "\"Parent name\" NULLS FIRST, " : "");
4168 
4169  res = PSQLexec(buf.data);
4170  termPQExpBuffer(&buf);
4171  if (!res)
4172  return false;
4173 
4174  initPQExpBuffer(&title);
4175  appendPQExpBufferStr(&title, tabletitle);
4176 
4177  myopt.nullPrint = NULL;
4178  myopt.title = title.data;
4179  myopt.translate_header = true;
4180  myopt.translate_columns = translate_columns;
4181  myopt.n_translate_columns = lengthof(translate_columns);
4182 
4183  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4184 
4185  termPQExpBuffer(&title);
4186 
4187  PQclear(res);
4188  return true;
4189 }

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

Referenced by exec_command_d().

◆ listPublications()

bool listPublications ( const char *  pattern)

Definition at line 6048 of file describe.c.

6049 {
6051  PGresult *res;
6052  printQueryOpt myopt = pset.popt;
6053  static const bool translate_columns[] = {false, false, false, false, false, false, false, false};
6054 
6055  if (pset.sversion < 100000)
6056  {
6057  char sverbuf[32];
6058 
6059  pg_log_error("The server (version %s) does not support publications.",
6061  sverbuf, sizeof(sverbuf)));
6062  return true;
6063  }
6064 
6065  initPQExpBuffer(&buf);
6066 
6068  "SELECT pubname AS \"%s\",\n"
6069  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6070  " puballtables AS \"%s\",\n"
6071  " pubinsert AS \"%s\",\n"
6072  " pubupdate AS \"%s\",\n"
6073  " pubdelete AS \"%s\"",
6074  gettext_noop("Name"),
6075  gettext_noop("Owner"),
6076  gettext_noop("All tables"),
6077  gettext_noop("Inserts"),
6078  gettext_noop("Updates"),
6079  gettext_noop("Deletes"));
6080  if (pset.sversion >= 110000)
6082  ",\n pubtruncate AS \"%s\"",
6083  gettext_noop("Truncates"));
6084  if (pset.sversion >= 130000)
6086  ",\n pubviaroot AS \"%s\"",
6087  gettext_noop("Via root"));
6088 
6090  "\nFROM pg_catalog.pg_publication\n");
6091 
6092  if (!validateSQLNamePattern(&buf, pattern, false, false,
6093  NULL, "pubname", NULL,
6094  NULL,
6095  NULL, 1))
6096  return false;
6097 
6098  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6099 
6100  res = PSQLexec(buf.data);
6101  termPQExpBuffer(&buf);
6102  if (!res)
6103  return false;
6104 
6105  myopt.nullPrint = NULL;
6106  myopt.title = _("List of publications");
6107  myopt.translate_header = true;
6108  myopt.translate_columns = translate_columns;
6109  myopt.n_translate_columns = lengthof(translate_columns);
6110 
6111  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6112 
6113  PQclear(res);
6114 
6115  return true;
6116 }

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

Referenced by exec_command_d().

◆ listSchemas()

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

Definition at line 4884 of file describe.c.

4885 {
4887  PGresult *res;
4888  printQueryOpt myopt = pset.popt;
4889  int pub_schema_tuples = 0;
4890  char **footers = NULL;
4891 
4892  initPQExpBuffer(&buf);
4894  "SELECT n.nspname AS \"%s\",\n"
4895  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4896  gettext_noop("Name"),
4897  gettext_noop("Owner"));
4898 
4899  if (verbose)
4900  {
4901  appendPQExpBufferStr(&buf, ",\n ");
4902  printACLColumn(&buf, "n.nspacl");
4904  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4905  gettext_noop("Description"));
4906  }
4907 
4909  "\nFROM pg_catalog.pg_namespace n\n");
4910 
4911  if (!showSystem && !pattern)
4913  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
4914 
4915  if (!validateSQLNamePattern(&buf, pattern,
4916  !showSystem && !pattern, false,
4917  NULL, "n.nspname", NULL,
4918  NULL,
4919  NULL, 2))
4920  return false;
4921 
4922  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4923 
4924  res = PSQLexec(buf.data);
4925  if (!res)
4926  {
4927  termPQExpBuffer(&buf);
4928  return false;
4929  }
4930 
4931  myopt.nullPrint = NULL;
4932  myopt.title = _("List of schemas");
4933  myopt.translate_header = true;
4934 
4935  if (pattern && pset.sversion >= 150000)
4936  {
4937  PGresult *result;
4938  int i;
4939 
4941  "SELECT pubname \n"
4942  "FROM pg_catalog.pg_publication p\n"
4943  " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
4944  " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
4945  "WHERE n.nspname = '%s'\n"
4946  "ORDER BY 1",
4947  pattern);
4948  result = PSQLexec(buf.data);
4949  if (!result)
4950  {
4951  termPQExpBuffer(&buf);
4952  return false;
4953  }
4954  else
4955  pub_schema_tuples = PQntuples(result);
4956 
4957  if (pub_schema_tuples > 0)
4958  {
4959  /*
4960  * Allocate memory for footers. Size of footers will be 1 (for
4961  * storing "Publications:" string) + publication schema mapping
4962  * count + 1 (for storing NULL).
4963  */
4964  footers = (char **) pg_malloc((1 + pub_schema_tuples + 1) * sizeof(char *));
4965  footers[0] = pg_strdup(_("Publications:"));
4966 
4967  /* Might be an empty set - that's ok */
4968  for (i = 0; i < pub_schema_tuples; i++)
4969  {
4970  printfPQExpBuffer(&buf, " \"%s\"",
4971  PQgetvalue(result, i, 0));
4972 
4973  footers[i + 1] = pg_strdup(buf.data);
4974  }
4975 
4976  footers[i + 1] = NULL;
4977  myopt.footers = footers;
4978  }
4979 
4980  PQclear(result);
4981  }
4982 
4983  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4984 
4985  termPQExpBuffer(&buf);
4986  PQclear(res);
4987 
4988  /* Free the memory allocated for the footer */
4989  if (footers)
4990  {
4991  char **footer = NULL;
4992 
4993  for (footer = footers; *footer; footer++)
4994  pg_free(*footer);
4995 
4996  pg_free(footers);
4997  }
4998 
4999  return true;
5000 }
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char ** footers
Definition: print.h:172

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, printQueryOpt::footers, gettext_noop, i, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, pg_free(), pg_malloc(), pg_strdup(), _psqlSettings::popt, PQclear(), PQgetvalue(), PQntuples(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTables()

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

Definition at line 3803 of file describe.c.

3804 {
3805  bool showTables = strchr(tabtypes, 't') != NULL;
3806  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3807  bool showViews = strchr(tabtypes, 'v') != NULL;
3808  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3809  bool showSeq = strchr(tabtypes, 's') != NULL;
3810  bool showForeign = strchr(tabtypes, 'E') != NULL;
3811 
3813  PGresult *res;
3814  printQueryOpt myopt = pset.popt;
3815  int cols_so_far;
3816  bool translate_columns[] = {false, false, true, false, false, false, false, false, false};
3817 
3818  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3819  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3820  showTables = showViews = showMatViews = showSeq = showForeign = true;
3821 
3822  initPQExpBuffer(&buf);
3823 
3825  "SELECT n.nspname as \"%s\",\n"
3826  " c.relname as \"%s\",\n"
3827  " CASE c.relkind"
3828  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3829  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3830  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3831  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3832  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3833  " WHEN " CppAsString2(RELKIND_TOASTVALUE) " THEN '%s'"
3834  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3835  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3836  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
3837  " END as \"%s\",\n"
3838  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3839  gettext_noop("Schema"),
3840  gettext_noop("Name"),
3841  gettext_noop("table"),
3842  gettext_noop("view"),
3843  gettext_noop("materialized view"),
3844  gettext_noop("index"),
3845  gettext_noop("sequence"),
3846  gettext_noop("TOAST table"),
3847  gettext_noop("foreign table"),
3848  gettext_noop("partitioned table"),
3849  gettext_noop("partitioned index"),
3850  gettext_noop("Type"),
3851  gettext_noop("Owner"));
3852  cols_so_far = 4;
3853 
3854  if (showIndexes)
3855  {
3857  ",\n c2.relname as \"%s\"",
3858  gettext_noop("Table"));
3859  cols_so_far++;
3860  }
3861 
3862  if (verbose)
3863  {
3864  /*
3865  * Show whether a relation is permanent, temporary, or unlogged.
3866  */
3868  ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3869  gettext_noop("permanent"),
3870  gettext_noop("temporary"),
3871  gettext_noop("unlogged"),
3872  gettext_noop("Persistence"));
3873  translate_columns[cols_so_far] = true;
3874 
3875  /*
3876  * We don't bother to count cols_so_far below here, as there's no need
3877  * to; this might change with future additions to the output columns.
3878  */
3879 
3880  /*
3881  * Access methods exist for tables, materialized views and indexes.
3882  * This has been introduced in PostgreSQL 12 for tables.
3883  */
3884  if (pset.sversion >= 120000 && !pset.hide_tableam &&
3885  (showTables || showMatViews || showIndexes))
3887  ",\n am.amname as \"%s\"",
3888  gettext_noop("Access method"));
3889 
3891  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
3892  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3893  gettext_noop("Size"),
3894  gettext_noop("Description"));
3895  }
3896 
3898  "\nFROM pg_catalog.pg_class c"
3899  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3900 
3901  if (pset.sversion >= 120000 && !pset.hide_tableam &&
3902  (showTables || showMatViews || showIndexes))
3904  "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
3905 
3906  if (showIndexes)
3908  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3909  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3910 
3911  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3912  if (showTables)
3913  {
3914  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
3915  CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
3916  /* with 'S' or a pattern, allow 't' to match TOAST tables too */
3917  if (showSystem || pattern)
3918  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_TOASTVALUE) ",");
3919  }
3920  if (showViews)
3921  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
3922  if (showMatViews)
3923  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_MATVIEW) ",");
3924  if (showIndexes)
3925  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_INDEX) ","
3926  CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
3927  if (showSeq)
3928  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ",");
3929  if (showSystem || pattern)
3930  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3931  if (showForeign)
3932  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ",");
3933 
3934  appendPQExpBufferStr(&buf, "''"); /* dummy */
3935  appendPQExpBufferStr(&buf, ")\n");
3936 
3937  if (!showSystem && !pattern)
3938  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3939  " AND n.nspname !~ '^pg_toast'\n"
3940  " AND n.nspname <> 'information_schema'\n");
3941 
3942  if (!validateSQLNamePattern(&buf, pattern, true, false,
3943  "n.nspname", "c.relname", NULL,
3944  "pg_catalog.pg_table_is_visible(c.oid)",
3945  NULL, 3))
3946  return false;
3947 
3948  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3949 
3950  res = PSQLexec(buf.data);
3951  termPQExpBuffer(&buf);
3952  if (!res)
3953  return false;
3954 
3955  /*
3956  * Most functions in this file are content to print an empty table when
3957  * there are no matching objects. We intentionally deviate from that
3958  * here, but only in !quiet mode, for historical reasons.
3959  */
3960  if (PQntuples(res) == 0 && !pset.quiet)
3961  {
3962  if (pattern)
3963  pg_log_error("Did not find any relation named \"%s\".",
3964  pattern);
3965  else
3966  pg_log_error("Did not find any relations.");
3967  }
3968  else
3969  {
3970  myopt.nullPrint = NULL;
3971  myopt.title = _("List of relations");
3972  myopt.translate_header = true;
3973  myopt.translate_columns = translate_columns;
3974  myopt.n_translate_columns = lengthof(translate_columns);
3975 
3976  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3977  }
3978 
3979  PQclear(res);
3980  return true;
3981 }
bool hide_tableam
Definition: settings.h:138

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

Referenced by exec_command_d().

◆ listTSConfigs()

bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

Definition at line 5375 of file describe.c.

5376 {
5378  PGresult *res;
5379  printQueryOpt myopt = pset.popt;
5380 
5381  if (verbose)
5382  return listTSConfigsVerbose(pattern);
5383 
5384  initPQExpBuffer(&buf);
5385 
5387  "SELECT\n"
5388  " n.nspname as \"%s\",\n"
5389  " c.cfgname as \"%s\",\n"
5390  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5391  "FROM pg_catalog.pg_ts_config c\n"
5392  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5393  gettext_noop("Schema"),
5394  gettext_noop("Name"),
5395  gettext_noop("Description")
5396  );
5397 
5398  if (!validateSQLNamePattern(&buf, pattern, false, false,
5399  "n.nspname", "c.cfgname", NULL,
5400  "pg_catalog.pg_ts_config_is_visible(c.oid)",
5401  NULL, 3))
5402  return false;
5403 
5404  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5405 
5406  res = PSQLexec(buf.data);
5407  termPQExpBuffer(&buf);
5408  if (!res)
5409  return false;
5410 
5411  myopt.nullPrint = NULL;
5412  myopt.title = _("List of text search configurations");
5413  myopt.translate_header = true;
5414 
5415  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5416 
5417  PQclear(res);
5418  return true;
5419 }
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:5422

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), listTSConfigsVerbose(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTSDictionaries()

bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 5249 of file describe.c.

5250 {
5252  PGresult *res;
5253  printQueryOpt myopt = pset.popt;
5254 
5255  initPQExpBuffer(&buf);
5256 
5258  "SELECT\n"
5259  " n.nspname as \"%s\",\n"
5260  " d.dictname as \"%s\",\n",
5261  gettext_noop("Schema"),
5262  gettext_noop("Name"));
5263 
5264  if (verbose)
5265  {
5267  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5268  " pg_catalog.pg_ts_template t\n"
5269  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5270  " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5271  " d.dictinitoption as \"%s\",\n",
5272  gettext_noop("Template"),
5273  gettext_noop("Init options"));
5274  }
5275 
5277  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5278  gettext_noop("Description"));
5279 
5280  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
5281  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5282 
5283  if (!validateSQLNamePattern(&buf, pattern, false, false,
5284  "n.nspname", "d.dictname", NULL,
5285  "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5286  NULL, 3))
5287  return false;
5288 
5289  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5290 
5291  res = PSQLexec(buf.data);
5292  termPQExpBuffer(&buf);
5293  if (!res)
5294  return false;
5295 
5296  myopt.nullPrint = NULL;
5297  myopt.title = _("List of text search dictionaries");
5298  myopt.translate_header = true;
5299 
5300  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5301 
5302  PQclear(res);
5303  return true;
5304 }

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTSParsers()

bool listTSParsers ( const char *  pattern,
bool  verbose 
)

Definition at line 5008 of file describe.c.

5009 {
5011  PGresult *res;
5012  printQueryOpt myopt = pset.popt;
5013 
5014  if (verbose)
5015  return listTSParsersVerbose(pattern);
5016 
5017  initPQExpBuffer(&buf);
5018 
5020  "SELECT\n"
5021  " n.nspname as \"%s\",\n"
5022  " p.prsname as \"%s\",\n"
5023  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5024  "FROM pg_catalog.pg_ts_parser p\n"
5025  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5026  gettext_noop("Schema"),
5027  gettext_noop("Name"),
5028  gettext_noop("Description")
5029  );
5030 
5031  if (!validateSQLNamePattern(&buf, pattern, false, false,
5032  "n.nspname", "p.prsname", NULL,
5033  "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5034  NULL, 3))
5035  return false;
5036 
5037  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5038 
5039  res = PSQLexec(buf.data);
5040  termPQExpBuffer(&buf);
5041  if (!res)
5042  return false;
5043 
5044  myopt.nullPrint = NULL;
5045  myopt.title = _("List of text search parsers");
5046  myopt.translate_header = true;
5047 
5048  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5049 
5050  PQclear(res);
5051  return true;
5052 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:5058

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), listTSParsersVerbose(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTSTemplates()

bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

Definition at line 5312 of file describe.c.

5313 {
5315  PGresult *res;
5316  printQueryOpt myopt = pset.popt;
5317 
5318  initPQExpBuffer(&buf);
5319 
5320  if (verbose)
5322  "SELECT\n"
5323  " n.nspname AS \"%s\",\n"
5324  " t.tmplname AS \"%s\",\n"
5325  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5326  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5327  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5328  gettext_noop("Schema"),
5329  gettext_noop("Name"),
5330  gettext_noop("Init"),
5331  gettext_noop("Lexize"),
5332  gettext_noop("Description"));
5333  else
5335  "SELECT\n"
5336  " n.nspname AS \"%s\",\n"
5337  " t.tmplname AS \"%s\",\n"
5338  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5339  gettext_noop("Schema"),
5340  gettext_noop("Name"),
5341  gettext_noop("Description"));
5342 
5343  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
5344  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5345 
5346  if (!validateSQLNamePattern(&buf, pattern, false, false,
5347  "n.nspname", "t.tmplname", NULL,
5348  "pg_catalog.pg_ts_template_is_visible(t.oid)",
5349  NULL, 3))
5350  return false;
5351 
5352  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5353 
5354  res = PSQLexec(buf.data);
5355  termPQExpBuffer(&buf);
5356  if (!res)
5357  return false;
5358 
5359  myopt.nullPrint = NULL;
5360  myopt.title = _("List of text search templates");
5361  myopt.translate_header = true;
5362 
5363  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5364 
5365  PQclear(res);
5366  return true;
5367 }

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listUserMappings()

bool listUserMappings ( const char *  pattern,
bool  verbose 
)

Definition at line 5718 of file describe.c.

5719 {
5721  PGresult *res;
5722  printQueryOpt myopt = pset.popt;
5723 
5724  initPQExpBuffer(&buf);
5726  "SELECT um.srvname AS \"%s\",\n"
5727  " um.usename AS \"%s\"",
5728  gettext_noop("Server"),
5729  gettext_noop("User name"));
5730 
5731  if (verbose)
5733  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
5734  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5735  " pg_catalog.quote_ident(option_name) || ' ' || "
5736  " pg_catalog.quote_literal(option_value) FROM "
5737  " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
5738  " END AS \"%s\"",
5739  gettext_noop("FDW options"));
5740 
5741  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
5742 
5743  if (!validateSQLNamePattern(&buf, pattern, false, false,
5744  NULL, "um.srvname", "um.usename", NULL,
5745  NULL, 1))
5746  return false;
5747 
5748  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
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 user mappings");
5757  myopt.translate_header = true;
5758 
5759  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5760 
5761  PQclear(res);
5762  return true;
5763 }

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ objectDescription()

bool objectDescription ( const char *  pattern,
bool  showSystem 
)

Definition at line 1218 of file describe.c.

1219 {
1221  PGresult *res;
1222  printQueryOpt myopt = pset.popt;
1223  static const bool translate_columns[] = {false, false, true, false};
1224 
1225  initPQExpBuffer(&buf);
1226 
1228  "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1229  "FROM (\n",
1230  gettext_noop("Schema"),
1231  gettext_noop("Name"),
1232  gettext_noop("Object"),
1233  gettext_noop("Description"));
1234 
1235  /* Table constraint descriptions */
1237  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1238  " n.nspname as nspname,\n"
1239  " CAST(pgc.conname AS pg_catalog.text) as name,"
1240  " CAST('%s' AS pg_catalog.text) as object\n"
1241  " FROM pg_catalog.pg_constraint pgc\n"
1242  " JOIN pg_catalog.pg_class c "
1243  "ON c.oid = pgc.conrelid\n"
1244  " LEFT JOIN pg_catalog.pg_namespace n "
1245  " ON n.oid = c.relnamespace\n",
1246  gettext_noop("table constraint"));
1247 
1248  if (!showSystem && !pattern)
1249  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1250  " AND n.nspname <> 'information_schema'\n");
1251 
1252  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1253  false, "n.nspname", "pgc.conname", NULL,
1254  "pg_catalog.pg_table_is_visible(c.oid)",
1255  NULL, 3))
1256  return false;
1257 
1258  /* Domain constraint descriptions */
1260  "UNION ALL\n"
1261  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1262  " n.nspname as nspname,\n"
1263  " CAST(pgc.conname AS pg_catalog.text) as name,"
1264  " CAST('%s' AS pg_catalog.text) as object\n"
1265  " FROM pg_catalog.pg_constraint pgc\n"
1266  " JOIN pg_catalog.pg_type t "
1267  "ON t.oid = pgc.contypid\n"
1268  " LEFT JOIN pg_catalog.pg_namespace n "
1269  " ON n.oid = t.typnamespace\n",
1270  gettext_noop("domain constraint"));
1271 
1272  if (!showSystem && !pattern)
1273  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1274  " AND n.nspname <> 'information_schema'\n");
1275 
1276  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1277  false, "n.nspname", "pgc.conname", NULL,
1278  "pg_catalog.pg_type_is_visible(t.oid)",
1279  NULL, 3))
1280  return false;
1281 
1282  /* Operator class descriptions */
1284  "UNION ALL\n"
1285  " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1286  " n.nspname as nspname,\n"
1287  " CAST(o.opcname AS pg_catalog.text) as name,\n"
1288  " CAST('%s' AS pg_catalog.text) as object\n"
1289  " FROM pg_catalog.pg_opclass o\n"
1290  " JOIN pg_catalog.pg_am am ON "
1291  "o.opcmethod = am.oid\n"
1292  " JOIN pg_catalog.pg_namespace n ON "
1293  "n.oid = o.opcnamespace\n",
1294  gettext_noop("operator class"));
1295 
1296  if (!showSystem && !pattern)
1297  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1298  " AND n.nspname <> 'information_schema'\n");
1299 
1300  if (!validateSQLNamePattern(&buf, pattern, true, false,
1301  "n.nspname", "o.opcname", NULL,
1302  "pg_catalog.pg_opclass_is_visible(o.oid)",
1303  NULL, 3))
1304  return false;
1305 
1306  /* Operator family descriptions */
1308  "UNION ALL\n"
1309  " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1310  " n.nspname as nspname,\n"
1311  " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1312  " CAST('%s' AS pg_catalog.text) as object\n"
1313  " FROM pg_catalog.pg_opfamily opf\n"
1314  " JOIN pg_catalog.pg_am am "
1315  "ON opf.opfmethod = am.oid\n"
1316  " JOIN pg_catalog.pg_namespace n "
1317  "ON opf.opfnamespace = n.oid\n",
1318  gettext_noop("operator family"));
1319 
1320  if (!showSystem && !pattern)
1321  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1322  " AND n.nspname <> 'information_schema'\n");
1323 
1324  if (!validateSQLNamePattern(&buf, pattern, true, false,
1325  "n.nspname", "opf.opfname", NULL,
1326  "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1327  NULL, 3))
1328  return false;
1329 
1330  /* Rule descriptions (ignore rules for views) */
1332  "UNION ALL\n"
1333  " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1334  " n.nspname as nspname,\n"
1335  " CAST(r.rulename AS pg_catalog.text) as name,"
1336  " CAST('%s' AS pg_catalog.text) as object\n"
1337  " FROM pg_catalog.pg_rewrite r\n"
1338  " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1339  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1340  " WHERE r.rulename != '_RETURN'\n",
1341  gettext_noop("rule"));
1342 
1343  if (!showSystem && !pattern)
1344  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1345  " AND n.nspname <> 'information_schema'\n");
1346 
1347  if (!validateSQLNamePattern(&buf, pattern, true, false,
1348  "n.nspname", "r.rulename", NULL,
1349  "pg_catalog.pg_table_is_visible(c.oid)",
1350  NULL, 3))
1351  return false;
1352 
1353  /* Trigger descriptions */
1355  "UNION ALL\n"
1356  " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1357  " n.nspname as nspname,\n"
1358  " CAST(t.tgname AS pg_catalog.text) as name,"
1359  " CAST('%s' AS pg_catalog.text) as object\n"
1360  " FROM pg_catalog.pg_trigger t\n"
1361  " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1362  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1363  gettext_noop("trigger"));
1364 
1365  if (!showSystem && !pattern)
1366  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1367  " AND n.nspname <> 'information_schema'\n");
1368 
1369  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1370  "n.nspname", "t.tgname", NULL,
1371  "pg_catalog.pg_table_is_visible(c.oid)",
1372  NULL, 3))
1373  return false;
1374 
1376  ") AS tt\n"
1377  " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1378 
1379  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1380 
1381  res = PSQLexec(buf.data);
1382  termPQExpBuffer(&buf);
1383  if (!res)
1384  return false;
1385 
1386  myopt.nullPrint = NULL;
1387  myopt.title = _("Object descriptions");
1388  myopt.translate_header = true;
1389  myopt.translate_columns = translate_columns;
1390  myopt.n_translate_columns = lengthof(translate_columns);
1391 
1392  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1393 
1394  PQclear(res);
1395  return true;
1396 }

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

Referenced by exec_command_d().

◆ permissionsList()

bool permissionsList ( const char *  pattern)

Definition at line 980 of file describe.c.

981 {
983  PGresult *res;
984  printQueryOpt myopt = pset.popt;
985  static const bool translate_columns[] = {false, false, true, false, false, false};
986 
988 
989  /*
990  * we ignore indexes and toast tables since they have no meaningful rights
991  */
993  "SELECT n.nspname as \"%s\",\n"
994  " c.relname as \"%s\",\n"
995  " CASE c.relkind"
996  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
997  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
998  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
999  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
1000  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
1001  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
1002  " END as \"%s\",\n"
1003  " ",
1004  gettext_noop("Schema"),
1005  gettext_noop("Name"),
1006  gettext_noop("table"),
1007  gettext_noop("view"),
1008  gettext_noop("materialized view"),
1009  gettext_noop("sequence"),
1010  gettext_noop("foreign table"),
1011  gettext_noop("partitioned table"),
1012  gettext_noop("Type"));
1013 
1014  printACLColumn(&buf, "c.relacl");
1015 
1017  ",\n pg_catalog.array_to_string(ARRAY(\n"
1018  " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1019  " FROM pg_catalog.pg_attribute a\n"
1020  " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1021  " ), E'\\n') AS \"%s\"",
1022  gettext_noop("Column privileges"));
1023 
1024  if (pset.sversion >= 90500 && pset.sversion < 100000)
1026  ",\n pg_catalog.array_to_string(ARRAY(\n"
1027  " SELECT polname\n"
1028  " || CASE WHEN polcmd != '*' THEN\n"
1029  " E' (' || polcmd::pg_catalog.text || E'):'\n"
1030  " ELSE E':'\n"
1031  " END\n"
1032  " || CASE WHEN polqual IS NOT NULL THEN\n"
1033  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1034  " ELSE E''\n"
1035  " END\n"
1036  " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1037  " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1038  " ELSE E''\n"
1039  " END"
1040  " || CASE WHEN polroles <> '{0}' THEN\n"
1041  " E'\\n to: ' || pg_catalog.array_to_string(\n"
1042  " ARRAY(\n"
1043  " SELECT rolname\n"
1044  " FROM pg_catalog.pg_roles\n"
1045  " WHERE oid = ANY (polroles)\n"
1046  " ORDER BY 1\n"
1047  " ), E', ')\n"
1048  " ELSE E''\n"
1049  " END\n"
1050  " FROM pg_catalog.pg_policy pol\n"
1051  " WHERE polrelid = c.oid), E'\\n')\n"
1052  " AS \"%s\"",
1053  gettext_noop("Policies"));
1054 
1055  if (pset.sversion >= 100000)
1057  ",\n pg_catalog.array_to_string(ARRAY(\n"
1058  " SELECT polname\n"
1059  " || CASE WHEN NOT polpermissive THEN\n"
1060  " E' (RESTRICTIVE)'\n"
1061  " ELSE '' END\n"
1062  " || CASE WHEN polcmd != '*' THEN\n"
1063  " E' (' || polcmd::pg_catalog.text || E'):'\n"
1064  " ELSE E':'\n"
1065  " END\n"
1066  " || CASE WHEN polqual IS NOT NULL THEN\n"
1067  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1068  " ELSE E''\n"
1069  " END\n"
1070  " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1071  " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1072  " ELSE E''\n"
1073  " END"
1074  " || CASE WHEN polroles <> '{0}' THEN\n"
1075  " E'\\n to: ' || pg_catalog.array_to_string(\n"
1076  " ARRAY(\n"
1077  " SELECT rolname\n"
1078  " FROM pg_catalog.pg_roles\n"
1079  " WHERE oid = ANY (polroles)\n"
1080  " ORDER BY 1\n"
1081  " ), E', ')\n"
1082  " ELSE E''\n"
1083  " END\n"
1084  " FROM pg_catalog.pg_policy pol\n"
1085  " WHERE polrelid = c.oid), E'\\n')\n"
1086  " AS \"%s\"",
1087  gettext_noop("Policies"));
1088 
1089  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
1090  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1091  "WHERE c.relkind IN ("
1092  CppAsString2(RELKIND_RELATION) ","
1093  CppAsString2(RELKIND_VIEW) ","
1094  CppAsString2(RELKIND_MATVIEW) ","
1095  CppAsString2(RELKIND_SEQUENCE) ","
1096  CppAsString2(RELKIND_FOREIGN_TABLE) ","
1097  CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
1098 
1099  /*
1100  * Unless a schema pattern is specified, we suppress system and temp
1101  * tables, since they normally aren't very interesting from a permissions
1102  * point of view. You can see 'em by explicit request though, eg with \z
1103  * pg_catalog.*
1104  */
1105  if (!validateSQLNamePattern(&buf, pattern, true, false,
1106  "n.nspname", "c.relname", NULL,
1107  "n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)",
1108  NULL, 3))
1109  return false;
1110 
1111  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
1112 
1113  res = PSQLexec(buf.data);
1114  if (!res)
1115  {
1116  termPQExpBuffer(&buf);
1117  return false;
1118  }
1119 
1120  myopt.nullPrint = NULL;
1121  printfPQExpBuffer(&buf, _("Access privileges"));
1122  myopt.title = buf.data;
1123  myopt.translate_header = true;
1124  myopt.translate_columns = translate_columns;
1125  myopt.n_translate_columns = lengthof(translate_columns);
1126 
1127  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1128 
1129  termPQExpBuffer(&buf);
1130  PQclear(res);
1131  return true;
1132 }

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d(), and exec_command_z().