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 showSystem)
 
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 *type_pattern, bool verbose)
 
bool listOperatorFamilies (const char *access_method_pattern, const char *type_pattern, bool verbose)
 
bool listOpFamilyOperators (const char *access_method_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 142 of file describe.c.

143 {
145  PGresult *res;
146  printQueryOpt myopt = pset.popt;
147  static const bool translate_columns[] = {false, true, false, false};
148 
149  if (pset.sversion < 90600)
150  {
151  char sverbuf[32];
152 
153  pg_log_error("The server (version %s) does not support access methods.",
155  sverbuf, sizeof(sverbuf)));
156  return true;
157  }
158 
160 
162  "SELECT amname AS \"%s\",\n"
163  " CASE amtype"
164  " WHEN 'i' THEN '%s'"
165  " WHEN 't' THEN '%s'"
166  " END AS \"%s\"",
167  gettext_noop("Name"),
168  gettext_noop("Index"),
169  gettext_noop("Table"),
170  gettext_noop("Type"));
171 
172  if (verbose)
173  {
175  ",\n amhandler AS \"%s\",\n"
176  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
177  gettext_noop("Handler"),
178  gettext_noop("Description"));
179  }
180 
182  "\nFROM pg_catalog.pg_am\n");
183 
184  if (!validateSQLNamePattern(&buf, pattern, false, false,
185  NULL, "amname", NULL,
186  NULL,
187  NULL, 1))
188  {
190  return false;
191  }
192 
193  appendPQExpBufferStr(&buf, "ORDER BY 1;");
194 
195  res = PSQLexec(buf.data);
197  if (!res)
198  return false;
199 
200  myopt.nullPrint = NULL;
201  myopt.title = _("List of access methods");
202  myopt.translate_header = true;
203  myopt.translate_columns = translate_columns;
204  myopt.n_translate_columns = lengthof(translate_columns);
205 
206  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
207 
208  PQclear(res);
209  return true;
210 }
PGresult * PSQLexec(const char *query)
Definition: common.c:560
#define gettext_noop(x)
Definition: c.h:1186
#define lengthof(array)
Definition: c.h:772
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:6128
#define _(x)
Definition: elog.c:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3534
int verbose
#define pg_log_error(...)
Definition: logging.h:106
static char * buf
Definition: pg_test_fsync.c:67
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
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:119
FILE * queryFout
Definition: settings.h:84
const bool * translate_columns
Definition: print.h:185
char * nullPrint
Definition: print.h:181
char * title
Definition: print.h:182
bool translate_header
Definition: print.h:184
int n_translate_columns
Definition: print.h:187

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  {
117  return false;
118  }
119 
120  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
121 
122  res = PSQLexec(buf.data);
124  if (!res)
125  return false;
126 
127  myopt.nullPrint = NULL;
128  myopt.title = _("List of aggregate functions");
129  myopt.translate_header = true;
130 
131  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
132 
133  PQclear(res);
134  return true;
135 }

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 4495 of file describe.c.

4497 {
4499  PGresult *res;
4500  printQueryOpt myopt = pset.popt;
4501 
4502  initPQExpBuffer(&buf);
4504  "SELECT s.name AS \"%s\", "
4505  "pg_catalog.current_setting(s.name) AS \"%s\"",
4506  gettext_noop("Parameter"),
4507  gettext_noop("Value"));
4508 
4509  if (verbose)
4510  {
4512  ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4513  gettext_noop("Type"),
4514  gettext_noop("Context"));
4515  if (pset.sversion >= 150000)
4516  printACLColumn(&buf, "p.paracl");
4517  else
4518  appendPQExpBuffer(&buf, "NULL AS \"%s\"",
4519  gettext_noop("Access privileges"));
4520  }
4521 
4522  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_settings s\n");
4523 
4524  if (verbose && pset.sversion >= 150000)
4526  " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4527  " ON pg_catalog.lower(s.name) = p.parname\n");
4528 
4529  if (pattern)
4530  processSQLNamePattern(pset.db, &buf, pattern,
4531  false, false,
4532  NULL, "pg_catalog.lower(s.name)", NULL,
4533  NULL, NULL, NULL);
4534  else
4535  appendPQExpBufferStr(&buf, "WHERE s.source <> 'default' AND\n"
4536  " s.setting IS DISTINCT FROM s.boot_val\n");
4537 
4538  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4539 
4540  res = PSQLexec(buf.data);
4541  termPQExpBuffer(&buf);
4542  if (!res)
4543  return false;
4544 
4545  myopt.nullPrint = NULL;
4546  if (pattern)
4547  myopt.title = _("List of configuration parameters");
4548  else
4549  myopt.title = _("List of non-default configuration parameters");
4550  myopt.translate_header = true;
4551 
4552  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4553 
4554  PQclear(res);
4555  return true;
4556 }
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6612
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:891
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 291 of file describe.c.

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

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 775 of file describe.c.

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

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 6304 of file describe.c.

6305 {
6307  int i;
6308  PGresult *res;
6309  bool has_pubtruncate;
6310  bool has_pubviaroot;
6311 
6312  PQExpBufferData title;
6313  printTableContent cont;
6314 
6315  if (pset.sversion < 100000)
6316  {
6317  char sverbuf[32];
6318 
6319  pg_log_error("The server (version %s) does not support publications.",
6321  sverbuf, sizeof(sverbuf)));
6322  return true;
6323  }
6324 
6325  has_pubtruncate = (pset.sversion >= 110000);
6326  has_pubviaroot = (pset.sversion >= 130000);
6327 
6328  initPQExpBuffer(&buf);
6329 
6331  "SELECT oid, pubname,\n"
6332  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6333  " puballtables, pubinsert, pubupdate, pubdelete");
6334  if (has_pubtruncate)
6336  ", pubtruncate");
6337  if (has_pubviaroot)
6339  ", pubviaroot");
6341  "\nFROM pg_catalog.pg_publication\n");
6342 
6343  if (!validateSQLNamePattern(&buf, pattern, false, false,
6344  NULL, "pubname", NULL,
6345  NULL,
6346  NULL, 1))
6347  {
6348  termPQExpBuffer(&buf);
6349  return false;
6350  }
6351 
6352  appendPQExpBufferStr(&buf, "ORDER BY 2;");
6353 
6354  res = PSQLexec(buf.data);
6355  if (!res)
6356  {
6357  termPQExpBuffer(&buf);
6358  return false;
6359  }
6360 
6361  if (PQntuples(res) == 0)
6362  {
6363  if (!pset.quiet)
6364  {
6365  if (pattern)
6366  pg_log_error("Did not find any publication named \"%s\".",
6367  pattern);
6368  else
6369  pg_log_error("Did not find any publications.");
6370  }
6371 
6372  termPQExpBuffer(&buf);
6373  PQclear(res);
6374  return false;
6375  }
6376 
6377  for (i = 0; i < PQntuples(res); i++)
6378  {
6379  const char align = 'l';
6380  int ncols = 5;
6381  int nrows = 1;
6382  char *pubid = PQgetvalue(res, i, 0);
6383  char *pubname = PQgetvalue(res, i, 1);
6384  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
6385  printTableOpt myopt = pset.popt.topt;
6386 
6387  if (has_pubtruncate)
6388  ncols++;
6389  if (has_pubviaroot)
6390  ncols++;
6391 
6392  initPQExpBuffer(&title);
6393  printfPQExpBuffer(&title, _("Publication %s"), pubname);
6394  printTableInit(&cont, &myopt, title.data, ncols, nrows);
6395 
6396  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
6397  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
6398  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
6399  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
6400  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
6401  if (has_pubtruncate)
6402  printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
6403  if (has_pubviaroot)
6404  printTableAddHeader(&cont, gettext_noop("Via root"), true, align);
6405 
6406  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
6407  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
6408  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
6409  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
6410  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
6411  if (has_pubtruncate)
6412  printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
6413  if (has_pubviaroot)
6414  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
6415 
6416  if (!puballtables)
6417  {
6418  /* Get the tables for the specified publication */
6420  "SELECT n.nspname, c.relname");
6421  if (pset.sversion >= 150000)
6422  {
6424  ", pg_get_expr(pr.prqual, c.oid)");
6426  ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6427  " pg_catalog.array_to_string("
6428  " ARRAY(SELECT attname\n"
6429  " FROM\n"
6430  " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6431  " pg_catalog.pg_attribute\n"
6432  " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6433  " ELSE NULL END)");
6434  }
6435  else
6437  ", NULL, NULL");
6439  "\nFROM pg_catalog.pg_class c,\n"
6440  " pg_catalog.pg_namespace n,\n"
6441  " pg_catalog.pg_publication_rel pr\n"
6442  "WHERE c.relnamespace = n.oid\n"
6443  " AND c.oid = pr.prrelid\n"
6444  " AND pr.prpubid = '%s'\n"
6445  "ORDER BY 1,2", pubid);
6446  if (!addFooterToPublicationDesc(&buf, _("Tables:"), false, &cont))
6447  goto error_return;
6448 
6449  if (pset.sversion >= 150000)
6450  {
6451  /* Get the schemas for the specified publication */
6453  "SELECT n.nspname\n"
6454  "FROM pg_catalog.pg_namespace n\n"
6455  " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6456  "WHERE pn.pnpubid = '%s'\n"
6457  "ORDER BY 1", pubid);
6458  if (!addFooterToPublicationDesc(&buf, _("Tables from schemas:"),
6459  true, &cont))
6460  goto error_return;
6461  }
6462  }
6463 
6464  printTable(&cont, pset.queryFout, false, pset.logfile);
6465  printTableCleanup(&cont);
6466 
6467  termPQExpBuffer(&title);
6468  }
6469 
6470  termPQExpBuffer(&buf);
6471  PQclear(res);
6472 
6473  return true;
6474 
6475 error_return:
6476  printTableCleanup(&cont);
6477  PQclear(res);
6478  termPQExpBuffer(&buf);
6479  termPQExpBuffer(&title);
6480  return false;
6481 }
static bool addFooterToPublicationDesc(PQExpBuffer buf, const char *footermsg, bool as_schema, printTableContent *const cont)
Definition: describe.c:6258
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3310
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3705
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3171
void printTableCleanup(printTableContent *const content)
Definition: print.c:3339
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3248
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3428
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3208
printTableOpt topt
Definition: print.h:180

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 3614 of file describe.c.

3615 {
3617  PGresult *res;
3618  printTableContent cont;
3619  printTableOpt myopt = pset.popt.topt;
3620  int ncols = 3;
3621  int nrows = 0;
3622  int i;
3623  int conns;
3624  const char align = 'l';
3625  char **attr;
3626 
3627  myopt.default_footer = false;
3628 
3629  initPQExpBuffer(&buf);
3630 
3632  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3633  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3634  " r.rolconnlimit, r.rolvaliduntil,\n"
3635  " ARRAY(SELECT b.rolname\n"
3636  " FROM pg_catalog.pg_auth_members m\n"
3637  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3638  " WHERE m.member = r.oid) as memberof");
3639 
3640  if (verbose)
3641  {
3642  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3643  ncols++;
3644  }
3645  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3646 
3647  if (pset.sversion >= 90500)
3648  {
3649  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3650  }
3651 
3652  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3653 
3654  if (!showSystem && !pattern)
3655  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3656 
3657  if (!validateSQLNamePattern(&buf, pattern, false, false,
3658  NULL, "r.rolname", NULL, NULL,
3659  NULL, 1))
3660  {
3661  termPQExpBuffer(&buf);
3662  return false;
3663  }
3664 
3665  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3666 
3667  res = PSQLexec(buf.data);
3668  if (!res)
3669  return false;
3670 
3671  nrows = PQntuples(res);
3672  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3673 
3674  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3675 
3676  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3677  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3678  /* ignores implicit memberships from superuser & pg_database_owner */
3679  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3680 
3681  if (verbose)
3682  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3683 
3684  for (i = 0; i < nrows; i++)
3685  {
3686  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3687 
3689  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3690  add_role_attribute(&buf, _("Superuser"));
3691 
3692  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3693  add_role_attribute(&buf, _("No inheritance"));
3694 
3695  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3696  add_role_attribute(&buf, _("Create role"));
3697 
3698  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3699  add_role_attribute(&buf, _("Create DB"));
3700 
3701  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3702  add_role_attribute(&buf, _("Cannot login"));
3703 
3704  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3705  add_role_attribute(&buf, _("Replication"));
3706 
3707  if (pset.sversion >= 90500)
3708  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3709  add_role_attribute(&buf, _("Bypass RLS"));
3710 
3711  conns = atoi(PQgetvalue(res, i, 6));
3712  if (conns >= 0)
3713  {
3714  if (buf.len > 0)
3715  appendPQExpBufferChar(&buf, '\n');
3716 
3717  if (conns == 0)
3718  appendPQExpBufferStr(&buf, _("No connections"));
3719  else
3720  appendPQExpBuffer(&buf, ngettext("%d connection",
3721  "%d connections",
3722  conns),
3723  conns);
3724  }
3725 
3726  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3727  {
3728  if (buf.len > 0)
3729  appendPQExpBufferChar(&buf, '\n');
3730  appendPQExpBufferStr(&buf, _("Password valid until "));
3732  }
3733 
3734  attr[i] = pg_strdup(buf.data);
3735 
3736  printTableAddCell(&cont, attr[i], false, false);
3737 
3738  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3739 
3740  if (verbose)
3741  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3742  }
3743  termPQExpBuffer(&buf);
3744 
3745  printTable(&cont, pset.queryFout, false, pset.logfile);
3746  printTableCleanup(&cont);
3747 
3748  for (i = 0; i < nrows; i++)
3749  free(attr[i]);
3750  free(attr);
3751 
3752  PQclear(res);
3753  return true;
3754 }
#define ngettext(s, p, n)
Definition: c.h:1171
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3757
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:146
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
bool default_footer
Definition: print.h:124

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 6490 of file describe.c.

6491 {
6493  PGresult *res;
6494  printQueryOpt myopt = pset.popt;
6495  static const bool translate_columns[] = {false, false, false, false,
6496  false, false, false, false, false, false, false, false};
6497 
6498  if (pset.sversion < 100000)
6499  {
6500  char sverbuf[32];
6501 
6502  pg_log_error("The server (version %s) does not support subscriptions.",
6504  sverbuf, sizeof(sverbuf)));
6505  return true;
6506  }
6507 
6508  initPQExpBuffer(&buf);
6509 
6511  "SELECT subname AS \"%s\"\n"
6512  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6513  ", subenabled AS \"%s\"\n"
6514  ", subpublications AS \"%s\"\n",
6515  gettext_noop("Name"),
6516  gettext_noop("Owner"),
6517  gettext_noop("Enabled"),
6518  gettext_noop("Publication"));
6519 
6520  if (verbose)
6521  {
6522  /* Binary mode and streaming are only supported in v14 and higher */
6523  if (pset.sversion >= 140000)
6524  {
6526  ", subbinary AS \"%s\"\n",
6527  gettext_noop("Binary"));
6528 
6529  if (pset.sversion >= 160000)
6531  ", (CASE substream\n"
6532  " WHEN 'f' THEN 'off'\n"
6533  " WHEN 't' THEN 'on'\n"
6534  " WHEN 'p' THEN 'parallel'\n"
6535  " END) AS \"%s\"\n",
6536  gettext_noop("Streaming"));
6537  else
6539  ", substream AS \"%s\"\n",
6540  gettext_noop("Streaming"));
6541  }
6542 
6543  /* Two_phase and disable_on_error are only supported in v15 and higher */
6544  if (pset.sversion >= 150000)
6546  ", subtwophasestate AS \"%s\"\n"
6547  ", subdisableonerr AS \"%s\"\n",
6548  gettext_noop("Two-phase commit"),
6549  gettext_noop("Disable on error"));
6550 
6551  if (pset.sversion >= 160000)
6553  ", suborigin AS \"%s\"\n",
6554  gettext_noop("Origin"));
6555 
6557  ", subsynccommit AS \"%s\"\n"
6558  ", subconninfo AS \"%s\"\n",
6559  gettext_noop("Synchronous commit"),
6560  gettext_noop("Conninfo"));
6561 
6562  /* Skip LSN is only supported in v15 and higher */
6563  if (pset.sversion >= 150000)
6565  ", subskiplsn AS \"%s\"\n",
6566  gettext_noop("Skip LSN"));
6567  }
6568 
6569  /* Only display subscriptions in current database. */
6571  "FROM pg_catalog.pg_subscription\n"
6572  "WHERE subdbid = (SELECT oid\n"
6573  " FROM pg_catalog.pg_database\n"
6574  " WHERE datname = pg_catalog.current_database())");
6575 
6576  if (!validateSQLNamePattern(&buf, pattern, true, false,
6577  NULL, "subname", NULL,
6578  NULL,
6579  NULL, 1))
6580  {
6581  termPQExpBuffer(&buf);
6582  return false;
6583  }
6584 
6585  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6586 
6587  res = PSQLexec(buf.data);
6588  termPQExpBuffer(&buf);
6589  if (!res)
6590  return false;
6591 
6592  myopt.nullPrint = NULL;
6593  myopt.title = _("List of subscriptions");
6594  myopt.translate_header = true;
6595  myopt.translate_columns = translate_columns;
6596  myopt.n_translate_columns = lengthof(translate_columns);
6597 
6598  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6599 
6600  PQclear(res);
6601  return true;
6602 }

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 1446 of file describe.c.

1447 {
1449  PGresult *res;
1450  int i;
1451 
1452  initPQExpBuffer(&buf);
1453 
1455  "SELECT c.oid,\n"
1456  " n.nspname,\n"
1457  " c.relname\n"
1458  "FROM pg_catalog.pg_class c\n"
1459  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1460 
1461  if (!showSystem && !pattern)
1462  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1463  " AND n.nspname <> 'information_schema'\n");
1464 
1465  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1466  "n.nspname", "c.relname", NULL,
1467  "pg_catalog.pg_table_is_visible(c.oid)",
1468  NULL, 3))
1469  {
1470  termPQExpBuffer(&buf);
1471  return false;
1472  }
1473 
1474  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1475 
1476  res = PSQLexec(buf.data);
1477  termPQExpBuffer(&buf);
1478  if (!res)
1479  return false;
1480 
1481  if (PQntuples(res) == 0)
1482  {
1483  if (!pset.quiet)
1484  {
1485  if (pattern)
1486  pg_log_error("Did not find any relation named \"%s\".",
1487  pattern);
1488  else
1489  pg_log_error("Did not find any relations.");
1490  }
1491  PQclear(res);
1492  return false;
1493  }
1494 
1495  for (i = 0; i < PQntuples(res); i++)
1496  {
1497  const char *oid;
1498  const char *nspname;
1499  const char *relname;
1500 
1501  oid = PQgetvalue(res, i, 0);
1502  nspname = PQgetvalue(res, i, 1);
1503  relname = PQgetvalue(res, i, 2);
1504 
1505  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1506  {
1507  PQclear(res);
1508  return false;
1509  }
1510  if (cancel_pressed)
1511  {
1512  PQclear(res);
1513  return false;
1514  }
1515  }
1516 
1517  PQclear(res);
1518  return true;
1519 }
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1529
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 217 of file describe.c.

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

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 619 of file describe.c.

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

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 917 of file describe.c.

918 {
919  PGresult *res;
921  printQueryOpt myopt = pset.popt;
922 
924 
926  "SELECT\n"
927  " d.datname as \"%s\",\n"
928  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
929  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
930  gettext_noop("Name"),
931  gettext_noop("Owner"),
932  gettext_noop("Encoding"));
933  if (pset.sversion >= 150000)
935  " CASE d.datlocprovider WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
936  gettext_noop("Locale Provider"));
937  else
939  " 'libc' AS \"%s\",\n",
940  gettext_noop("Locale Provider"));
942  " d.datcollate as \"%s\",\n"
943  " d.datctype as \"%s\",\n",
944  gettext_noop("Collate"),
945  gettext_noop("Ctype"));
946  if (pset.sversion >= 150000)
948  " d.daticulocale as \"%s\",\n",
949  gettext_noop("ICU Locale"));
950  else
952  " NULL as \"%s\",\n",
953  gettext_noop("ICU Locale"));
954  if (pset.sversion >= 160000)
956  " d.daticurules as \"%s\",\n",
957  gettext_noop("ICU Rules"));
958  else
960  " NULL as \"%s\",\n",
961  gettext_noop("ICU Rules"));
962  appendPQExpBufferStr(&buf, " ");
963  printACLColumn(&buf, "d.datacl");
964  if (verbose)
966  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
967  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
968  " ELSE 'No Access'\n"
969  " END as \"%s\""
970  ",\n t.spcname as \"%s\""
971  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
972  gettext_noop("Size"),
973  gettext_noop("Tablespace"),
974  gettext_noop("Description"));
976  "\nFROM pg_catalog.pg_database d\n");
977  if (verbose)
979  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
980 
981  if (pattern)
982  {
983  if (!validateSQLNamePattern(&buf, pattern, false, false,
984  NULL, "d.datname", NULL, NULL,
985  NULL, 1))
986  {
988  return false;
989  }
990  }
991 
992  appendPQExpBufferStr(&buf, "ORDER BY 1;");
993  res = PSQLexec(buf.data);
995  if (!res)
996  return false;
997 
998  myopt.nullPrint = NULL;
999  myopt.title = _("List of databases");
1000  myopt.translate_header = true;
1001 
1002  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1003 
1004  PQclear(res);
1005  return true;
1006 }

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 4742 of file describe.c.

4743 {
4745  PGresult *res;
4746  printQueryOpt myopt = pset.popt;
4747  static const bool translate_columns[] = {false, false, false, true, false};
4748 
4749  initPQExpBuffer(&buf);
4750 
4752  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4753  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4754  gettext_noop("Source type"),
4755  gettext_noop("Target type"));
4756 
4757  /*
4758  * We don't attempt to localize '(binary coercible)' or '(with inout)',
4759  * because there's too much risk of gettext translating a function name
4760  * that happens to match some string in the PO database.
4761  */
4763  " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4764  " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4765  " ELSE p.proname\n"
4766  " END AS \"%s\",\n",
4767  COERCION_METHOD_BINARY,
4768  COERCION_METHOD_INOUT,
4769  gettext_noop("Function"));
4770 
4772  " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4773  " WHEN c.castcontext = '%c' THEN '%s'\n"
4774  " ELSE '%s'\n"
4775  " END AS \"%s\"",
4776  COERCION_CODE_EXPLICIT,
4777  gettext_noop("no"),
4778  COERCION_CODE_ASSIGNMENT,
4779  gettext_noop("in assignment"),
4780  gettext_noop("yes"),
4781  gettext_noop("Implicit?"));
4782 
4783  if (verbose)
4785  ",\n d.description AS \"%s\"",
4786  gettext_noop("Description"));
4787 
4788  /*
4789  * We need a left join to pg_proc for binary casts; the others are just
4790  * paranoia.
4791  */
4793  "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4794  " ON c.castfunc = p.oid\n"
4795  " LEFT JOIN pg_catalog.pg_type ts\n"
4796  " ON c.castsource = ts.oid\n"
4797  " LEFT JOIN pg_catalog.pg_namespace ns\n"
4798  " ON ns.oid = ts.typnamespace\n"
4799  " LEFT JOIN pg_catalog.pg_type tt\n"
4800  " ON c.casttarget = tt.oid\n"
4801  " LEFT JOIN pg_catalog.pg_namespace nt\n"
4802  " ON nt.oid = tt.typnamespace\n");
4803 
4804  if (verbose)
4806  " LEFT JOIN pg_catalog.pg_description d\n"
4807  " ON d.classoid = c.tableoid AND d.objoid = "
4808  "c.oid AND d.objsubid = 0\n");
4809 
4810  appendPQExpBufferStr(&buf, "WHERE ( (true");
4811 
4812  /*
4813  * Match name pattern against either internal or external name of either
4814  * castsource or casttarget
4815  */
4816  if (!validateSQLNamePattern(&buf, pattern, true, false,
4817  "ns.nspname", "ts.typname",
4818  "pg_catalog.format_type(ts.oid, NULL)",
4819  "pg_catalog.pg_type_is_visible(ts.oid)",
4820  NULL, 3))
4821  goto error_return;
4822 
4823  appendPQExpBufferStr(&buf, ") OR (true");
4824 
4825  if (!validateSQLNamePattern(&buf, pattern, true, false,
4826  "nt.nspname", "tt.typname",
4827  "pg_catalog.format_type(tt.oid, NULL)",
4828  "pg_catalog.pg_type_is_visible(tt.oid)",
4829  NULL, 3))
4830  goto error_return;
4831 
4832  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
4833 
4834  res = PSQLexec(buf.data);
4835  termPQExpBuffer(&buf);
4836  if (!res)
4837  return false;
4838 
4839  myopt.nullPrint = NULL;
4840  myopt.title = _("List of casts");
4841  myopt.translate_header = true;
4842  myopt.translate_columns = translate_columns;
4843  myopt.n_translate_columns = lengthof(translate_columns);
4844 
4845  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4846 
4847  PQclear(res);
4848  return true;
4849 
4850 error_return:
4851  termPQExpBuffer(&buf);
4852  return false;
4853 }

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 4861 of file describe.c.

4862 {
4864  PGresult *res;
4865  printQueryOpt myopt = pset.popt;
4866  static const bool translate_columns[] = {false, false, false, false, false, false, false, true, false};
4867 
4868  initPQExpBuffer(&buf);
4869 
4871  "SELECT\n"
4872  " n.nspname AS \"%s\",\n"
4873  " c.collname AS \"%s\",\n",
4874  gettext_noop("Schema"),
4875  gettext_noop("Name"));
4876 
4877  if (pset.sversion >= 100000)
4879  " CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
4880  gettext_noop("Provider"));
4881  else
4883  " 'libc' AS \"%s\",\n",
4884  gettext_noop("Provider"));
4885 
4887  " c.collcollate AS \"%s\",\n"
4888  " c.collctype AS \"%s\",\n",
4889  gettext_noop("Collate"),
4890  gettext_noop("Ctype"));
4891 
4892  if (pset.sversion >= 150000)
4894  " c.colliculocale AS \"%s\",\n",
4895  gettext_noop("ICU Locale"));
4896  else
4898  " c.collcollate AS \"%s\",\n",
4899  gettext_noop("ICU Locale"));
4900 
4901  if (pset.sversion >= 160000)
4903  " c.collicurules AS \"%s\",\n",
4904  gettext_noop("ICU Rules"));
4905  else
4907  " NULL AS \"%s\",\n",
4908  gettext_noop("ICU Rules"));
4909 
4910  if (pset.sversion >= 120000)
4912  " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4913  gettext_noop("yes"), gettext_noop("no"),
4914  gettext_noop("Deterministic?"));
4915  else
4917  " '%s' AS \"%s\"",
4918  gettext_noop("yes"),
4919  gettext_noop("Deterministic?"));
4920 
4921  if (verbose)
4923  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4924  gettext_noop("Description"));
4925 
4927  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4928  "WHERE n.oid = c.collnamespace\n");
4929 
4930  if (!showSystem && !pattern)
4931  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4932  " AND n.nspname <> 'information_schema'\n");
4933 
4934  /*
4935  * Hide collations that aren't usable in the current database's encoding.
4936  * If you think to change this, note that pg_collation_is_visible rejects
4937  * unusable collations, so you will need to hack name pattern processing
4938  * somehow to avoid inconsistent behavior.
4939  */
4940  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4941 
4942  if (!validateSQLNamePattern(&buf, pattern, true, false,
4943  "n.nspname", "c.collname", NULL,
4944  "pg_catalog.pg_collation_is_visible(c.oid)",
4945  NULL, 3))
4946  {
4947  termPQExpBuffer(&buf);
4948  return false;
4949  }
4950 
4951  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4952 
4953  res = PSQLexec(buf.data);
4954  termPQExpBuffer(&buf);
4955  if (!res)
4956  return false;
4957 
4958  myopt.nullPrint = NULL;
4959  myopt.title = _("List of collations");
4960  myopt.translate_header = true;
4961  myopt.translate_columns = translate_columns;
4962  myopt.n_translate_columns = lengthof(translate_columns);
4963 
4964  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4965 
4966  PQclear(res);
4967  return true;
4968 }

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 4414 of file describe.c.

4415 {
4417  PGresult *res;
4418  printQueryOpt myopt = pset.popt;
4419  static const bool translate_columns[] =
4420  {false, false, false, false, true, false};
4421 
4422  initPQExpBuffer(&buf);
4423 
4425  "SELECT n.nspname AS \"%s\",\n"
4426  " c.conname AS \"%s\",\n"
4427  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4428  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4429  " CASE WHEN c.condefault THEN '%s'\n"
4430  " ELSE '%s' END AS \"%s\"",
4431  gettext_noop("Schema"),
4432  gettext_noop("Name"),
4433  gettext_noop("Source"),
4434  gettext_noop("Destination"),
4435  gettext_noop("yes"), gettext_noop("no"),
4436  gettext_noop("Default?"));
4437 
4438  if (verbose)
4440  ",\n d.description AS \"%s\"",
4441  gettext_noop("Description"));
4442 
4444  "\nFROM pg_catalog.pg_conversion c\n"
4445  " JOIN pg_catalog.pg_namespace n "
4446  "ON n.oid = c.connamespace\n");
4447 
4448  if (verbose)
4450  "LEFT JOIN pg_catalog.pg_description d "
4451  "ON d.classoid = c.tableoid\n"
4452  " AND d.objoid = c.oid "
4453  "AND d.objsubid = 0\n");
4454 
4455  appendPQExpBufferStr(&buf, "WHERE true\n");
4456 
4457  if (!showSystem && !pattern)
4458  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4459  " AND n.nspname <> 'information_schema'\n");
4460 
4461  if (!validateSQLNamePattern(&buf, pattern, true, false,
4462  "n.nspname", "c.conname", NULL,
4463  "pg_catalog.pg_conversion_is_visible(c.oid)",
4464  NULL, 3))
4465  {
4466  termPQExpBuffer(&buf);
4467  return false;
4468  }
4469 
4470  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4471 
4472  res = PSQLexec(buf.data);
4473  termPQExpBuffer(&buf);
4474  if (!res)
4475  return false;
4476 
4477  myopt.nullPrint = NULL;
4478  myopt.title = _("List of conversions");
4479  myopt.translate_header = true;
4480  myopt.translate_columns = translate_columns;
4481  myopt.n_translate_columns = lengthof(translate_columns);
4482 
4483  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4484 
4485  PQclear(res);
4486  return true;
4487 }

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 3769 of file describe.c.

3770 {
3772  PGresult *res;
3773  printQueryOpt myopt = pset.popt;
3774  bool havewhere;
3775 
3776  initPQExpBuffer(&buf);
3777 
3778  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3779  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"",
3780  gettext_noop("Role"),
3781  gettext_noop("Database"),
3782  gettext_noop("Settings"));
3783  if (pset.sversion >= 160000)
3784  appendPQExpBuffer(&buf, ",\npg_catalog.array_to_string(setuser, E'\\n') AS \"%s\"",
3785  gettext_noop("User set"));
3786  appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_db_role_setting s\n"
3787  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3788  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n");
3789  if (!validateSQLNamePattern(&buf, pattern, false, false,
3790  NULL, "r.rolname", NULL, NULL, &havewhere, 1))
3791  goto error_return;
3792  if (!validateSQLNamePattern(&buf, pattern2, havewhere, false,
3793  NULL, "d.datname", NULL, NULL,
3794  NULL, 1))
3795  goto error_return;
3796  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3797 
3798  res = PSQLexec(buf.data);
3799  termPQExpBuffer(&buf);
3800  if (!res)
3801  return false;
3802 
3803  /*
3804  * Most functions in this file are content to print an empty table when
3805  * there are no matching objects. We intentionally deviate from that
3806  * here, but only in !quiet mode, because of the possibility that the user
3807  * is confused about what the two pattern arguments mean.
3808  */
3809  if (PQntuples(res) == 0 && !pset.quiet)
3810  {
3811  if (pattern && pattern2)
3812  pg_log_error("Did not find any settings for role \"%s\" and database \"%s\".",
3813  pattern, pattern2);
3814  else if (pattern)
3815  pg_log_error("Did not find any settings for role \"%s\".",
3816  pattern);
3817  else
3818  pg_log_error("Did not find any settings.");
3819  }
3820  else
3821  {
3822  myopt.nullPrint = NULL;
3823  myopt.title = _("List of settings");
3824  myopt.translate_header = true;
3825 
3826  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3827  }
3828 
3829  PQclear(res);
3830  return true;
3831 
3832 error_return:
3833  termPQExpBuffer(&buf);
3834  return false;
3835 }

References _, appendPQExpBuffer(), 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, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1174 of file describe.c.

1175 {
1177  PGresult *res;
1178  printQueryOpt myopt = pset.popt;
1179  static const bool translate_columns[] = {false, false, true, false};
1180 
1181  initPQExpBuffer(&buf);
1182 
1184  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1185  " n.nspname AS \"%s\",\n"
1186  " 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"
1187  " ",
1188  gettext_noop("Owner"),
1189  gettext_noop("Schema"),
1190  DEFACLOBJ_RELATION,
1191  gettext_noop("table"),
1192  DEFACLOBJ_SEQUENCE,
1193  gettext_noop("sequence"),
1194  DEFACLOBJ_FUNCTION,
1195  gettext_noop("function"),
1196  DEFACLOBJ_TYPE,
1197  gettext_noop("type"),
1198  DEFACLOBJ_NAMESPACE,
1199  gettext_noop("schema"),
1200  gettext_noop("Type"));
1201 
1202  printACLColumn(&buf, "d.defaclacl");
1203 
1204  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1205  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1206 
1207  if (!validateSQLNamePattern(&buf, pattern, false, false,
1208  NULL,
1209  "n.nspname",
1210  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1211  NULL,
1212  NULL, 3))
1213  goto error_return;
1214 
1215  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1216 
1217  res = PSQLexec(buf.data);
1218  if (!res)
1219  goto error_return;
1220 
1221  myopt.nullPrint = NULL;
1222  printfPQExpBuffer(&buf, _("Default access privileges"));
1223  myopt.title = buf.data;
1224  myopt.translate_header = true;
1225  myopt.translate_columns = translate_columns;
1226  myopt.n_translate_columns = lengthof(translate_columns);
1227 
1228  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1229 
1230  termPQExpBuffer(&buf);
1231  PQclear(res);
1232  return true;
1233 
1234 error_return:
1235  termPQExpBuffer(&buf);
1236  return false;
1237 }

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 4330 of file describe.c.

4331 {
4333  PGresult *res;
4334  printQueryOpt myopt = pset.popt;
4335 
4336  initPQExpBuffer(&buf);
4337 
4339  "SELECT n.nspname as \"%s\",\n"
4340  " t.typname as \"%s\",\n"
4341  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4342  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4343  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4344  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4345  " t.typdefault as \"%s\",\n"
4346  " pg_catalog.array_to_string(ARRAY(\n"
4347  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4348  " ), ' ') as \"%s\"",
4349  gettext_noop("Schema"),
4350  gettext_noop("Name"),
4351  gettext_noop("Type"),
4352  gettext_noop("Collation"),
4353  gettext_noop("Nullable"),
4354  gettext_noop("Default"),
4355  gettext_noop("Check"));
4356 
4357  if (verbose)
4358  {
4359  appendPQExpBufferStr(&buf, ",\n ");
4360  printACLColumn(&buf, "t.typacl");
4362  ",\n d.description as \"%s\"",
4363  gettext_noop("Description"));
4364  }
4365 
4367  "\nFROM pg_catalog.pg_type t\n"
4368  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4369 
4370  if (verbose)
4372  " LEFT JOIN pg_catalog.pg_description d "
4373  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4374  "AND d.objsubid = 0\n");
4375 
4376  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
4377 
4378  if (!showSystem && !pattern)
4379  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4380  " AND n.nspname <> 'information_schema'\n");
4381 
4382  if (!validateSQLNamePattern(&buf, pattern, true, false,
4383  "n.nspname", "t.typname", NULL,
4384  "pg_catalog.pg_type_is_visible(t.oid)",
4385  NULL, 3))
4386  {
4387  termPQExpBuffer(&buf);
4388  return false;
4389  }
4390 
4391  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4392 
4393  res = PSQLexec(buf.data);
4394  termPQExpBuffer(&buf);
4395  if (!res)
4396  return false;
4397 
4398  myopt.nullPrint = NULL;
4399  myopt.title = _("List of domains");
4400  myopt.translate_header = true;
4401 
4402  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4403 
4404  PQclear(res);
4405  return true;
4406 }

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 4564 of file describe.c.

4565 {
4567  PGresult *res;
4568  printQueryOpt myopt = pset.popt;
4569  static const bool translate_columns[] =
4570  {false, false, false, true, false, false, false};
4571 
4572  if (pset.sversion < 90300)
4573  {
4574  char sverbuf[32];
4575 
4576  pg_log_error("The server (version %s) does not support event triggers.",
4578  sverbuf, sizeof(sverbuf)));
4579  return true;
4580  }
4581 
4582  initPQExpBuffer(&buf);
4583 
4585  "SELECT evtname as \"%s\", "
4586  "evtevent as \"%s\", "
4587  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4588  " case evtenabled when 'O' then '%s'"
4589  " when 'R' then '%s'"
4590  " when 'A' then '%s'"
4591  " when 'D' then '%s' end as \"%s\",\n"
4592  " e.evtfoid::pg_catalog.regproc as \"%s\", "
4593  "pg_catalog.array_to_string(array(select x"
4594  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4595  gettext_noop("Name"),
4596  gettext_noop("Event"),
4597  gettext_noop("Owner"),
4598  gettext_noop("enabled"),
4599  gettext_noop("replica"),
4600  gettext_noop("always"),
4601  gettext_noop("disabled"),
4602  gettext_noop("Enabled"),
4603  gettext_noop("Function"),
4604  gettext_noop("Tags"));
4605  if (verbose)
4607  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4608  gettext_noop("Description"));
4610  "\nFROM pg_catalog.pg_event_trigger e ");
4611 
4612  if (!validateSQLNamePattern(&buf, pattern, false, false,
4613  NULL, "evtname", NULL, NULL,
4614  NULL, 1))
4615  {
4616  termPQExpBuffer(&buf);
4617  return false;
4618  }
4619 
4620  appendPQExpBufferStr(&buf, "ORDER BY 1");
4621 
4622  res = PSQLexec(buf.data);
4623  termPQExpBuffer(&buf);
4624  if (!res)
4625  return false;
4626 
4627  myopt.nullPrint = NULL;
4628  myopt.title = _("List of event triggers");
4629  myopt.translate_header = true;
4630  myopt.translate_columns = translate_columns;
4631  myopt.n_translate_columns = lengthof(translate_columns);
4632 
4633  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4634 
4635  PQclear(res);
4636  return true;
4637 }

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 4645 of file describe.c.

4646 {
4648  PGresult *res;
4649  printQueryOpt myopt = pset.popt;
4650 
4651  if (pset.sversion < 100000)
4652  {
4653  char sverbuf[32];
4654 
4655  pg_log_error("The server (version %s) does not support extended statistics.",
4657  sverbuf, sizeof(sverbuf)));
4658  return true;
4659  }
4660 
4661  initPQExpBuffer(&buf);
4663  "SELECT \n"
4664  "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4665  "es.stxname AS \"%s\", \n",
4666  gettext_noop("Schema"),
4667  gettext_noop("Name"));
4668 
4669  if (pset.sversion >= 140000)
4671  "pg_catalog.format('%%s FROM %%s', \n"
4672  " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4673  " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4674  gettext_noop("Definition"));
4675  else
4677  "pg_catalog.format('%%s FROM %%s', \n"
4678  " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4679  " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4680  " JOIN pg_catalog.pg_attribute a \n"
4681  " ON (es.stxrelid = a.attrelid \n"
4682  " AND a.attnum = s.attnum \n"
4683  " AND NOT a.attisdropped)), \n"
4684  "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4685  gettext_noop("Definition"));
4686 
4688  ",\nCASE WHEN 'd' = any(es.stxkind) THEN 'defined' \n"
4689  "END AS \"%s\", \n"
4690  "CASE WHEN 'f' = any(es.stxkind) THEN 'defined' \n"
4691  "END AS \"%s\"",
4692  gettext_noop("Ndistinct"),
4693  gettext_noop("Dependencies"));
4694 
4695  /*
4696  * Include the MCV statistics kind.
4697  */
4698  if (pset.sversion >= 120000)
4699  {
4701  ",\nCASE WHEN 'm' = any(es.stxkind) THEN 'defined' \n"
4702  "END AS \"%s\" ",
4703  gettext_noop("MCV"));
4704  }
4705 
4707  " \nFROM pg_catalog.pg_statistic_ext es \n");
4708 
4709  if (!validateSQLNamePattern(&buf, pattern,
4710  false, false,
4711  "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text", "es.stxname",
4712  NULL, "pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4713  NULL, 3))
4714  {
4715  termPQExpBuffer(&buf);
4716  return false;
4717  }
4718 
4719  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4720 
4721  res = PSQLexec(buf.data);
4722  termPQExpBuffer(&buf);
4723  if (!res)
4724  return false;
4725 
4726  myopt.nullPrint = NULL;
4727  myopt.title = _("List of extended statistics");
4728  myopt.translate_header = true;
4729 
4730  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4731 
4732  PQclear(res);
4733  return true;
4734 }

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 6016 of file describe.c.

6017 {
6019  PGresult *res;
6020  int i;
6021 
6022  initPQExpBuffer(&buf);
6024  "SELECT e.extname, e.oid\n"
6025  "FROM pg_catalog.pg_extension e\n");
6026 
6027  if (!validateSQLNamePattern(&buf, pattern,
6028  false, false,
6029  NULL, "e.extname", NULL,
6030  NULL,
6031  NULL, 1))
6032  {
6033  termPQExpBuffer(&buf);
6034  return false;
6035  }
6036 
6037  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6038 
6039  res = PSQLexec(buf.data);
6040  termPQExpBuffer(&buf);
6041  if (!res)
6042  return false;
6043 
6044  if (PQntuples(res) == 0)
6045  {
6046  if (!pset.quiet)
6047  {
6048  if (pattern)
6049  pg_log_error("Did not find any extension named \"%s\".",
6050  pattern);
6051  else
6052  pg_log_error("Did not find any extensions.");
6053  }
6054  PQclear(res);
6055  return false;
6056  }
6057 
6058  for (i = 0; i < PQntuples(res); i++)
6059  {
6060  const char *extname;
6061  const char *oid;
6062 
6063  extname = PQgetvalue(res, i, 0);
6064  oid = PQgetvalue(res, i, 1);
6065 
6066  if (!listOneExtensionContents(extname, oid))
6067  {
6068  PQclear(res);
6069  return false;
6070  }
6071  if (cancel_pressed)
6072  {
6073  PQclear(res);
6074  return false;
6075  }
6076  }
6077 
6078  PQclear(res);
6079  return true;
6080 }
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:6083

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 5964 of file describe.c.

5965 {
5967  PGresult *res;
5968  printQueryOpt myopt = pset.popt;
5969 
5970  initPQExpBuffer(&buf);
5972  "SELECT e.extname AS \"%s\", "
5973  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
5974  "FROM pg_catalog.pg_extension e "
5975  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
5976  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
5977  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
5978  gettext_noop("Name"),
5979  gettext_noop("Version"),
5980  gettext_noop("Schema"),
5981  gettext_noop("Description"));
5982 
5983  if (!validateSQLNamePattern(&buf, pattern,
5984  false, false,
5985  NULL, "e.extname", NULL,
5986  NULL,
5987  NULL, 1))
5988  {
5989  termPQExpBuffer(&buf);
5990  return false;
5991  }
5992 
5993  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5994 
5995  res = PSQLexec(buf.data);
5996  termPQExpBuffer(&buf);
5997  if (!res)
5998  return false;
5999 
6000  myopt.nullPrint = NULL;
6001  myopt.title = _("List of installed extensions");
6002  myopt.translate_header = true;
6003 
6004  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6005 
6006  PQclear(res);
6007  return true;
6008 }

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 5686 of file describe.c.

5687 {
5689  PGresult *res;
5690  printQueryOpt myopt = pset.popt;
5691 
5692  initPQExpBuffer(&buf);
5694  "SELECT fdw.fdwname AS \"%s\",\n"
5695  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5696  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5697  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5698  gettext_noop("Name"),
5699  gettext_noop("Owner"),
5700  gettext_noop("Handler"),
5701  gettext_noop("Validator"));
5702 
5703  if (verbose)
5704  {
5705  appendPQExpBufferStr(&buf, ",\n ");
5706  printACLColumn(&buf, "fdwacl");
5708  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5709  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5710  " pg_catalog.quote_ident(option_name) || ' ' || "
5711  " pg_catalog.quote_literal(option_value) FROM "
5712  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5713  " END AS \"%s\""
5714  ",\n d.description AS \"%s\" ",
5715  gettext_noop("FDW options"),
5716  gettext_noop("Description"));
5717  }
5718 
5719  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
5720 
5721  if (verbose)
5723  "LEFT JOIN pg_catalog.pg_description d\n"
5724  " ON d.classoid = fdw.tableoid "
5725  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5726 
5727  if (!validateSQLNamePattern(&buf, pattern, false, false,
5728  NULL, "fdwname", NULL, NULL,
5729  NULL, 1))
5730  {
5731  termPQExpBuffer(&buf);
5732  return false;
5733  }
5734 
5735  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5736 
5737  res = PSQLexec(buf.data);
5738  termPQExpBuffer(&buf);
5739  if (!res)
5740  return false;
5741 
5742  myopt.nullPrint = NULL;
5743  myopt.title = _("List of foreign-data wrappers");
5744  myopt.translate_header = true;
5745 
5746  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5747 
5748  PQclear(res);
5749  return true;
5750 }

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 5758 of file describe.c.

5759 {
5761  PGresult *res;
5762  printQueryOpt myopt = pset.popt;
5763 
5764  initPQExpBuffer(&buf);
5766  "SELECT s.srvname AS \"%s\",\n"
5767  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5768  " f.fdwname AS \"%s\"",
5769  gettext_noop("Name"),
5770  gettext_noop("Owner"),
5771  gettext_noop("Foreign-data wrapper"));
5772 
5773  if (verbose)
5774  {
5775  appendPQExpBufferStr(&buf, ",\n ");
5776  printACLColumn(&buf, "s.srvacl");
5778  ",\n"
5779  " s.srvtype AS \"%s\",\n"
5780  " s.srvversion AS \"%s\",\n"
5781  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5782  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5783  " pg_catalog.quote_ident(option_name) || ' ' || "
5784  " pg_catalog.quote_literal(option_value) FROM "
5785  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
5786  " END AS \"%s\",\n"
5787  " d.description AS \"%s\"",
5788  gettext_noop("Type"),
5789  gettext_noop("Version"),
5790  gettext_noop("FDW options"),
5791  gettext_noop("Description"));
5792  }
5793 
5795  "\nFROM pg_catalog.pg_foreign_server s\n"
5796  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
5797 
5798  if (verbose)
5800  "LEFT JOIN pg_catalog.pg_description d\n "
5801  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
5802  "AND d.objsubid = 0\n");
5803 
5804  if (!validateSQLNamePattern(&buf, pattern, false, false,
5805  NULL, "s.srvname", NULL, NULL,
5806  NULL, 1))
5807  {
5808  termPQExpBuffer(&buf);
5809  return false;
5810  }
5811 
5812  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5813 
5814  res = PSQLexec(buf.data);
5815  termPQExpBuffer(&buf);
5816  if (!res)
5817  return false;
5818 
5819  myopt.nullPrint = NULL;
5820  myopt.title = _("List of foreign servers");
5821  myopt.translate_header = true;
5822 
5823  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5824 
5825  PQclear(res);
5826  return true;
5827 }

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 5891 of file describe.c.

5892 {
5894  PGresult *res;
5895  printQueryOpt myopt = pset.popt;
5896 
5897  initPQExpBuffer(&buf);
5899  "SELECT n.nspname AS \"%s\",\n"
5900  " c.relname AS \"%s\",\n"
5901  " s.srvname AS \"%s\"",
5902  gettext_noop("Schema"),
5903  gettext_noop("Table"),
5904  gettext_noop("Server"));
5905 
5906  if (verbose)
5908  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
5909  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5910  " pg_catalog.quote_ident(option_name) || ' ' || "
5911  " pg_catalog.quote_literal(option_value) FROM "
5912  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
5913  " END AS \"%s\",\n"
5914  " d.description AS \"%s\"",
5915  gettext_noop("FDW options"),
5916  gettext_noop("Description"));
5917 
5919  "\nFROM pg_catalog.pg_foreign_table ft\n"
5920  " INNER JOIN pg_catalog.pg_class c"
5921  " ON c.oid = ft.ftrelid\n"
5922  " INNER JOIN pg_catalog.pg_namespace n"
5923  " ON n.oid = c.relnamespace\n"
5924  " INNER JOIN pg_catalog.pg_foreign_server s"
5925  " ON s.oid = ft.ftserver\n");
5926  if (verbose)
5928  " LEFT JOIN pg_catalog.pg_description d\n"
5929  " ON d.classoid = c.tableoid AND "
5930  "d.objoid = c.oid AND d.objsubid = 0\n");
5931 
5932  if (!validateSQLNamePattern(&buf, pattern, false, false,
5933  "n.nspname", "c.relname", NULL,
5934  "pg_catalog.pg_table_is_visible(c.oid)",
5935  NULL, 3))
5936  {
5937  termPQExpBuffer(&buf);
5938  return false;
5939  }
5940 
5941  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5942 
5943  res = PSQLexec(buf.data);
5944  termPQExpBuffer(&buf);
5945  if (!res)
5946  return false;
5947 
5948  myopt.nullPrint = NULL;
5949  myopt.title = _("List of foreign tables");
5950  myopt.translate_header = true;
5951 
5952  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5953 
5954  PQclear(res);
5955  return true;
5956 }

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 4253 of file describe.c.

4254 {
4256  PGresult *res;
4257  printQueryOpt myopt = pset.popt;
4258 
4259  initPQExpBuffer(&buf);
4260 
4262  "SELECT l.lanname AS \"%s\",\n"
4263  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4264  " l.lanpltrusted AS \"%s\"",
4265  gettext_noop("Name"),
4266  gettext_noop("Owner"),
4267  gettext_noop("Trusted"));
4268 
4269  if (verbose)
4270  {
4272  ",\n NOT l.lanispl AS \"%s\",\n"
4273  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4274  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4275  "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4276  gettext_noop("Internal language"),
4277  gettext_noop("Call handler"),
4278  gettext_noop("Validator"),
4279  gettext_noop("Inline handler"));
4280  printACLColumn(&buf, "l.lanacl");
4281  }
4282 
4284  ",\n d.description AS \"%s\""
4285  "\nFROM pg_catalog.pg_language l\n"
4286  "LEFT JOIN pg_catalog.pg_description d\n"
4287  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4288  " AND d.objsubid = 0\n",
4289  gettext_noop("Description"));
4290 
4291  if (pattern)
4292  {
4293  if (!validateSQLNamePattern(&buf, pattern, false, false,
4294  NULL, "l.lanname", NULL, NULL,
4295  NULL, 2))
4296  {
4297  termPQExpBuffer(&buf);
4298  return false;
4299  }
4300  }
4301 
4302  if (!showSystem && !pattern)
4303  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
4304 
4305 
4306  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4307 
4308  res = PSQLexec(buf.data);
4309  termPQExpBuffer(&buf);
4310  if (!res)
4311  return false;
4312 
4313  myopt.nullPrint = NULL;
4314  myopt.title = _("List of languages");
4315  myopt.translate_header = true;
4316 
4317  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4318 
4319  PQclear(res);
4320  return true;
4321 }

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 7007 of file describe.c.

7008 {
7010  PGresult *res;
7011  printQueryOpt myopt = pset.popt;
7012 
7013  initPQExpBuffer(&buf);
7014 
7016  "SELECT oid as \"%s\",\n"
7017  " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
7018  gettext_noop("ID"),
7019  gettext_noop("Owner"));
7020 
7021  if (verbose)
7022  {
7023  printACLColumn(&buf, "lomacl");
7024  appendPQExpBufferStr(&buf, ",\n ");
7025  }
7026 
7028  "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
7029  "FROM pg_catalog.pg_largeobject_metadata\n"
7030  "ORDER BY oid",
7031  gettext_noop("Description"));
7032 
7033  res = PSQLexec(buf.data);
7034  termPQExpBuffer(&buf);
7035  if (!res)
7036  return false;
7037 
7038  myopt.nullPrint = NULL;
7039  myopt.title = _("Large objects");
7040  myopt.translate_header = true;
7041 
7042  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7043 
7044  PQclear(res);
7045  return true;
7046 }

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 *  type_pattern,
bool  verbose 
)

Definition at line 6626 of file describe.c.

6628 {
6630  PGresult *res;
6631  printQueryOpt myopt = pset.popt;
6632  bool have_where = false;
6633  static const bool translate_columns[] = {false, false, false, false, false, false, false};
6634 
6635  initPQExpBuffer(&buf);
6636 
6638  "SELECT\n"
6639  " am.amname AS \"%s\",\n"
6640  " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6641  " CASE\n"
6642  " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6643  " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6644  " ELSE NULL\n"
6645  " END AS \"%s\",\n"
6646  " CASE\n"
6647  " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6648  " THEN pg_catalog.format('%%I', c.opcname)\n"
6649  " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6650  " END AS \"%s\",\n"
6651  " (CASE WHEN c.opcdefault\n"
6652  " THEN '%s'\n"
6653  " ELSE '%s'\n"
6654  " END) AS \"%s\"",
6655  gettext_noop("AM"),
6656  gettext_noop("Input type"),
6657  gettext_noop("Storage type"),
6658  gettext_noop("Operator class"),
6659  gettext_noop("yes"),
6660  gettext_noop("no"),
6661  gettext_noop("Default?"));
6662  if (verbose)
6664  ",\n CASE\n"
6665  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6666  " THEN pg_catalog.format('%%I', of.opfname)\n"
6667  " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
6668  " END AS \"%s\",\n"
6669  " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6670  gettext_noop("Operator family"),
6671  gettext_noop("Owner"));
6673  "\nFROM pg_catalog.pg_opclass c\n"
6674  " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6675  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6676  " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6677  " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
6678  if (verbose)
6680  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6681  " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6682 
6683  if (access_method_pattern)
6684  if (!validateSQLNamePattern(&buf, access_method_pattern,
6685  false, false, NULL, "am.amname", NULL, NULL,
6686  &have_where, 1))
6687  goto error_return;
6688  if (type_pattern)
6689  {
6690  /* Match type name pattern against either internal or external name */
6691  if (!validateSQLNamePattern(&buf, type_pattern, have_where, false,
6692  "tn.nspname", "t.typname",
6693  "pg_catalog.format_type(t.oid, NULL)",
6694  "pg_catalog.pg_type_is_visible(t.oid)",
6695  NULL, 3))
6696  goto error_return;
6697  }
6698 
6699  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
6700  res = PSQLexec(buf.data);
6701  termPQExpBuffer(&buf);
6702  if (!res)
6703  return false;
6704 
6705  myopt.nullPrint = NULL;
6706  myopt.title = _("List of operator classes");
6707  myopt.translate_header = true;
6708  myopt.translate_columns = translate_columns;
6709  myopt.n_translate_columns = lengthof(translate_columns);
6710 
6711  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6712 
6713  PQclear(res);
6714  return true;
6715 
6716 error_return:
6717  termPQExpBuffer(&buf);
6718  return false;
6719 }

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 *  type_pattern,
bool  verbose 
)

Definition at line 6728 of file describe.c.

6730 {
6732  PGresult *res;
6733  printQueryOpt myopt = pset.popt;
6734  bool have_where = false;
6735  static const bool translate_columns[] = {false, false, false, false};
6736 
6737  initPQExpBuffer(&buf);
6738 
6740  "SELECT\n"
6741  " am.amname AS \"%s\",\n"
6742  " CASE\n"
6743  " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
6744  " THEN pg_catalog.format('%%I', f.opfname)\n"
6745  " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
6746  " END AS \"%s\",\n"
6747  " (SELECT\n"
6748  " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
6749  " FROM pg_catalog.pg_opclass oc\n"
6750  " WHERE oc.opcfamily = f.oid) \"%s\"",
6751  gettext_noop("AM"),
6752  gettext_noop("Operator family"),
6753  gettext_noop("Applicable types"));
6754  if (verbose)
6756  ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
6757  gettext_noop("Owner"));
6759  "\nFROM pg_catalog.pg_opfamily f\n"
6760  " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
6761  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
6762 
6763  if (access_method_pattern)
6764  if (!validateSQLNamePattern(&buf, access_method_pattern,
6765  false, false, NULL, "am.amname", NULL, NULL,
6766  &have_where, 1))
6767  goto error_return;
6768  if (type_pattern)
6769  {
6771  " %s EXISTS (\n"
6772  " SELECT 1\n"
6773  " FROM pg_catalog.pg_type t\n"
6774  " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
6775  " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
6776  " WHERE oc.opcfamily = f.oid\n",
6777  have_where ? "AND" : "WHERE");
6778  /* Match type name pattern against either internal or external name */
6779  if (!validateSQLNamePattern(&buf, type_pattern, true, false,
6780  "tn.nspname", "t.typname",
6781  "pg_catalog.format_type(t.oid, NULL)",
6782  "pg_catalog.pg_type_is_visible(t.oid)",
6783  NULL, 3))
6784  goto error_return;
6785  appendPQExpBufferStr(&buf, " )\n");
6786  }
6787 
6788  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6789  res = PSQLexec(buf.data);
6790  termPQExpBuffer(&buf);
6791  if (!res)
6792  return false;
6793 
6794  myopt.nullPrint = NULL;
6795  myopt.title = _("List of operator families");
6796  myopt.translate_header = true;
6797  myopt.translate_columns = translate_columns;
6798  myopt.n_translate_columns = lengthof(translate_columns);
6799 
6800  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6801 
6802  PQclear(res);
6803  return true;
6804 
6805 error_return:
6806  termPQExpBuffer(&buf);
6807  return false;
6808 }

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 6917 of file describe.c.

6919 {
6921  PGresult *res;
6922  printQueryOpt myopt = pset.popt;
6923  bool have_where = false;
6924  static const bool translate_columns[] = {false, false, false, false, false, false};
6925 
6926  initPQExpBuffer(&buf);
6927 
6929  "SELECT\n"
6930  " am.amname AS \"%s\",\n"
6931  " CASE\n"
6932  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6933  " THEN pg_catalog.format('%%I', of.opfname)\n"
6934  " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
6935  " END AS \"%s\",\n"
6936  " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
6937  " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
6938  " ap.amprocnum AS \"%s\"\n",
6939  gettext_noop("AM"),
6940  gettext_noop("Operator family"),
6941  gettext_noop("Registered left type"),
6942  gettext_noop("Registered right type"),
6943  gettext_noop("Number"));
6944 
6945  if (!verbose)
6947  ", p.proname AS \"%s\"\n",
6948  gettext_noop("Function"));
6949  else
6951  ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
6952  gettext_noop("Function"));
6953 
6955  "FROM pg_catalog.pg_amproc ap\n"
6956  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
6957  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
6958  " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
6959  " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
6960 
6961  if (access_method_pattern)
6962  {
6963  if (!validateSQLNamePattern(&buf, access_method_pattern,
6964  false, false, NULL, "am.amname",
6965  NULL, NULL,
6966  &have_where, 1))
6967  goto error_return;
6968  }
6969  if (family_pattern)
6970  {
6971  if (!validateSQLNamePattern(&buf, family_pattern, have_where, false,
6972  "ns.nspname", "of.opfname", NULL, NULL,
6973  NULL, 3))
6974  goto error_return;
6975  }
6976 
6977  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6978  " ap.amproclefttype = ap.amprocrighttype DESC,\n"
6979  " 3, 4, 5;");
6980 
6981  res = PSQLexec(buf.data);
6982  termPQExpBuffer(&buf);
6983  if (!res)
6984  return false;
6985 
6986  myopt.nullPrint = NULL;
6987  myopt.title = _("List of support functions of operator families");
6988  myopt.translate_header = true;
6989  myopt.translate_columns = translate_columns;
6990  myopt.n_translate_columns = lengthof(translate_columns);
6991 
6992  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6993 
6994  PQclear(res);
6995  return true;
6996 
6997 error_return:
6998  termPQExpBuffer(&buf);
6999  return false;
7000 }

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 *  access_method_pattern,
const char *  family_pattern,
bool  verbose 
)

Definition at line 6818 of file describe.c.

6820 {
6822  PGresult *res;
6823  printQueryOpt myopt = pset.popt;
6824  bool have_where = false;
6825 
6826  static const bool translate_columns[] = {false, false, false, false, false, false};
6827 
6828  initPQExpBuffer(&buf);
6829 
6831  "SELECT\n"
6832  " am.amname AS \"%s\",\n"
6833  " CASE\n"
6834  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6835  " THEN pg_catalog.format('%%I', of.opfname)\n"
6836  " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
6837  " END AS \"%s\",\n"
6838  " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
6839  " o.amopstrategy AS \"%s\",\n"
6840  " CASE o.amoppurpose\n"
6841  " WHEN 'o' THEN '%s'\n"
6842  " WHEN 's' THEN '%s'\n"
6843  " END AS \"%s\"\n",
6844  gettext_noop("AM"),
6845  gettext_noop("Operator family"),
6846  gettext_noop("Operator"),
6847  gettext_noop("Strategy"),
6848  gettext_noop("ordering"),
6849  gettext_noop("search"),
6850  gettext_noop("Purpose"));
6851 
6852  if (verbose)
6854  ", ofs.opfname AS \"%s\"\n",
6855  gettext_noop("Sort opfamily"));
6857  "FROM pg_catalog.pg_amop o\n"
6858  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
6859  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
6860  " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
6861  if (verbose)
6863  " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n");
6864 
6865  if (access_method_pattern)
6866  {
6867  if (!validateSQLNamePattern(&buf, access_method_pattern,
6868  false, false, NULL, "am.amname",
6869  NULL, NULL,
6870  &have_where, 1))
6871  goto error_return;
6872  }
6873 
6874  if (family_pattern)
6875  {
6876  if (!validateSQLNamePattern(&buf, family_pattern, have_where, false,
6877  "nsf.nspname", "of.opfname", NULL, NULL,
6878  NULL, 3))
6879  goto error_return;
6880  }
6881 
6882  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6883  " o.amoplefttype = o.amoprighttype DESC,\n"
6884  " pg_catalog.format_type(o.amoplefttype, NULL),\n"
6885  " pg_catalog.format_type(o.amoprighttype, NULL),\n"
6886  " o.amopstrategy;");
6887 
6888  res = PSQLexec(buf.data);
6889  termPQExpBuffer(&buf);
6890  if (!res)
6891  return false;
6892 
6893  myopt.nullPrint = NULL;
6894  myopt.title = _("List of operators of operator families");
6895  myopt.translate_header = true;
6896  myopt.translate_columns = translate_columns;
6897  myopt.n_translate_columns = lengthof(translate_columns);
6898 
6899  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6900 
6901  PQclear(res);
6902  return true;
6903 
6904 error_return:
6905  termPQExpBuffer(&buf);
6906  return false;
6907 }

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 4052 of file describe.c.

4053 {
4054  bool showTables = strchr(reltypes, 't') != NULL;
4055  bool showIndexes = strchr(reltypes, 'i') != NULL;
4056  bool showNested = strchr(reltypes, 'n') != NULL;
4058  PQExpBufferData title;
4059  PGresult *res;
4060  printQueryOpt myopt = pset.popt;
4061  bool translate_columns[] = {false, false, false, false, false, false, false, false, false};
4062  const char *tabletitle;
4063  bool mixed_output = false;
4064 
4065  /*
4066  * Note: Declarative table partitioning is only supported as of Pg 10.0.
4067  */
4068  if (pset.sversion < 100000)
4069  {
4070  char sverbuf[32];
4071 
4072  pg_log_error("The server (version %s) does not support declarative table partitioning.",
4074  sverbuf, sizeof(sverbuf)));
4075  return true;
4076  }
4077 
4078  /* If no relation kind was selected, show them all */
4079  if (!showTables && !showIndexes)
4080  showTables = showIndexes = true;
4081 
4082  if (showIndexes && !showTables)
4083  tabletitle = _("List of partitioned indexes"); /* \dPi */
4084  else if (showTables && !showIndexes)
4085  tabletitle = _("List of partitioned tables"); /* \dPt */
4086  else
4087  {
4088  /* show all kinds */
4089  tabletitle = _("List of partitioned relations");
4090  mixed_output = true;
4091  }
4092 
4093  initPQExpBuffer(&buf);
4094 
4096  "SELECT n.nspname as \"%s\",\n"
4097  " c.relname as \"%s\",\n"
4098  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4099  gettext_noop("Schema"),
4100  gettext_noop("Name"),
4101  gettext_noop("Owner"));
4102 
4103  if (mixed_output)
4104  {
4106  ",\n CASE c.relkind"
4107  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
4108  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
4109  " END as \"%s\"",
4110  gettext_noop("partitioned table"),
4111  gettext_noop("partitioned index"),
4112  gettext_noop("Type"));
4113 
4114  translate_columns[3] = true;
4115  }
4116 
4117  if (showNested || pattern)
4119  ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4120  gettext_noop("Parent name"));
4121 
4122  if (showIndexes)
4124  ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4125  gettext_noop("Table"));
4126 
4127  if (verbose)
4128  {
4129  if (showNested)
4130  {
4132  ",\n s.dps as \"%s\"",
4133  gettext_noop("Leaf partition size"));
4135  ",\n s.tps as \"%s\"",
4136  gettext_noop("Total size"));
4137  }
4138  else
4139  /* Sizes of all partitions are considered in this case. */
4141  ",\n s.tps as \"%s\"",
4142  gettext_noop("Total size"));
4143 
4145  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4146  gettext_noop("Description"));
4147  }
4148 
4150  "\nFROM pg_catalog.pg_class c"
4151  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4152 
4153  if (showIndexes)
4155  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4156  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4157 
4158  if (showNested || pattern)
4160  "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4161 
4162  if (verbose)
4163  {
4164  if (pset.sversion < 120000)
4165  {
4167  ",\n LATERAL (WITH RECURSIVE d\n"
4168  " AS (SELECT inhrelid AS oid, 1 AS level\n"
4169  " FROM pg_catalog.pg_inherits\n"
4170  " WHERE inhparent = c.oid\n"
4171  " UNION ALL\n"
4172  " SELECT inhrelid, level + 1\n"
4173  " FROM pg_catalog.pg_inherits i\n"
4174  " JOIN d ON i.inhparent = d.oid)\n"
4175  " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4176  "d.oid))) AS tps,\n"
4177  " pg_catalog.pg_size_pretty(sum("
4178  "\n CASE WHEN d.level = 1"
4179  " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4180  " FROM d) s");
4181  }
4182  else
4183  {
4184  /* PostgreSQL 12 has pg_partition_tree function */
4186  ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4187  "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4188  "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4189  " ELSE 0 END)) AS dps"
4190  ",\n pg_catalog.pg_size_pretty(sum("
4191  "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4192  "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4193  }
4194  }
4195 
4196  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4197  if (showTables)
4198  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
4199  if (showIndexes)
4200  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
4201  appendPQExpBufferStr(&buf, "''"); /* dummy */
4202  appendPQExpBufferStr(&buf, ")\n");
4203 
4204  appendPQExpBufferStr(&buf, !showNested && !pattern ?
4205  " AND NOT c.relispartition\n" : "");
4206 
4207  if (!pattern)
4208  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4209  " AND n.nspname !~ '^pg_toast'\n"
4210  " AND n.nspname <> 'information_schema'\n");
4211 
4212  if (!validateSQLNamePattern(&buf, pattern, true, false,
4213  "n.nspname", "c.relname", NULL,
4214  "pg_catalog.pg_table_is_visible(c.oid)",
4215  NULL, 3))
4216  {
4217  termPQExpBuffer(&buf);
4218  return false;
4219  }
4220 
4221  appendPQExpBuffer(&buf, "ORDER BY \"Schema\", %s%s\"Name\";",
4222  mixed_output ? "\"Type\" DESC, " : "",
4223  showNested || pattern ? "\"Parent name\" NULLS FIRST, " : "");
4224 
4225  res = PSQLexec(buf.data);
4226  termPQExpBuffer(&buf);
4227  if (!res)
4228  return false;
4229 
4230  initPQExpBuffer(&title);
4231  appendPQExpBufferStr(&title, tabletitle);
4232 
4233  myopt.nullPrint = NULL;
4234  myopt.title = title.data;
4235  myopt.translate_header = true;
4236  myopt.translate_columns = translate_columns;
4237  myopt.n_translate_columns = lengthof(translate_columns);
4238 
4239  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4240 
4241  termPQExpBuffer(&title);
4242 
4243  PQclear(res);
4244  return true;
4245 }

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 6181 of file describe.c.

6182 {
6184  PGresult *res;
6185  printQueryOpt myopt = pset.popt;
6186  static const bool translate_columns[] = {false, false, false, false, false, false, false, false};
6187 
6188  if (pset.sversion < 100000)
6189  {
6190  char sverbuf[32];
6191 
6192  pg_log_error("The server (version %s) does not support publications.",
6194  sverbuf, sizeof(sverbuf)));
6195  return true;
6196  }
6197 
6198  initPQExpBuffer(&buf);
6199 
6201  "SELECT pubname AS \"%s\",\n"
6202  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6203  " puballtables AS \"%s\",\n"
6204  " pubinsert AS \"%s\",\n"
6205  " pubupdate AS \"%s\",\n"
6206  " pubdelete AS \"%s\"",
6207  gettext_noop("Name"),
6208  gettext_noop("Owner"),
6209  gettext_noop("All tables"),
6210  gettext_noop("Inserts"),
6211  gettext_noop("Updates"),
6212  gettext_noop("Deletes"));
6213  if (pset.sversion >= 110000)
6215  ",\n pubtruncate AS \"%s\"",
6216  gettext_noop("Truncates"));
6217  if (pset.sversion >= 130000)
6219  ",\n pubviaroot AS \"%s\"",
6220  gettext_noop("Via root"));
6221 
6223  "\nFROM pg_catalog.pg_publication\n");
6224 
6225  if (!validateSQLNamePattern(&buf, pattern, false, false,
6226  NULL, "pubname", NULL,
6227  NULL,
6228  NULL, 1))
6229  {
6230  termPQExpBuffer(&buf);
6231  return false;
6232  }
6233 
6234  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6235 
6236  res = PSQLexec(buf.data);
6237  termPQExpBuffer(&buf);
6238  if (!res)
6239  return false;
6240 
6241  myopt.nullPrint = NULL;
6242  myopt.title = _("List of publications");
6243  myopt.translate_header = true;
6244  myopt.translate_columns = translate_columns;
6245  myopt.n_translate_columns = lengthof(translate_columns);
6246 
6247  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6248 
6249  PQclear(res);
6250 
6251  return true;
6252 }

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 4976 of file describe.c.

4977 {
4979  PGresult *res;
4980  printQueryOpt myopt = pset.popt;
4981  int pub_schema_tuples = 0;
4982  char **footers = NULL;
4983 
4984  initPQExpBuffer(&buf);
4986  "SELECT n.nspname AS \"%s\",\n"
4987  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4988  gettext_noop("Name"),
4989  gettext_noop("Owner"));
4990 
4991  if (verbose)
4992  {
4993  appendPQExpBufferStr(&buf, ",\n ");
4994  printACLColumn(&buf, "n.nspacl");
4996  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4997  gettext_noop("Description"));
4998  }
4999 
5001  "\nFROM pg_catalog.pg_namespace n\n");
5002 
5003  if (!showSystem && !pattern)
5005  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5006 
5007  if (!validateSQLNamePattern(&buf, pattern,
5008  !showSystem && !pattern, false,
5009  NULL, "n.nspname", NULL,
5010  NULL,
5011  NULL, 2))
5012  goto error_return;
5013 
5014  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5015 
5016  res = PSQLexec(buf.data);
5017  if (!res)
5018  goto error_return;
5019 
5020  myopt.nullPrint = NULL;
5021  myopt.title = _("List of schemas");
5022  myopt.translate_header = true;
5023 
5024  if (pattern && pset.sversion >= 150000)
5025  {
5026  PGresult *result;
5027  int i;
5028 
5030  "SELECT pubname \n"
5031  "FROM pg_catalog.pg_publication p\n"
5032  " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5033  " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5034  "WHERE n.nspname = '%s'\n"
5035  "ORDER BY 1",
5036  pattern);
5037  result = PSQLexec(buf.data);
5038  if (!result)
5039  goto error_return;
5040  else
5041  pub_schema_tuples = PQntuples(result);
5042 
5043  if (pub_schema_tuples > 0)
5044  {
5045  /*
5046  * Allocate memory for footers. Size of footers will be 1 (for
5047  * storing "Publications:" string) + publication schema mapping
5048  * count + 1 (for storing NULL).
5049  */
5050  footers = (char **) pg_malloc((1 + pub_schema_tuples + 1) * sizeof(char *));
5051  footers[0] = pg_strdup(_("Publications:"));
5052 
5053  /* Might be an empty set - that's ok */
5054  for (i = 0; i < pub_schema_tuples; i++)
5055  {
5056  printfPQExpBuffer(&buf, " \"%s\"",
5057  PQgetvalue(result, i, 0));
5058 
5059  footers[i + 1] = pg_strdup(buf.data);
5060  }
5061 
5062  footers[i + 1] = NULL;
5063  myopt.footers = footers;
5064  }
5065 
5066  PQclear(result);
5067  }
5068 
5069  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5070 
5071  termPQExpBuffer(&buf);
5072  PQclear(res);
5073 
5074  /* Free the memory allocated for the footer */
5075  if (footers)
5076  {
5077  char **footer = NULL;
5078 
5079  for (footer = footers; *footer; footer++)
5080  pg_free(*footer);
5081 
5082  pg_free(footers);
5083  }
5084 
5085  return true;
5086 
5087 error_return:
5088  termPQExpBuffer(&buf);
5089  return false;
5090 }
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:183

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 3853 of file describe.c.

3854 {
3855  bool showTables = strchr(tabtypes, 't') != NULL;
3856  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3857  bool showViews = strchr(tabtypes, 'v') != NULL;
3858  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3859  bool showSeq = strchr(tabtypes, 's') != NULL;
3860  bool showForeign = strchr(tabtypes, 'E') != NULL;
3861 
3863  PGresult *res;
3864  printQueryOpt myopt = pset.popt;
3865  int cols_so_far;
3866  bool translate_columns[] = {false, false, true, false, false, false, false, false, false};
3867 
3868  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3869  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3870  showTables = showViews = showMatViews = showSeq = showForeign = true;
3871 
3872  initPQExpBuffer(&buf);
3873 
3875  "SELECT n.nspname as \"%s\",\n"
3876  " c.relname as \"%s\",\n"
3877  " CASE c.relkind"
3878  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3879  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3880  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3881  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3882  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3883  " WHEN " CppAsString2(RELKIND_TOASTVALUE) " THEN '%s'"
3884  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3885  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3886  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
3887  " END as \"%s\",\n"
3888  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3889  gettext_noop("Schema"),
3890  gettext_noop("Name"),
3891  gettext_noop("table"),
3892  gettext_noop("view"),
3893  gettext_noop("materialized view"),
3894  gettext_noop("index"),
3895  gettext_noop("sequence"),
3896  gettext_noop("TOAST table"),
3897  gettext_noop("foreign table"),
3898  gettext_noop("partitioned table"),
3899  gettext_noop("partitioned index"),
3900  gettext_noop("Type"),
3901  gettext_noop("Owner"));
3902  cols_so_far = 4;
3903 
3904  if (showIndexes)
3905  {
3907  ",\n c2.relname as \"%s\"",
3908  gettext_noop("Table"));
3909  cols_so_far++;
3910  }
3911 
3912  if (verbose)
3913  {
3914  /*
3915  * Show whether a relation is permanent, temporary, or unlogged.
3916  */
3918  ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3919  gettext_noop("permanent"),
3920  gettext_noop("temporary"),
3921  gettext_noop("unlogged"),
3922  gettext_noop("Persistence"));
3923  translate_columns[cols_so_far] = true;
3924 
3925  /*
3926  * We don't bother to count cols_so_far below here, as there's no need
3927  * to; this might change with future additions to the output columns.
3928  */
3929 
3930  /*
3931  * Access methods exist for tables, materialized views and indexes.
3932  * This has been introduced in PostgreSQL 12 for tables.
3933  */
3934  if (pset.sversion >= 120000 && !pset.hide_tableam &&
3935  (showTables || showMatViews || showIndexes))
3937  ",\n am.amname as \"%s\"",
3938  gettext_noop("Access method"));
3939 
3941  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
3942  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3943  gettext_noop("Size"),
3944  gettext_noop("Description"));
3945  }
3946 
3948  "\nFROM pg_catalog.pg_class c"
3949  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3950 
3951  if (pset.sversion >= 120000 && !pset.hide_tableam &&
3952  (showTables || showMatViews || showIndexes))
3954  "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
3955 
3956  if (showIndexes)
3958  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3959  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3960 
3961  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3962  if (showTables)
3963  {
3964  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
3965  CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
3966  /* with 'S' or a pattern, allow 't' to match TOAST tables too */
3967  if (showSystem || pattern)
3968  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_TOASTVALUE) ",");
3969  }
3970  if (showViews)
3971  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
3972  if (showMatViews)
3973  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_MATVIEW) ",");
3974  if (showIndexes)
3975  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_INDEX) ","
3976  CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
3977  if (showSeq)
3978  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ",");
3979  if (showSystem || pattern)
3980  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3981  if (showForeign)
3982  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ",");
3983 
3984  appendPQExpBufferStr(&buf, "''"); /* dummy */
3985  appendPQExpBufferStr(&buf, ")\n");
3986 
3987  if (!showSystem && !pattern)
3988  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3989  " AND n.nspname !~ '^pg_toast'\n"
3990  " AND n.nspname <> 'information_schema'\n");
3991 
3992  if (!validateSQLNamePattern(&buf, pattern, true, false,
3993  "n.nspname", "c.relname", NULL,
3994  "pg_catalog.pg_table_is_visible(c.oid)",
3995  NULL, 3))
3996  {
3997  termPQExpBuffer(&buf);
3998  return false;
3999  }
4000 
4001  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
4002 
4003  res = PSQLexec(buf.data);
4004  termPQExpBuffer(&buf);
4005  if (!res)
4006  return false;
4007 
4008  /*
4009  * Most functions in this file are content to print an empty table when
4010  * there are no matching objects. We intentionally deviate from that
4011  * here, but only in !quiet mode, for historical reasons.
4012  */
4013  if (PQntuples(res) == 0 && !pset.quiet)
4014  {
4015  if (pattern)
4016  pg_log_error("Did not find any relation named \"%s\".",
4017  pattern);
4018  else
4019  pg_log_error("Did not find any relations.");
4020  }
4021  else
4022  {
4023  myopt.nullPrint = NULL;
4024  myopt.title = _("List of relations");
4025  myopt.translate_header = true;
4026  myopt.translate_columns = translate_columns;
4027  myopt.n_translate_columns = lengthof(translate_columns);
4028 
4029  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4030  }
4031 
4032  PQclear(res);
4033  return true;
4034 }
bool hide_tableam
Definition: settings.h:141

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 5480 of file describe.c.

5481 {
5483  PGresult *res;
5484  printQueryOpt myopt = pset.popt;
5485 
5486  if (verbose)
5487  return listTSConfigsVerbose(pattern);
5488 
5489  initPQExpBuffer(&buf);
5490 
5492  "SELECT\n"
5493  " n.nspname as \"%s\",\n"
5494  " c.cfgname as \"%s\",\n"
5495  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5496  "FROM pg_catalog.pg_ts_config c\n"
5497  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5498  gettext_noop("Schema"),
5499  gettext_noop("Name"),
5500  gettext_noop("Description")
5501  );
5502 
5503  if (!validateSQLNamePattern(&buf, pattern, false, false,
5504  "n.nspname", "c.cfgname", NULL,
5505  "pg_catalog.pg_ts_config_is_visible(c.oid)",
5506  NULL, 3))
5507  {
5508  termPQExpBuffer(&buf);
5509  return false;
5510  }
5511 
5512  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5513 
5514  res = PSQLexec(buf.data);
5515  termPQExpBuffer(&buf);
5516  if (!res)
5517  return false;
5518 
5519  myopt.nullPrint = NULL;
5520  myopt.title = _("List of text search configurations");
5521  myopt.translate_header = true;
5522 
5523  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5524 
5525  PQclear(res);
5526  return true;
5527 }
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:5530

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 5348 of file describe.c.

5349 {
5351  PGresult *res;
5352  printQueryOpt myopt = pset.popt;
5353 
5354  initPQExpBuffer(&buf);
5355 
5357  "SELECT\n"
5358  " n.nspname as \"%s\",\n"
5359  " d.dictname as \"%s\",\n",
5360  gettext_noop("Schema"),
5361  gettext_noop("Name"));
5362 
5363  if (verbose)
5364  {
5366  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5367  " pg_catalog.pg_ts_template t\n"
5368  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5369  " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5370  " d.dictinitoption as \"%s\",\n",
5371  gettext_noop("Template"),
5372  gettext_noop("Init options"));
5373  }
5374 
5376  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5377  gettext_noop("Description"));
5378 
5379  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
5380  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5381 
5382  if (!validateSQLNamePattern(&buf, pattern, false, false,
5383  "n.nspname", "d.dictname", NULL,
5384  "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5385  NULL, 3))
5386  {
5387  termPQExpBuffer(&buf);
5388  return false;
5389  }
5390 
5391  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5392 
5393  res = PSQLexec(buf.data);
5394  termPQExpBuffer(&buf);
5395  if (!res)
5396  return false;
5397 
5398  myopt.nullPrint = NULL;
5399  myopt.title = _("List of text search dictionaries");
5400  myopt.translate_header = true;
5401 
5402  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5403 
5404  PQclear(res);
5405  return true;
5406 }

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 5098 of file describe.c.

5099 {
5101  PGresult *res;
5102  printQueryOpt myopt = pset.popt;
5103 
5104  if (verbose)
5105  return listTSParsersVerbose(pattern);
5106 
5107  initPQExpBuffer(&buf);
5108 
5110  "SELECT\n"
5111  " n.nspname as \"%s\",\n"
5112  " p.prsname as \"%s\",\n"
5113  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5114  "FROM pg_catalog.pg_ts_parser p\n"
5115  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5116  gettext_noop("Schema"),
5117  gettext_noop("Name"),
5118  gettext_noop("Description")
5119  );
5120 
5121  if (!validateSQLNamePattern(&buf, pattern, false, false,
5122  "n.nspname", "p.prsname", NULL,
5123  "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5124  NULL, 3))
5125  {
5126  termPQExpBuffer(&buf);
5127  return false;
5128  }
5129 
5130  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5131 
5132  res = PSQLexec(buf.data);
5133  termPQExpBuffer(&buf);
5134  if (!res)
5135  return false;
5136 
5137  myopt.nullPrint = NULL;
5138  myopt.title = _("List of text search parsers");
5139  myopt.translate_header = true;
5140 
5141  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5142 
5143  PQclear(res);
5144  return true;
5145 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:5151

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 5414 of file describe.c.

5415 {
5417  PGresult *res;
5418  printQueryOpt myopt = pset.popt;
5419 
5420  initPQExpBuffer(&buf);
5421 
5422  if (verbose)
5424  "SELECT\n"
5425  " n.nspname AS \"%s\",\n"
5426  " t.tmplname AS \"%s\",\n"
5427  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5428  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5429  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5430  gettext_noop("Schema"),
5431  gettext_noop("Name"),
5432  gettext_noop("Init"),
5433  gettext_noop("Lexize"),
5434  gettext_noop("Description"));
5435  else
5437  "SELECT\n"
5438  " n.nspname AS \"%s\",\n"
5439  " t.tmplname AS \"%s\",\n"
5440  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5441  gettext_noop("Schema"),
5442  gettext_noop("Name"),
5443  gettext_noop("Description"));
5444 
5445  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
5446  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5447 
5448  if (!validateSQLNamePattern(&buf, pattern, false, false,
5449  "n.nspname", "t.tmplname", NULL,
5450  "pg_catalog.pg_ts_template_is_visible(t.oid)",
5451  NULL, 3))
5452  {
5453  termPQExpBuffer(&buf);
5454  return false;
5455  }
5456 
5457  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5458 
5459  res = PSQLexec(buf.data);
5460  termPQExpBuffer(&buf);
5461  if (!res)
5462  return false;
5463 
5464  myopt.nullPrint = NULL;
5465  myopt.title = _("List of text search templates");
5466  myopt.translate_header = true;
5467 
5468  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5469 
5470  PQclear(res);
5471  return true;
5472 }

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 5835 of file describe.c.

5836 {
5838  PGresult *res;
5839  printQueryOpt myopt = pset.popt;
5840 
5841  initPQExpBuffer(&buf);
5843  "SELECT um.srvname AS \"%s\",\n"
5844  " um.usename AS \"%s\"",
5845  gettext_noop("Server"),
5846  gettext_noop("User name"));
5847 
5848  if (verbose)
5850  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
5851  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5852  " pg_catalog.quote_ident(option_name) || ' ' || "
5853  " pg_catalog.quote_literal(option_value) FROM "
5854  " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
5855  " END AS \"%s\"",
5856  gettext_noop("FDW options"));
5857 
5858  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
5859 
5860  if (!validateSQLNamePattern(&buf, pattern, false, false,
5861  NULL, "um.srvname", "um.usename", NULL,
5862  NULL, 1))
5863  {
5864  termPQExpBuffer(&buf);
5865  return false;
5866  }
5867 
5868  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5869 
5870  res = PSQLexec(buf.data);
5871  termPQExpBuffer(&buf);
5872  if (!res)
5873  return false;
5874 
5875  myopt.nullPrint = NULL;
5876  myopt.title = _("List of user mappings");
5877  myopt.translate_header = true;
5878 
5879  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5880 
5881  PQclear(res);
5882  return true;
5883 }

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 1252 of file describe.c.

1253 {
1255  PGresult *res;
1256  printQueryOpt myopt = pset.popt;
1257  static const bool translate_columns[] = {false, false, true, false};
1258 
1259  initPQExpBuffer(&buf);
1260 
1262  "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1263  "FROM (\n",
1264  gettext_noop("Schema"),
1265  gettext_noop("Name"),
1266  gettext_noop("Object"),
1267  gettext_noop("Description"));
1268 
1269  /* Table constraint descriptions */
1271  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1272  " n.nspname as nspname,\n"
1273  " CAST(pgc.conname AS pg_catalog.text) as name,"
1274  " CAST('%s' AS pg_catalog.text) as object\n"
1275  " FROM pg_catalog.pg_constraint pgc\n"
1276  " JOIN pg_catalog.pg_class c "
1277  "ON c.oid = pgc.conrelid\n"
1278  " LEFT JOIN pg_catalog.pg_namespace n "
1279  " ON n.oid = c.relnamespace\n",
1280  gettext_noop("table constraint"));
1281 
1282  if (!showSystem && !pattern)
1283  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1284  " AND n.nspname <> 'information_schema'\n");
1285 
1286  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1287  false, "n.nspname", "pgc.conname", NULL,
1288  "pg_catalog.pg_table_is_visible(c.oid)",
1289  NULL, 3))
1290  goto error_return;
1291 
1292  /* Domain constraint descriptions */
1294  "UNION ALL\n"
1295  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1296  " n.nspname as nspname,\n"
1297  " CAST(pgc.conname AS pg_catalog.text) as name,"
1298  " CAST('%s' AS pg_catalog.text) as object\n"
1299  " FROM pg_catalog.pg_constraint pgc\n"
1300  " JOIN pg_catalog.pg_type t "
1301  "ON t.oid = pgc.contypid\n"
1302  " LEFT JOIN pg_catalog.pg_namespace n "
1303  " ON n.oid = t.typnamespace\n",
1304  gettext_noop("domain constraint"));
1305 
1306  if (!showSystem && !pattern)
1307  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1308  " AND n.nspname <> 'information_schema'\n");
1309 
1310  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1311  false, "n.nspname", "pgc.conname", NULL,
1312  "pg_catalog.pg_type_is_visible(t.oid)",
1313  NULL, 3))
1314  goto error_return;
1315 
1316  /* Operator class descriptions */
1318  "UNION ALL\n"
1319  " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1320  " n.nspname as nspname,\n"
1321  " CAST(o.opcname AS pg_catalog.text) as name,\n"
1322  " CAST('%s' AS pg_catalog.text) as object\n"
1323  " FROM pg_catalog.pg_opclass o\n"
1324  " JOIN pg_catalog.pg_am am ON "
1325  "o.opcmethod = am.oid\n"
1326  " JOIN pg_catalog.pg_namespace n ON "
1327  "n.oid = o.opcnamespace\n",
1328  gettext_noop("operator class"));
1329 
1330  if (!showSystem && !pattern)
1331  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1332  " AND n.nspname <> 'information_schema'\n");
1333 
1334  if (!validateSQLNamePattern(&buf, pattern, true, false,
1335  "n.nspname", "o.opcname", NULL,
1336  "pg_catalog.pg_opclass_is_visible(o.oid)",
1337  NULL, 3))
1338  goto error_return;
1339 
1340  /* Operator family descriptions */
1342  "UNION ALL\n"
1343  " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1344  " n.nspname as nspname,\n"
1345  " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1346  " CAST('%s' AS pg_catalog.text) as object\n"
1347  " FROM pg_catalog.pg_opfamily opf\n"
1348  " JOIN pg_catalog.pg_am am "
1349  "ON opf.opfmethod = am.oid\n"
1350  " JOIN pg_catalog.pg_namespace n "
1351  "ON opf.opfnamespace = n.oid\n",
1352  gettext_noop("operator family"));
1353 
1354  if (!showSystem && !pattern)
1355  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1356  " AND n.nspname <> 'information_schema'\n");
1357 
1358  if (!validateSQLNamePattern(&buf, pattern, true, false,
1359  "n.nspname", "opf.opfname", NULL,
1360  "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1361  NULL, 3))
1362  goto error_return;
1363 
1364  /* Rule descriptions (ignore rules for views) */
1366  "UNION ALL\n"
1367  " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1368  " n.nspname as nspname,\n"
1369  " CAST(r.rulename AS pg_catalog.text) as name,"
1370  " CAST('%s' AS pg_catalog.text) as object\n"
1371  " FROM pg_catalog.pg_rewrite r\n"
1372  " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1373  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1374  " WHERE r.rulename != '_RETURN'\n",
1375  gettext_noop("rule"));
1376 
1377  if (!showSystem && !pattern)
1378  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1379  " AND n.nspname <> 'information_schema'\n");
1380 
1381  if (!validateSQLNamePattern(&buf, pattern, true, false,
1382  "n.nspname", "r.rulename", NULL,
1383  "pg_catalog.pg_table_is_visible(c.oid)",
1384  NULL, 3))
1385  goto error_return;
1386 
1387  /* Trigger descriptions */
1389  "UNION ALL\n"
1390  " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1391  " n.nspname as nspname,\n"
1392  " CAST(t.tgname AS pg_catalog.text) as name,"
1393  " CAST('%s' AS pg_catalog.text) as object\n"
1394  " FROM pg_catalog.pg_trigger t\n"
1395  " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1396  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1397  gettext_noop("trigger"));
1398 
1399  if (!showSystem && !pattern)
1400  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1401  " AND n.nspname <> 'information_schema'\n");
1402 
1403  if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1404  "n.nspname", "t.tgname", NULL,
1405  "pg_catalog.pg_table_is_visible(c.oid)",
1406  NULL, 3))
1407  goto error_return;
1408 
1410  ") AS tt\n"
1411  " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1412 
1413  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1414 
1415  res = PSQLexec(buf.data);
1416  termPQExpBuffer(&buf);
1417  if (!res)
1418  return false;
1419 
1420  myopt.nullPrint = NULL;
1421  myopt.title = _("Object descriptions");
1422  myopt.translate_header = true;
1423  myopt.translate_columns = translate_columns;
1424  myopt.n_translate_columns = lengthof(translate_columns);
1425 
1426  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1427 
1428  PQclear(res);
1429  return true;
1430 
1431 error_return:
1432  termPQExpBuffer(&buf);
1433  return false;
1434 }

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,
bool  showSystem 
)

Definition at line 1014 of file describe.c.

1015 {
1017  PGresult *res;
1018  printQueryOpt myopt = pset.popt;
1019  static const bool translate_columns[] = {false, false, true, false, false, false};
1020 
1021  initPQExpBuffer(&buf);
1022 
1023  /*
1024  * we ignore indexes and toast tables since they have no meaningful rights
1025  */
1027  "SELECT n.nspname as \"%s\",\n"
1028  " c.relname as \"%s\",\n"
1029  " CASE c.relkind"
1030  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
1031  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
1032  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
1033  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
1034  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
1035  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
1036  " END as \"%s\",\n"
1037  " ",
1038  gettext_noop("Schema"),
1039  gettext_noop("Name"),
1040  gettext_noop("table"),
1041  gettext_noop("view"),
1042  gettext_noop("materialized view"),
1043  gettext_noop("sequence"),
1044  gettext_noop("foreign table"),
1045  gettext_noop("partitioned table"),
1046  gettext_noop("Type"));
1047 
1048  printACLColumn(&buf, "c.relacl");
1049 
1051  ",\n pg_catalog.array_to_string(ARRAY(\n"
1052  " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1053  " FROM pg_catalog.pg_attribute a\n"
1054  " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1055  " ), E'\\n') AS \"%s\"",
1056  gettext_noop("Column privileges"));
1057 
1058  if (pset.sversion >= 90500 && pset.sversion < 100000)
1060  ",\n pg_catalog.array_to_string(ARRAY(\n"
1061  " SELECT polname\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  if (pset.sversion >= 100000)
1091  ",\n pg_catalog.array_to_string(ARRAY(\n"
1092  " SELECT polname\n"
1093  " || CASE WHEN NOT polpermissive THEN\n"
1094  " E' (RESTRICTIVE)'\n"
1095  " ELSE '' END\n"
1096  " || CASE WHEN polcmd != '*' THEN\n"
1097  " E' (' || polcmd::pg_catalog.text || E'):'\n"
1098  " ELSE E':'\n"
1099  " END\n"
1100  " || CASE WHEN polqual IS NOT NULL THEN\n"
1101  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1102  " ELSE E''\n"
1103  " END\n"
1104  " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1105  " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1106  " ELSE E''\n"
1107  " END"
1108  " || CASE WHEN polroles <> '{0}' THEN\n"
1109  " E'\\n to: ' || pg_catalog.array_to_string(\n"
1110  " ARRAY(\n"
1111  " SELECT rolname\n"
1112  " FROM pg_catalog.pg_roles\n"
1113  " WHERE oid = ANY (polroles)\n"
1114  " ORDER BY 1\n"
1115  " ), E', ')\n"
1116  " ELSE E''\n"
1117  " END\n"
1118  " FROM pg_catalog.pg_policy pol\n"
1119  " WHERE polrelid = c.oid), E'\\n')\n"
1120  " AS \"%s\"",
1121  gettext_noop("Policies"));
1122 
1123  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
1124  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1125  "WHERE c.relkind IN ("
1126  CppAsString2(RELKIND_RELATION) ","
1127  CppAsString2(RELKIND_VIEW) ","
1128  CppAsString2(RELKIND_MATVIEW) ","
1129  CppAsString2(RELKIND_SEQUENCE) ","
1130  CppAsString2(RELKIND_FOREIGN_TABLE) ","
1131  CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
1132 
1133  if (!showSystem && !pattern)
1134  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1135  " AND n.nspname <> 'information_schema'\n");
1136 
1137  if (!validateSQLNamePattern(&buf, pattern, true, false,
1138  "n.nspname", "c.relname", NULL,
1139  "pg_catalog.pg_table_is_visible(c.oid)",
1140  NULL, 3))
1141  goto error_return;
1142 
1143  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
1144 
1145  res = PSQLexec(buf.data);
1146  if (!res)
1147  goto error_return;
1148 
1149  myopt.nullPrint = NULL;
1150  printfPQExpBuffer(&buf, _("Access privileges"));
1151  myopt.title = buf.data;
1152  myopt.translate_header = true;
1153  myopt.translate_columns = translate_columns;
1154  myopt.n_translate_columns = lengthof(translate_columns);
1155 
1156  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1157 
1158  termPQExpBuffer(&buf);
1159  PQclear(res);
1160  return true;
1161 
1162 error_return:
1163  termPQExpBuffer(&buf);
1164  return false;
1165 }

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().