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

Go to the source code of this file.

Functions

bool describeAggregates (const char *pattern, bool verbose, bool showSystem)
 
bool describeAccessMethods (const char *pattern, bool verbose)
 
bool describeTablespaces (const char *pattern, bool verbose)
 
bool describeFunctions (const char *functypes, const char *pattern, bool verbose, bool showSystem)
 
bool describeTypes (const char *pattern, bool verbose, bool showSystem)
 
bool describeOperators (const char *pattern, bool verbose, bool showSystem)
 
bool describeRoles (const char *pattern, bool verbose, bool showSystem)
 
bool listDbRoleSettings (const char *pattern1, const char *pattern2)
 
bool permissionsList (const char *pattern)
 
bool listDefaultACLs (const char *pattern)
 
bool objectDescription (const char *pattern, bool showSystem)
 
bool describeTableDetails (const char *pattern, bool verbose, bool showSystem)
 
bool listTSConfigs (const char *pattern, bool verbose)
 
bool listTSParsers (const char *pattern, bool verbose)
 
bool listTSDictionaries (const char *pattern, bool verbose)
 
bool listTSTemplates (const char *pattern, bool verbose)
 
bool listAllDbs (const char *pattern, bool verbose)
 
bool listTables (const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
 
bool listDomains (const char *pattern, bool verbose, bool showSystem)
 
bool listConversions (const char *pattern, bool verbose, bool showSystem)
 
bool listCasts (const char *pattern, bool verbose)
 
bool listCollations (const char *pattern, bool verbose, bool showSystem)
 
bool listSchemas (const char *pattern, bool verbose, bool showSystem)
 
bool listForeignDataWrappers (const char *pattern, bool verbose)
 
bool listForeignServers (const char *pattern, bool verbose)
 
bool listUserMappings (const char *pattern, bool verbose)
 
bool listForeignTables (const char *pattern, bool verbose)
 
bool listLanguages (const char *pattern, bool verbose, bool showSystem)
 
bool listExtensions (const char *pattern)
 
bool listExtensionContents (const char *pattern)
 
bool listEventTriggers (const char *pattern, bool verbose)
 
bool listPublications (const char *pattern)
 
bool describePublications (const char *pattern)
 
bool describeSubscriptions (const char *pattern, bool verbose)
 

Function Documentation

◆ describeAccessMethods()

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 140 of file describe.c.

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

Referenced by exec_command_d().

141 {
143  PGresult *res;
144  printQueryOpt myopt = pset.popt;
145  static const bool translate_columns[] = {false, true, false, false};
146 
147  if (pset.sversion < 90600)
148  {
149  char sverbuf[32];
150 
151  psql_error("The server (version %s) does not support access methods.\n",
153  sverbuf, sizeof(sverbuf)));
154  return true;
155  }
156 
157  initPQExpBuffer(&buf);
158 
159  printfPQExpBuffer(&buf,
160  "SELECT amname AS \"%s\",\n"
161  " CASE amtype"
162  " WHEN 'i' THEN '%s'"
163  " END AS \"%s\"",
164  gettext_noop("Name"),
165  gettext_noop("Index"),
166  gettext_noop("Type"));
167 
168  if (verbose)
169  {
170  appendPQExpBuffer(&buf,
171  ",\n amhandler AS \"%s\",\n"
172  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
173  gettext_noop("Handler"),
174  gettext_noop("Description"));
175  }
176 
178  "\nFROM pg_catalog.pg_am\n");
179 
180  processSQLNamePattern(pset.db, &buf, pattern, false, false,
181  NULL, "amname", NULL,
182  NULL);
183 
184  appendPQExpBufferStr(&buf, "ORDER BY 1;");
185 
186  res = PSQLexec(buf.data);
187  termPQExpBuffer(&buf);
188  if (!res)
189  return false;
190 
191  myopt.nullPrint = NULL;
192  myopt.title = _("List of access methods");
193  myopt.translate_header = true;
194  myopt.translate_columns = translate_columns;
195  myopt.n_translate_columns = lengthof(translate_columns);
196 
197  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
198 
199  PQclear(res);
200  return true;
201 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeAggregates()

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

Definition at line 62 of file describe.c.

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

Referenced by exec_command_d().

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

◆ describeFunctions()

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

Definition at line 303 of file describe.c.

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

Referenced by exec_command_d().

304 {
305  bool showAggregate = strchr(functypes, 'a') != NULL;
306  bool showNormal = strchr(functypes, 'n') != NULL;
307  bool showTrigger = strchr(functypes, 't') != NULL;
308  bool showWindow = strchr(functypes, 'w') != NULL;
309  bool have_where;
311  PGresult *res;
312  printQueryOpt myopt = pset.popt;
313  static const bool translate_columns[] = {false, false, false, false, true, true, true, false, true, false, false, false, false};
314 
315  /* No "Parallel" column before 9.6 */
316  static const bool translate_columns_pre_96[] = {false, false, false, false, true, true, false, true, false, false, false, false};
317 
318  if (strlen(functypes) != strspn(functypes, "antwS+"))
319  {
320  psql_error("\\df only takes [antwS+] as options\n");
321  return true;
322  }
323 
324  if (showWindow && pset.sversion < 80400)
325  {
326  char sverbuf[32];
327 
328  psql_error("\\df does not take a \"w\" option with server version %s\n",
330  sverbuf, sizeof(sverbuf)));
331  return true;
332  }
333 
334  if (!showAggregate && !showNormal && !showTrigger && !showWindow)
335  {
336  showAggregate = showNormal = showTrigger = true;
337  if (pset.sversion >= 80400)
338  showWindow = true;
339  }
340 
341  initPQExpBuffer(&buf);
342 
343  printfPQExpBuffer(&buf,
344  "SELECT n.nspname as \"%s\",\n"
345  " p.proname as \"%s\",\n",
346  gettext_noop("Schema"),
347  gettext_noop("Name"));
348 
349  if (pset.sversion >= 80400)
350  appendPQExpBuffer(&buf,
351  " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
352  " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
353  " CASE\n"
354  " WHEN p.proisagg THEN '%s'\n"
355  " WHEN p.proiswindow THEN '%s'\n"
356  " WHEN p.prorettype = 0 THEN '%s'\n"
357  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
358  " ELSE '%s'\n"
359  " END as \"%s\"",
360  gettext_noop("Result data type"),
361  gettext_noop("Argument data types"),
362  /* translator: "agg" is short for "aggregate" */
363  gettext_noop("agg"),
364  gettext_noop("window"),
365  gettext_noop("proc"),
366  gettext_noop("trigger"),
367  gettext_noop("func"),
368  gettext_noop("Type"));
369  else if (pset.sversion >= 80100)
370  appendPQExpBuffer(&buf,
371  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
372  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
373  " CASE WHEN proallargtypes IS NOT NULL THEN\n"
374  " pg_catalog.array_to_string(ARRAY(\n"
375  " SELECT\n"
376  " CASE\n"
377  " WHEN p.proargmodes[s.i] = 'i' THEN ''\n"
378  " WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n"
379  " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n"
380  " WHEN p.proargmodes[s.i] = 'v' THEN 'VARIADIC '\n"
381  " END ||\n"
382  " CASE\n"
383  " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n"
384  " ELSE p.proargnames[s.i] || ' '\n"
385  " END ||\n"
386  " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n"
387  " FROM\n"
388  " pg_catalog.generate_series(1, pg_catalog.array_upper(p.proallargtypes, 1)) AS s(i)\n"
389  " ), ', ')\n"
390  " ELSE\n"
391  " pg_catalog.array_to_string(ARRAY(\n"
392  " SELECT\n"
393  " CASE\n"
394  " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n"
395  " ELSE p.proargnames[s.i+1] || ' '\n"
396  " END ||\n"
397  " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
398  " FROM\n"
399  " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
400  " ), ', ')\n"
401  " END AS \"%s\",\n"
402  " CASE\n"
403  " WHEN p.proisagg THEN '%s'\n"
404  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
405  " ELSE '%s'\n"
406  " END AS \"%s\"",
407  gettext_noop("Result data type"),
408  gettext_noop("Argument data types"),
409  /* translator: "agg" is short for "aggregate" */
410  gettext_noop("agg"),
411  gettext_noop("trigger"),
412  gettext_noop("func"),
413  gettext_noop("Type"));
414  else
415  appendPQExpBuffer(&buf,
416  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
417  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
418  " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
419  " CASE\n"
420  " WHEN p.proisagg THEN '%s'\n"
421  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
422  " ELSE '%s'\n"
423  " END AS \"%s\"",
424  gettext_noop("Result data type"),
425  gettext_noop("Argument data types"),
426  /* translator: "agg" is short for "aggregate" */
427  gettext_noop("agg"),
428  gettext_noop("trigger"),
429  gettext_noop("func"),
430  gettext_noop("Type"));
431 
432  if (verbose)
433  {
434  appendPQExpBuffer(&buf,
435  ",\n CASE\n"
436  " WHEN p.provolatile = 'i' THEN '%s'\n"
437  " WHEN p.provolatile = 's' THEN '%s'\n"
438  " WHEN p.provolatile = 'v' THEN '%s'\n"
439  " END as \"%s\"",
440  gettext_noop("immutable"),
441  gettext_noop("stable"),
442  gettext_noop("volatile"),
443  gettext_noop("Volatility"));
444  if (pset.sversion >= 90600)
445  appendPQExpBuffer(&buf,
446  ",\n CASE\n"
447  " WHEN p.proparallel = 'r' THEN '%s'\n"
448  " WHEN p.proparallel = 's' THEN '%s'\n"
449  " WHEN p.proparallel = 'u' THEN '%s'\n"
450  " END as \"%s\"",
451  gettext_noop("restricted"),
452  gettext_noop("safe"),
453  gettext_noop("unsafe"),
454  gettext_noop("Parallel"));
455  appendPQExpBuffer(&buf,
456  ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
457  ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
458  gettext_noop("Owner"),
459  gettext_noop("definer"),
460  gettext_noop("invoker"),
461  gettext_noop("Security"));
462  appendPQExpBufferStr(&buf, ",\n ");
463  printACLColumn(&buf, "p.proacl");
464  appendPQExpBuffer(&buf,
465  ",\n l.lanname as \"%s\""
466  ",\n p.prosrc as \"%s\""
467  ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
468  gettext_noop("Language"),
469  gettext_noop("Source code"),
470  gettext_noop("Description"));
471  }
472 
474  "\nFROM pg_catalog.pg_proc p"
475  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
476 
477  if (verbose)
479  " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
480 
481  have_where = false;
482 
483  /* filter by function type, if requested */
484  if (showNormal && showAggregate && showTrigger && showWindow)
485  /* Do nothing */ ;
486  else if (showNormal)
487  {
488  if (!showAggregate)
489  {
490  if (have_where)
491  appendPQExpBufferStr(&buf, " AND ");
492  else
493  {
494  appendPQExpBufferStr(&buf, "WHERE ");
495  have_where = true;
496  }
497  appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
498  }
499  if (!showTrigger)
500  {
501  if (have_where)
502  appendPQExpBufferStr(&buf, " AND ");
503  else
504  {
505  appendPQExpBufferStr(&buf, "WHERE ");
506  have_where = true;
507  }
508  appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
509  }
510  if (!showWindow && pset.sversion >= 80400)
511  {
512  if (have_where)
513  appendPQExpBufferStr(&buf, " AND ");
514  else
515  {
516  appendPQExpBufferStr(&buf, "WHERE ");
517  have_where = true;
518  }
519  appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
520  }
521  }
522  else
523  {
524  bool needs_or = false;
525 
526  appendPQExpBufferStr(&buf, "WHERE (\n ");
527  have_where = true;
528  /* Note: at least one of these must be true ... */
529  if (showAggregate)
530  {
531  appendPQExpBufferStr(&buf, "p.proisagg\n");
532  needs_or = true;
533  }
534  if (showTrigger)
535  {
536  if (needs_or)
537  appendPQExpBufferStr(&buf, " OR ");
539  "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
540  needs_or = true;
541  }
542  if (showWindow)
543  {
544  if (needs_or)
545  appendPQExpBufferStr(&buf, " OR ");
546  appendPQExpBufferStr(&buf, "p.proiswindow\n");
547  needs_or = true;
548  }
549  appendPQExpBufferStr(&buf, " )\n");
550  }
551 
552  processSQLNamePattern(pset.db, &buf, pattern, have_where, false,
553  "n.nspname", "p.proname", NULL,
554  "pg_catalog.pg_function_is_visible(p.oid)");
555 
556  if (!showSystem && !pattern)
557  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
558  " AND n.nspname <> 'information_schema'\n");
559 
560  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
561 
562  res = PSQLexec(buf.data);
563  termPQExpBuffer(&buf);
564  if (!res)
565  return false;
566 
567  myopt.nullPrint = NULL;
568  myopt.title = _("List of functions");
569  myopt.translate_header = true;
570  if (pset.sversion >= 90600)
571  {
572  myopt.translate_columns = translate_columns;
573  myopt.n_translate_columns = lengthof(translate_columns);
574  }
575  else
576  {
577  myopt.translate_columns = translate_columns_pre_96;
578  myopt.n_translate_columns = lengthof(translate_columns_pre_96);
579  }
580 
581  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
582 
583  PQclear(res);
584  return true;
585 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeOperators()

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

Definition at line 710 of file describe.c.

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

Referenced by exec_command_d().

711 {
713  PGresult *res;
714  printQueryOpt myopt = pset.popt;
715 
716  initPQExpBuffer(&buf);
717 
718  /*
719  * Note: before Postgres 9.1, we did not assign comments to any built-in
720  * operators, preferring to let the comment on the underlying function
721  * suffice. The coalesce() on the obj_description() calls below supports
722  * this convention by providing a fallback lookup of a comment on the
723  * operator's function. As of 9.1 there is a policy that every built-in
724  * operator should have a comment; so the coalesce() is no longer
725  * necessary so far as built-in operators are concerned. We keep it
726  * anyway, for now, because (1) third-party modules may still be following
727  * the old convention, and (2) we'd need to do it anyway when talking to a
728  * pre-9.1 server.
729  */
730 
731  printfPQExpBuffer(&buf,
732  "SELECT n.nspname as \"%s\",\n"
733  " o.oprname AS \"%s\",\n"
734  " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
735  " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
736  " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
737  gettext_noop("Schema"),
738  gettext_noop("Name"),
739  gettext_noop("Left arg type"),
740  gettext_noop("Right arg type"),
741  gettext_noop("Result type"));
742 
743  if (verbose)
744  appendPQExpBuffer(&buf,
745  " o.oprcode AS \"%s\",\n",
746  gettext_noop("Function"));
747 
748  appendPQExpBuffer(&buf,
749  " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
750  " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
751  "FROM pg_catalog.pg_operator o\n"
752  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
753  gettext_noop("Description"));
754 
755  if (!showSystem && !pattern)
756  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
757  " AND n.nspname <> 'information_schema'\n");
758 
759  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
760  "n.nspname", "o.oprname", NULL,
761  "pg_catalog.pg_operator_is_visible(o.oid)");
762 
763  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
764 
765  res = PSQLexec(buf.data);
766  termPQExpBuffer(&buf);
767  if (!res)
768  return false;
769 
770  myopt.nullPrint = NULL;
771  myopt.title = _("List of operators");
772  myopt.translate_header = true;
773 
774  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
775 
776  PQclear(res);
777  return true;
778 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describePublications()

bool describePublications ( const char *  pattern)

Definition at line 5206 of file describe.c.

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

Referenced by exec_command_d().

5207 {
5209  int i;
5210  PGresult *res;
5211 
5212  if (pset.sversion < 100000)
5213  {
5214  char sverbuf[32];
5215 
5216  psql_error("The server (version %s) does not support publications.\n",
5218  sverbuf, sizeof(sverbuf)));
5219  return true;
5220  }
5221 
5222  initPQExpBuffer(&buf);
5223 
5224  printfPQExpBuffer(&buf,
5225  "SELECT oid, pubname,\n"
5226  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
5227  " puballtables, pubinsert, pubupdate, pubdelete\n"
5228  "FROM pg_catalog.pg_publication\n");
5229 
5230  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5231  NULL, "pubname", NULL,
5232  NULL);
5233 
5234  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5235 
5236  res = PSQLexec(buf.data);
5237  if (!res)
5238  {
5239  termPQExpBuffer(&buf);
5240  return false;
5241  }
5242 
5243  if (PQntuples(res) == 0)
5244  {
5245  if (!pset.quiet)
5246  {
5247  if (pattern)
5248  psql_error("Did not find any publication named \"%s\".\n",
5249  pattern);
5250  else
5251  psql_error("Did not find any publications.\n");
5252  }
5253 
5254  termPQExpBuffer(&buf);
5255  PQclear(res);
5256  return false;
5257  }
5258 
5259  for (i = 0; i < PQntuples(res); i++)
5260  {
5261  const char align = 'l';
5262  int ncols = 5;
5263  int nrows = 1;
5264  int tables = 0;
5265  PGresult *tabres;
5266  char *pubid = PQgetvalue(res, i, 0);
5267  char *pubname = PQgetvalue(res, i, 1);
5268  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
5269  int j;
5270  PQExpBufferData title;
5271  printTableOpt myopt = pset.popt.topt;
5272  printTableContent cont;
5273 
5274  initPQExpBuffer(&title);
5275  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5276  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5277 
5278  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
5279  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
5280  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5281  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5282  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5283 
5284  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
5285  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5286  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5287  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5288  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
5289 
5290  if (!puballtables)
5291  {
5292  printfPQExpBuffer(&buf,
5293  "SELECT n.nspname, c.relname\n"
5294  "FROM pg_catalog.pg_class c,\n"
5295  " pg_catalog.pg_namespace n,\n"
5296  " pg_catalog.pg_publication_rel pr\n"
5297  "WHERE c.relnamespace = n.oid\n"
5298  " AND c.oid = pr.prrelid\n"
5299  " AND pr.prpubid = '%s'\n"
5300  "ORDER BY 1,2", pubid);
5301 
5302  tabres = PSQLexec(buf.data);
5303  if (!tabres)
5304  {
5305  printTableCleanup(&cont);
5306  PQclear(res);
5307  termPQExpBuffer(&buf);
5308  termPQExpBuffer(&title);
5309  return false;
5310  }
5311  else
5312  tables = PQntuples(tabres);
5313 
5314  if (tables > 0)
5315  printTableAddFooter(&cont, _("Tables:"));
5316 
5317  for (j = 0; j < tables; j++)
5318  {
5319  printfPQExpBuffer(&buf, " \"%s.%s\"",
5320  PQgetvalue(tabres, j, 0),
5321  PQgetvalue(tabres, j, 1));
5322 
5323  printTableAddFooter(&cont, buf.data);
5324  }
5325  PQclear(tabres);
5326  }
5327 
5328  printTable(&cont, pset.queryFout, false, pset.logfile);
5329  printTableCleanup(&cont);
5330 
5331  termPQExpBuffer(&title);
5332  }
5333 
5334  termPQExpBuffer(&buf);
5335  PQclear(res);
5336 
5337  return true;
5338 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
void printTableCleanup(printTableContent *const content)
Definition: print.c:3101
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
printTableOpt topt
Definition: print.h:165
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2970
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3010
static char * buf
Definition: pg_test_fsync.c:67
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3190
void psql_error(const char *fmt,...)
Definition: common.c:221
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3058
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2933
int i
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeRoles()

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

Definition at line 3109 of file describe.c.

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

Referenced by exec_command_d().

3110 {
3112  PGresult *res;
3113  printTableContent cont;
3114  printTableOpt myopt = pset.popt.topt;
3115  int ncols = 3;
3116  int nrows = 0;
3117  int i;
3118  int conns;
3119  const char align = 'l';
3120  char **attr;
3121 
3122  myopt.default_footer = false;
3123 
3124  initPQExpBuffer(&buf);
3125 
3126  if (pset.sversion >= 80100)
3127  {
3128  printfPQExpBuffer(&buf,
3129  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3130  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3131  " r.rolconnlimit, r.rolvaliduntil,\n"
3132  " ARRAY(SELECT b.rolname\n"
3133  " FROM pg_catalog.pg_auth_members m\n"
3134  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3135  " WHERE m.member = r.oid) as memberof");
3136 
3137  if (verbose && pset.sversion >= 80200)
3138  {
3139  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3140  ncols++;
3141  }
3142  if (pset.sversion >= 90100)
3143  {
3144  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3145  }
3146 
3147  if (pset.sversion >= 90500)
3148  {
3149  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3150  }
3151 
3152  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3153 
3154  if (!showSystem && !pattern)
3155  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3156 
3157  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3158  NULL, "r.rolname", NULL, NULL);
3159  }
3160  else
3161  {
3162  printfPQExpBuffer(&buf,
3163  "SELECT u.usename AS rolname,\n"
3164  " u.usesuper AS rolsuper,\n"
3165  " true AS rolinherit, false AS rolcreaterole,\n"
3166  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3167  " -1 AS rolconnlimit,"
3168  " u.valuntil as rolvaliduntil,\n"
3169  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3170  "\nFROM pg_catalog.pg_user u\n");
3171 
3172  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3173  NULL, "u.usename", NULL, NULL);
3174  }
3175 
3176  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3177 
3178  res = PSQLexec(buf.data);
3179  if (!res)
3180  return false;
3181 
3182  nrows = PQntuples(res);
3183  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3184 
3185  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3186 
3187  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3188  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3189  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3190 
3191  if (verbose && pset.sversion >= 80200)
3192  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3193 
3194  for (i = 0; i < nrows; i++)
3195  {
3196  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3197 
3198  resetPQExpBuffer(&buf);
3199  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3200  add_role_attribute(&buf, _("Superuser"));
3201 
3202  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3203  add_role_attribute(&buf, _("No inheritance"));
3204 
3205  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3206  add_role_attribute(&buf, _("Create role"));
3207 
3208  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3209  add_role_attribute(&buf, _("Create DB"));
3210 
3211  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3212  add_role_attribute(&buf, _("Cannot login"));
3213 
3214  if (pset.sversion >= 90100)
3215  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3216  add_role_attribute(&buf, _("Replication"));
3217 
3218  if (pset.sversion >= 90500)
3219  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3220  add_role_attribute(&buf, _("Bypass RLS"));
3221 
3222  conns = atoi(PQgetvalue(res, i, 6));
3223  if (conns >= 0)
3224  {
3225  if (buf.len > 0)
3226  appendPQExpBufferChar(&buf, '\n');
3227 
3228  if (conns == 0)
3229  appendPQExpBufferStr(&buf, _("No connections"));
3230  else
3231  appendPQExpBuffer(&buf, ngettext("%d connection",
3232  "%d connections",
3233  conns),
3234  conns);
3235  }
3236 
3237  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3238  {
3239  if (buf.len > 0)
3240  appendPQExpBufferChar(&buf, '\n');
3241  appendPQExpBufferStr(&buf, _("Password valid until "));
3242  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3243  }
3244 
3245  attr[i] = pg_strdup(buf.data);
3246 
3247  printTableAddCell(&cont, attr[i], false, false);
3248 
3249  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3250 
3251  if (verbose && pset.sversion >= 80200)
3252  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3253  }
3254  termPQExpBuffer(&buf);
3255 
3256  printTable(&cont, pset.queryFout, false, pset.logfile);
3257  printTableCleanup(&cont);
3258 
3259  for (i = 0; i < nrows; i++)
3260  free(attr[i]);
3261  free(attr);
3262 
3263  PQclear(res);
3264  return true;
3265 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
void printTableCleanup(printTableContent *const content)
Definition: print.c:3101
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
printTableOpt topt
Definition: print.h:165
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3268
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2970
static PGconn ** conns
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3010
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3190
static int verbose
Definition: pg_basebackup.c:85
#define ngettext(s, p, n)
Definition: c.h:991
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define free(a)
Definition: header.h:65
bool default_footer
Definition: print.h:110
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2933
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeSubscriptions()

bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 5347 of file describe.c.

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

Referenced by exec_command_d().

5348 {
5350  PGresult *res;
5351  printQueryOpt myopt = pset.popt;
5352  static const bool translate_columns[] = {false, false, false, false,
5353  false, false};
5354 
5355  if (pset.sversion < 100000)
5356  {
5357  char sverbuf[32];
5358 
5359  psql_error("The server (version %s) does not support subscriptions.\n",
5361  sverbuf, sizeof(sverbuf)));
5362  return true;
5363  }
5364 
5365  initPQExpBuffer(&buf);
5366 
5367  printfPQExpBuffer(&buf,
5368  "SELECT subname AS \"%s\"\n"
5369  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5370  ", subenabled AS \"%s\"\n"
5371  ", subpublications AS \"%s\"\n",
5372  gettext_noop("Name"),
5373  gettext_noop("Owner"),
5374  gettext_noop("Enabled"),
5375  gettext_noop("Publication"));
5376 
5377  if (verbose)
5378  {
5379  appendPQExpBuffer(&buf,
5380  ", subsynccommit AS \"%s\"\n"
5381  ", subconninfo AS \"%s\"\n",
5382  gettext_noop("Synchronous commit"),
5383  gettext_noop("Conninfo"));
5384  }
5385 
5386  /* Only display subscriptions in current database. */
5387  appendPQExpBufferStr(&buf,
5388  "FROM pg_catalog.pg_subscription\n"
5389  "WHERE subdbid = (SELECT oid\n"
5390  " FROM pg_catalog.pg_database\n"
5391  " WHERE datname = pg_catalog.current_database())");
5392 
5393  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5394  NULL, "subname", NULL,
5395  NULL);
5396 
5397  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5398 
5399  res = PSQLexec(buf.data);
5400  termPQExpBuffer(&buf);
5401  if (!res)
5402  return false;
5403 
5404  myopt.nullPrint = NULL;
5405  myopt.title = _("List of subscriptions");
5406  myopt.translate_header = true;
5407  myopt.translate_columns = translate_columns;
5408  myopt.n_translate_columns = lengthof(translate_columns);
5409 
5410  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5411 
5412  PQclear(res);
5413  return true;
5414 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeTableDetails()

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

Definition at line 1294 of file describe.c.

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

Referenced by exec_command_d().

1295 {
1297  PGresult *res;
1298  int i;
1299 
1300  initPQExpBuffer(&buf);
1301 
1302  printfPQExpBuffer(&buf,
1303  "SELECT c.oid,\n"
1304  " n.nspname,\n"
1305  " c.relname\n"
1306  "FROM pg_catalog.pg_class c\n"
1307  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1308 
1309  if (!showSystem && !pattern)
1310  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1311  " AND n.nspname <> 'information_schema'\n");
1312 
1313  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1314  "n.nspname", "c.relname", NULL,
1315  "pg_catalog.pg_table_is_visible(c.oid)");
1316 
1317  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1318 
1319  res = PSQLexec(buf.data);
1320  termPQExpBuffer(&buf);
1321  if (!res)
1322  return false;
1323 
1324  if (PQntuples(res) == 0)
1325  {
1326  if (!pset.quiet)
1327  {
1328  if (pattern)
1329  psql_error("Did not find any relation named \"%s\".\n",
1330  pattern);
1331  else
1332  psql_error("Did not find any relations.\n");
1333  }
1334  PQclear(res);
1335  return false;
1336  }
1337 
1338  for (i = 0; i < PQntuples(res); i++)
1339  {
1340  const char *oid;
1341  const char *nspname;
1342  const char *relname;
1343 
1344  oid = PQgetvalue(res, i, 0);
1345  nspname = PQgetvalue(res, i, 1);
1346  relname = PQgetvalue(res, i, 2);
1347 
1348  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1349  {
1350  PQclear(res);
1351  return false;
1352  }
1353  if (cancel_pressed)
1354  {
1355  PQclear(res);
1356  return false;
1357  }
1358  }
1359 
1360  PQclear(res);
1361  return true;
1362 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:67
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1372
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
void PQclear(PGresult *res)
Definition: fe-exec.c:671
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeTablespaces()

bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 208 of file describe.c.

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

Referenced by exec_command_d().

209 {
211  PGresult *res;
212  printQueryOpt myopt = pset.popt;
213 
214  if (pset.sversion < 80000)
215  {
216  char sverbuf[32];
217 
218  psql_error("The server (version %s) does not support tablespaces.\n",
220  sverbuf, sizeof(sverbuf)));
221  return true;
222  }
223 
224  initPQExpBuffer(&buf);
225 
226  if (pset.sversion >= 90200)
227  printfPQExpBuffer(&buf,
228  "SELECT spcname AS \"%s\",\n"
229  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
230  " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
231  gettext_noop("Name"),
232  gettext_noop("Owner"),
233  gettext_noop("Location"));
234  else
235  printfPQExpBuffer(&buf,
236  "SELECT spcname AS \"%s\",\n"
237  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
238  " spclocation AS \"%s\"",
239  gettext_noop("Name"),
240  gettext_noop("Owner"),
241  gettext_noop("Location"));
242 
243  if (verbose)
244  {
245  appendPQExpBufferStr(&buf, ",\n ");
246  printACLColumn(&buf, "spcacl");
247  }
248 
249  if (verbose && pset.sversion >= 90000)
250  appendPQExpBuffer(&buf,
251  ",\n spcoptions AS \"%s\"",
252  gettext_noop("Options"));
253 
254  if (verbose && pset.sversion >= 90200)
255  appendPQExpBuffer(&buf,
256  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"",
257  gettext_noop("Size"));
258 
259  if (verbose && pset.sversion >= 80200)
260  appendPQExpBuffer(&buf,
261  ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
262  gettext_noop("Description"));
263 
265  "\nFROM pg_catalog.pg_tablespace\n");
266 
267  processSQLNamePattern(pset.db, &buf, pattern, false, false,
268  NULL, "spcname", NULL,
269  NULL);
270 
271  appendPQExpBufferStr(&buf, "ORDER BY 1;");
272 
273  res = PSQLexec(buf.data);
274  termPQExpBuffer(&buf);
275  if (!res)
276  return false;
277 
278  myopt.nullPrint = NULL;
279  myopt.title = _("List of tablespaces");
280  myopt.translate_header = true;
281 
282  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
283 
284  PQclear(res);
285  return true;
286 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeTypes()

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

Definition at line 594 of file describe.c.

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

Referenced by exec_command_d().

595 {
597  PGresult *res;
598  printQueryOpt myopt = pset.popt;
599 
600  initPQExpBuffer(&buf);
601 
602  printfPQExpBuffer(&buf,
603  "SELECT n.nspname as \"%s\",\n"
604  " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
605  gettext_noop("Schema"),
606  gettext_noop("Name"));
607  if (verbose)
608  appendPQExpBuffer(&buf,
609  " t.typname AS \"%s\",\n"
610  " CASE WHEN t.typrelid != 0\n"
611  " THEN CAST('tuple' AS pg_catalog.text)\n"
612  " WHEN t.typlen < 0\n"
613  " THEN CAST('var' AS pg_catalog.text)\n"
614  " ELSE CAST(t.typlen AS pg_catalog.text)\n"
615  " END AS \"%s\",\n",
616  gettext_noop("Internal name"),
617  gettext_noop("Size"));
618  if (verbose && pset.sversion >= 80300)
619  {
621  " pg_catalog.array_to_string(\n"
622  " ARRAY(\n"
623  " SELECT e.enumlabel\n"
624  " FROM pg_catalog.pg_enum e\n"
625  " WHERE e.enumtypid = t.oid\n");
626 
627  if (pset.sversion >= 90100)
629  " ORDER BY e.enumsortorder\n");
630  else
632  " ORDER BY e.oid\n");
633 
634  appendPQExpBuffer(&buf,
635  " ),\n"
636  " E'\\n'\n"
637  " ) AS \"%s\",\n",
638  gettext_noop("Elements"));
639  }
640  if (verbose)
641  {
642  appendPQExpBuffer(&buf,
643  " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
644  gettext_noop("Owner"));
645  }
646  if (verbose && pset.sversion >= 90200)
647  {
648  printACLColumn(&buf, "t.typacl");
649  appendPQExpBufferStr(&buf, ",\n ");
650  }
651 
652  appendPQExpBuffer(&buf,
653  " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
654  gettext_noop("Description"));
655 
656  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
657  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
658 
659  /*
660  * do not include complex types (typrelid!=0) unless they are standalone
661  * composite types
662  */
663  appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
664  appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
665  " FROM pg_catalog.pg_class c "
666  "WHERE c.oid = t.typrelid))\n");
667 
668  /*
669  * do not include array types (before 8.3 we have to use the assumption
670  * that their names start with underscore)
671  */
672  if (pset.sversion >= 80300)
673  appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
674  else
675  appendPQExpBufferStr(&buf, " AND t.typname !~ '^_'\n");
676 
677  if (!showSystem && !pattern)
678  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
679  " AND n.nspname <> 'information_schema'\n");
680 
681  /* Match name pattern against either internal or external name */
682  processSQLNamePattern(pset.db, &buf, pattern, true, false,
683  "n.nspname", "t.typname",
684  "pg_catalog.format_type(t.oid, NULL)",
685  "pg_catalog.pg_type_is_visible(t.oid)");
686 
687  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
688 
689  res = PSQLexec(buf.data);
690  termPQExpBuffer(&buf);
691  if (!res)
692  return false;
693 
694  myopt.nullPrint = NULL;
695  myopt.title = _("List of data types");
696  myopt.translate_header = true;
697 
698  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
699 
700  PQclear(res);
701  return true;
702 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define RELKIND_COMPOSITE_TYPE
Definition: pg_class.h:166
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
#define CppAsString2(x)
Definition: c.h:216
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listAllDbs()

bool listAllDbs ( const char *  pattern,
bool  verbose 
)

Definition at line 787 of file describe.c.

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

Referenced by exec_command_list(), and main().

788 {
789  PGresult *res;
791  printQueryOpt myopt = pset.popt;
792 
793  initPQExpBuffer(&buf);
794 
795  printfPQExpBuffer(&buf,
796  "SELECT d.datname as \"%s\",\n"
797  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
798  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
799  gettext_noop("Name"),
800  gettext_noop("Owner"),
801  gettext_noop("Encoding"));
802  if (pset.sversion >= 80400)
803  appendPQExpBuffer(&buf,
804  " d.datcollate as \"%s\",\n"
805  " d.datctype as \"%s\",\n",
806  gettext_noop("Collate"),
807  gettext_noop("Ctype"));
808  appendPQExpBufferStr(&buf, " ");
809  printACLColumn(&buf, "d.datacl");
810  if (verbose && pset.sversion >= 80200)
811  appendPQExpBuffer(&buf,
812  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
813  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
814  " ELSE 'No Access'\n"
815  " END as \"%s\"",
816  gettext_noop("Size"));
817  if (verbose && pset.sversion >= 80000)
818  appendPQExpBuffer(&buf,
819  ",\n t.spcname as \"%s\"",
820  gettext_noop("Tablespace"));
821  if (verbose && pset.sversion >= 80200)
822  appendPQExpBuffer(&buf,
823  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
824  gettext_noop("Description"));
826  "\nFROM pg_catalog.pg_database d\n");
827  if (verbose && pset.sversion >= 80000)
829  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
830 
831  if (pattern)
832  processSQLNamePattern(pset.db, &buf, pattern, false, false,
833  NULL, "d.datname", NULL, NULL);
834 
835  appendPQExpBufferStr(&buf, "ORDER BY 1;");
836  res = PSQLexec(buf.data);
837  termPQExpBuffer(&buf);
838  if (!res)
839  return false;
840 
841  myopt.nullPrint = NULL;
842  myopt.title = _("List of databases");
843  myopt.translate_header = true;
844 
845  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
846 
847  PQclear(res);
848  return true;
849 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listCasts()

bool listCasts ( const char *  pattern,
bool  verbose 
)

Definition at line 3830 of file describe.c.

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

Referenced by exec_command_d().

3831 {
3833  PGresult *res;
3834  printQueryOpt myopt = pset.popt;
3835  static const bool translate_columns[] = {false, false, false, true, false};
3836 
3837  initPQExpBuffer(&buf);
3838 
3839  /*
3840  * We need a left join to pg_proc for binary casts; the others are just
3841  * paranoia. Also note that we don't attempt to localize '(binary
3842  * coercible)', because there's too much risk of gettext translating a
3843  * function name that happens to match some string in the PO database.
3844  */
3845  printfPQExpBuffer(&buf,
3846  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3847  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3848  " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3849  " ELSE p.proname\n"
3850  " END as \"%s\",\n"
3851  " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3852  " WHEN c.castcontext = 'a' THEN '%s'\n"
3853  " ELSE '%s'\n"
3854  " END as \"%s\"",
3855  gettext_noop("Source type"),
3856  gettext_noop("Target type"),
3857  gettext_noop("Function"),
3858  gettext_noop("no"),
3859  gettext_noop("in assignment"),
3860  gettext_noop("yes"),
3861  gettext_noop("Implicit?"));
3862 
3863  if (verbose)
3864  appendPQExpBuffer(&buf,
3865  ",\n d.description AS \"%s\"\n",
3866  gettext_noop("Description"));
3867 
3868  appendPQExpBufferStr(&buf,
3869  "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
3870  " ON c.castfunc = p.oid\n"
3871  " LEFT JOIN pg_catalog.pg_type ts\n"
3872  " ON c.castsource = ts.oid\n"
3873  " LEFT JOIN pg_catalog.pg_namespace ns\n"
3874  " ON ns.oid = ts.typnamespace\n"
3875  " LEFT JOIN pg_catalog.pg_type tt\n"
3876  " ON c.casttarget = tt.oid\n"
3877  " LEFT JOIN pg_catalog.pg_namespace nt\n"
3878  " ON nt.oid = tt.typnamespace\n");
3879 
3880  if (verbose)
3881  appendPQExpBufferStr(&buf,
3882  " LEFT JOIN pg_catalog.pg_description d\n"
3883  " ON d.classoid = c.tableoid AND d.objoid = "
3884  "c.oid AND d.objsubid = 0\n");
3885 
3886  appendPQExpBufferStr(&buf, "WHERE ( (true");
3887 
3888  /*
3889  * Match name pattern against either internal or external name of either
3890  * castsource or casttarget
3891  */
3892  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3893  "ns.nspname", "ts.typname",
3894  "pg_catalog.format_type(ts.oid, NULL)",
3895  "pg_catalog.pg_type_is_visible(ts.oid)");
3896 
3897  appendPQExpBufferStr(&buf, ") OR (true");
3898 
3899  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3900  "nt.nspname", "tt.typname",
3901  "pg_catalog.format_type(tt.oid, NULL)",
3902  "pg_catalog.pg_type_is_visible(tt.oid)");
3903 
3904  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
3905 
3906  res = PSQLexec(buf.data);
3907  termPQExpBuffer(&buf);
3908  if (!res)
3909  return false;
3910 
3911  myopt.nullPrint = NULL;
3912  myopt.title = _("List of casts");
3913  myopt.translate_header = true;
3914  myopt.translate_columns = translate_columns;
3915  myopt.n_translate_columns = lengthof(translate_columns);
3916 
3917  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3918 
3919  PQclear(res);
3920  return true;
3921 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listCollations()

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

Definition at line 3929 of file describe.c.

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

Referenced by exec_command_d().

3930 {
3932  PGresult *res;
3933  printQueryOpt myopt = pset.popt;
3934  static const bool translate_columns[] = {false, false, false, false, false, false};
3935 
3936  if (pset.sversion < 90100)
3937  {
3938  char sverbuf[32];
3939 
3940  psql_error("The server (version %s) does not support collations.\n",
3942  sverbuf, sizeof(sverbuf)));
3943  return true;
3944  }
3945 
3946  initPQExpBuffer(&buf);
3947 
3948  printfPQExpBuffer(&buf,
3949  "SELECT n.nspname AS \"%s\",\n"
3950  " c.collname AS \"%s\",\n"
3951  " c.collcollate AS \"%s\",\n"
3952  " c.collctype AS \"%s\"",
3953  gettext_noop("Schema"),
3954  gettext_noop("Name"),
3955  gettext_noop("Collate"),
3956  gettext_noop("Ctype"));
3957 
3958  if (pset.sversion >= 100000)
3959  appendPQExpBuffer(&buf,
3960  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
3961  gettext_noop("Provider"));
3962 
3963  if (verbose)
3964  appendPQExpBuffer(&buf,
3965  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
3966  gettext_noop("Description"));
3967 
3968  appendPQExpBufferStr(&buf,
3969  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
3970  "WHERE n.oid = c.collnamespace\n");
3971 
3972  if (!showSystem && !pattern)
3973  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3974  " AND n.nspname <> 'information_schema'\n");
3975 
3976  /*
3977  * Hide collations that aren't usable in the current database's encoding.
3978  * If you think to change this, note that pg_collation_is_visible rejects
3979  * unusable collations, so you will need to hack name pattern processing
3980  * somehow to avoid inconsistent behavior.
3981  */
3982  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
3983 
3984  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3985  "n.nspname", "c.collname", NULL,
3986  "pg_catalog.pg_collation_is_visible(c.oid)");
3987 
3988  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3989 
3990  res = PSQLexec(buf.data);
3991  termPQExpBuffer(&buf);
3992  if (!res)
3993  return false;
3994 
3995  myopt.nullPrint = NULL;
3996  myopt.title = _("List of collations");
3997  myopt.translate_header = true;
3998  myopt.translate_columns = translate_columns;
3999  myopt.n_translate_columns = lengthof(translate_columns);
4000 
4001  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4002 
4003  PQclear(res);
4004  return true;
4005 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listConversions()

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

Definition at line 3688 of file describe.c.

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

Referenced by exec_command_d().

3689 {
3691  PGresult *res;
3692  printQueryOpt myopt = pset.popt;
3693  static const bool translate_columns[] =
3694  {false, false, false, false, true, false};
3695 
3696  initPQExpBuffer(&buf);
3697 
3698  printfPQExpBuffer(&buf,
3699  "SELECT n.nspname AS \"%s\",\n"
3700  " c.conname AS \"%s\",\n"
3701  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
3702  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
3703  " CASE WHEN c.condefault THEN '%s'\n"
3704  " ELSE '%s' END AS \"%s\"",
3705  gettext_noop("Schema"),
3706  gettext_noop("Name"),
3707  gettext_noop("Source"),
3708  gettext_noop("Destination"),
3709  gettext_noop("yes"), gettext_noop("no"),
3710  gettext_noop("Default?"));
3711 
3712  if (verbose)
3713  appendPQExpBuffer(&buf,
3714  ",\n d.description AS \"%s\"",
3715  gettext_noop("Description"));
3716 
3717  appendPQExpBufferStr(&buf,
3718  "\nFROM pg_catalog.pg_conversion c\n"
3719  " JOIN pg_catalog.pg_namespace n "
3720  "ON n.oid = c.connamespace\n");
3721 
3722  if (verbose)
3723  appendPQExpBufferStr(&buf,
3724  "LEFT JOIN pg_catalog.pg_description d "
3725  "ON d.classoid = c.tableoid\n"
3726  " AND d.objoid = c.oid "
3727  "AND d.objsubid = 0\n");
3728 
3729  appendPQExpBufferStr(&buf, "WHERE true\n");
3730 
3731  if (!showSystem && !pattern)
3732  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3733  " AND n.nspname <> 'information_schema'\n");
3734 
3735  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3736  "n.nspname", "c.conname", NULL,
3737  "pg_catalog.pg_conversion_is_visible(c.oid)");
3738 
3739  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3740 
3741  res = PSQLexec(buf.data);
3742  termPQExpBuffer(&buf);
3743  if (!res)
3744  return false;
3745 
3746  myopt.nullPrint = NULL;
3747  myopt.title = _("List of conversions");
3748  myopt.translate_header = true;
3749  myopt.translate_columns = translate_columns;
3750  myopt.n_translate_columns = lengthof(translate_columns);
3751 
3752  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3753 
3754  PQclear(res);
3755  return true;
3756 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listDbRoleSettings()

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

Definition at line 3280 of file describe.c.

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

Referenced by exec_command_d().

3281 {
3283  PGresult *res;
3284  printQueryOpt myopt = pset.popt;
3285  bool havewhere;
3286 
3287  if (pset.sversion < 90000)
3288  {
3289  char sverbuf[32];
3290 
3291  psql_error("The server (version %s) does not support per-database role settings.\n",
3293  sverbuf, sizeof(sverbuf)));
3294  return true;
3295  }
3296 
3297  initPQExpBuffer(&buf);
3298 
3299  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3300  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3301  "FROM pg_catalog.pg_db_role_setting s\n"
3302  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3303  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3304  gettext_noop("Role"),
3305  gettext_noop("Database"),
3306  gettext_noop("Settings"));
3307  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3308  NULL, "r.rolname", NULL, NULL);
3309  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3310  NULL, "d.datname", NULL, NULL);
3311  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3312 
3313  res = PSQLexec(buf.data);
3314  termPQExpBuffer(&buf);
3315  if (!res)
3316  return false;
3317 
3318  /*
3319  * Most functions in this file are content to print an empty table when
3320  * there are no matching objects. We intentionally deviate from that
3321  * here, but only in !quiet mode, because of the possibility that the user
3322  * is confused about what the two pattern arguments mean.
3323  */
3324  if (PQntuples(res) == 0 && !pset.quiet)
3325  {
3326  if (pattern && pattern2)
3327  psql_error("Did not find any settings for role \"%s\" and database \"%s\".\n",
3328  pattern, pattern2);
3329  else if (pattern)
3330  psql_error("Did not find any settings for role \"%s\".\n",
3331  pattern);
3332  else
3333  psql_error("Did not find any settings.\n");
3334  }
3335  else
3336  {
3337  myopt.nullPrint = NULL;
3338  myopt.title = _("List of settings");
3339  myopt.translate_header = true;
3340 
3341  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3342  }
3343 
3344  PQclear(res);
3345  return true;
3346 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1017 of file describe.c.

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

Referenced by exec_command_d().

1018 {
1020  PGresult *res;
1021  printQueryOpt myopt = pset.popt;
1022  static const bool translate_columns[] = {false, false, true, false};
1023 
1024  if (pset.sversion < 90000)
1025  {
1026  char sverbuf[32];
1027 
1028  psql_error("The server (version %s) does not support altering default privileges.\n",
1030  sverbuf, sizeof(sverbuf)));
1031  return true;
1032  }
1033 
1034  initPQExpBuffer(&buf);
1035 
1036  printfPQExpBuffer(&buf,
1037  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1038  " n.nspname AS \"%s\",\n"
1039  " 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"
1040  " ",
1041  gettext_noop("Owner"),
1042  gettext_noop("Schema"),
1044  gettext_noop("table"),
1046  gettext_noop("sequence"),
1048  gettext_noop("function"),
1050  gettext_noop("type"),
1052  gettext_noop("schema"),
1053  gettext_noop("Type"));
1054 
1055  printACLColumn(&buf, "d.defaclacl");
1056 
1057  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1058  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1059 
1060  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1061  NULL,
1062  "n.nspname",
1063  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1064  NULL);
1065 
1066  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1067 
1068  res = PSQLexec(buf.data);
1069  if (!res)
1070  {
1071  termPQExpBuffer(&buf);
1072  return false;
1073  }
1074 
1075  myopt.nullPrint = NULL;
1076  printfPQExpBuffer(&buf, _("Default access privileges"));
1077  myopt.title = buf.data;
1078  myopt.translate_header = true;
1079  myopt.translate_columns = translate_columns;
1080  myopt.n_translate_columns = lengthof(translate_columns);
1081 
1082  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1083 
1084  termPQExpBuffer(&buf);
1085  PQclear(res);
1086  return true;
1087 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
#define DEFACLOBJ_SEQUENCE
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
#define DEFACLOBJ_TYPE
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
#define DEFACLOBJ_NAMESPACE
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DEFACLOBJ_RELATION
char * title
Definition: print.h:167
#define DEFACLOBJ_FUNCTION
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listDomains()

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

Definition at line 3602 of file describe.c.

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

Referenced by exec_command_d().

3603 {
3605  PGresult *res;
3606  printQueryOpt myopt = pset.popt;
3607 
3608  initPQExpBuffer(&buf);
3609 
3610  printfPQExpBuffer(&buf,
3611  "SELECT n.nspname as \"%s\",\n"
3612  " t.typname as \"%s\",\n"
3613  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
3614  gettext_noop("Schema"),
3615  gettext_noop("Name"),
3616  gettext_noop("Type"));
3617 
3618  if (pset.sversion >= 90100)
3619  appendPQExpBuffer(&buf,
3620  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
3621  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
3622  gettext_noop("Collation"));
3623  appendPQExpBuffer(&buf,
3624  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
3625  " t.typdefault as \"%s\",\n"
3626  " pg_catalog.array_to_string(ARRAY(\n"
3627  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
3628  " ), ' ') as \"%s\"",
3629  gettext_noop("Nullable"),
3630  gettext_noop("Default"),
3631  gettext_noop("Check"));
3632 
3633  if (verbose)
3634  {
3635  if (pset.sversion >= 90200)
3636  {
3637  appendPQExpBufferStr(&buf, ",\n ");
3638  printACLColumn(&buf, "t.typacl");
3639  }
3640  appendPQExpBuffer(&buf,
3641  ",\n d.description as \"%s\"",
3642  gettext_noop("Description"));
3643  }
3644 
3645  appendPQExpBufferStr(&buf,
3646  "\nFROM pg_catalog.pg_type t\n"
3647  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
3648 
3649  if (verbose)
3650  appendPQExpBufferStr(&buf,
3651  " LEFT JOIN pg_catalog.pg_description d "
3652  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
3653  "AND d.objsubid = 0\n");
3654 
3655  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
3656 
3657  if (!showSystem && !pattern)
3658  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3659  " AND n.nspname <> 'information_schema'\n");
3660 
3661  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3662  "n.nspname", "t.typname", NULL,
3663  "pg_catalog.pg_type_is_visible(t.oid)");
3664 
3665  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3666 
3667  res = PSQLexec(buf.data);
3668  termPQExpBuffer(&buf);
3669  if (!res)
3670  return false;
3671 
3672  myopt.nullPrint = NULL;
3673  myopt.title = _("List of domains");
3674  myopt.translate_header = true;
3675 
3676  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3677 
3678  PQclear(res);
3679  return true;
3680 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listEventTriggers()

bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 3764 of file describe.c.

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

Referenced by exec_command_d().

3765 {
3767  PGresult *res;
3768  printQueryOpt myopt = pset.popt;
3769  static const bool translate_columns[] =
3770  {false, false, false, true, false, false, false};
3771 
3772  initPQExpBuffer(&buf);
3773 
3774  printfPQExpBuffer(&buf,
3775  "SELECT evtname as \"%s\", "
3776  "evtevent as \"%s\", "
3777  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
3778  " case evtenabled when 'O' then '%s'"
3779  " when 'R' then '%s'"
3780  " when 'A' then '%s'"
3781  " when 'D' then '%s' end as \"%s\",\n"
3782  " e.evtfoid::pg_catalog.regproc as \"%s\", "
3783  "pg_catalog.array_to_string(array(select x"
3784  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
3785  gettext_noop("Name"),
3786  gettext_noop("Event"),
3787  gettext_noop("Owner"),
3788  gettext_noop("enabled"),
3789  gettext_noop("replica"),
3790  gettext_noop("always"),
3791  gettext_noop("disabled"),
3792  gettext_noop("Enabled"),
3793  gettext_noop("Procedure"),
3794  gettext_noop("Tags"));
3795  if (verbose)
3796  appendPQExpBuffer(&buf,
3797  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
3798  gettext_noop("Description"));
3799  appendPQExpBufferStr(&buf,
3800  "\nFROM pg_catalog.pg_event_trigger e ");
3801 
3802  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3803  NULL, "evtname", NULL, NULL);
3804 
3805  appendPQExpBufferStr(&buf, "ORDER BY 1");
3806 
3807  res = PSQLexec(buf.data);
3808  termPQExpBuffer(&buf);
3809  if (!res)
3810  return false;
3811 
3812  myopt.nullPrint = NULL;
3813  myopt.title = _("List of event triggers");
3814  myopt.translate_header = true;
3815  myopt.translate_columns = translate_columns;
3816  myopt.n_translate_columns = lengthof(translate_columns);
3817 
3818  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3819 
3820  PQclear(res);
3821  return true;
3822 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listExtensionContents()

bool listExtensionContents ( const char *  pattern)

Definition at line 5026 of file describe.c.

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

Referenced by exec_command_d().

5027 {
5029  PGresult *res;
5030  int i;
5031 
5032  if (pset.sversion < 90100)
5033  {
5034  char sverbuf[32];
5035 
5036  psql_error("The server (version %s) does not support extensions.\n",
5038  sverbuf, sizeof(sverbuf)));
5039  return true;
5040  }
5041 
5042  initPQExpBuffer(&buf);
5043  printfPQExpBuffer(&buf,
5044  "SELECT e.extname, e.oid\n"
5045  "FROM pg_catalog.pg_extension e\n");
5046 
5047  processSQLNamePattern(pset.db, &buf, pattern,
5048  false, false,
5049  NULL, "e.extname", NULL,
5050  NULL);
5051 
5052  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5053 
5054  res = PSQLexec(buf.data);
5055  termPQExpBuffer(&buf);
5056  if (!res)
5057  return false;
5058 
5059  if (PQntuples(res) == 0)
5060  {
5061  if (!pset.quiet)
5062  {
5063  if (pattern)
5064  psql_error("Did not find any extension named \"%s\".\n",
5065  pattern);
5066  else
5067  psql_error("Did not find any extensions.\n");
5068  }
5069  PQclear(res);
5070  return false;
5071  }
5072 
5073  for (i = 0; i < PQntuples(res); i++)
5074  {
5075  const char *extname;
5076  const char *oid;
5077 
5078  extname = PQgetvalue(res, i, 0);
5079  oid = PQgetvalue(res, i, 1);
5080 
5081  if (!listOneExtensionContents(extname, oid))
5082  {
5083  PQclear(res);
5084  return false;
5085  }
5086  if (cancel_pressed)
5087  {
5088  PQclear(res);
5089  return false;
5090  }
5091  }
5092 
5093  PQclear(res);
5094  return true;
5095 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:67
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5098
void psql_error(const char *fmt,...)
Definition: common.c:221
void PQclear(PGresult *res)
Definition: fe-exec.c:671
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listExtensions()

bool listExtensions ( const char *  pattern)

Definition at line 4969 of file describe.c.

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

Referenced by exec_command_d().

4970 {
4972  PGresult *res;
4973  printQueryOpt myopt = pset.popt;
4974 
4975  if (pset.sversion < 90100)
4976  {
4977  char sverbuf[32];
4978 
4979  psql_error("The server (version %s) does not support extensions.\n",
4981  sverbuf, sizeof(sverbuf)));
4982  return true;
4983  }
4984 
4985  initPQExpBuffer(&buf);
4986  printfPQExpBuffer(&buf,
4987  "SELECT e.extname AS \"%s\", "
4988  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4989  "FROM pg_catalog.pg_extension e "
4990  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4991  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4992  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4993  gettext_noop("Name"),
4994  gettext_noop("Version"),
4995  gettext_noop("Schema"),
4996  gettext_noop("Description"));
4997 
4998  processSQLNamePattern(pset.db, &buf, pattern,
4999  false, false,
5000  NULL, "e.extname", NULL,
5001  NULL);
5002 
5003  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5004 
5005  res = PSQLexec(buf.data);
5006  termPQExpBuffer(&buf);
5007  if (!res)
5008  return false;
5009 
5010  myopt.nullPrint = NULL;
5011  myopt.title = _("List of installed extensions");
5012  myopt.translate_header = true;
5013 
5014  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5015 
5016  PQclear(res);
5017  return true;
5018 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 4665 of file describe.c.

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

Referenced by exec_command_d().

4666 {
4668  PGresult *res;
4669  printQueryOpt myopt = pset.popt;
4670 
4671  if (pset.sversion < 80400)
4672  {
4673  char sverbuf[32];
4674 
4675  psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4677  sverbuf, sizeof(sverbuf)));
4678  return true;
4679  }
4680 
4681  initPQExpBuffer(&buf);
4682  printfPQExpBuffer(&buf,
4683  "SELECT fdw.fdwname AS \"%s\",\n"
4684  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4685  gettext_noop("Name"),
4686  gettext_noop("Owner"));
4687  if (pset.sversion >= 90100)
4688  appendPQExpBuffer(&buf,
4689  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4690  gettext_noop("Handler"));
4691  appendPQExpBuffer(&buf,
4692  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4693  gettext_noop("Validator"));
4694 
4695  if (verbose)
4696  {
4697  appendPQExpBufferStr(&buf, ",\n ");
4698  printACLColumn(&buf, "fdwacl");
4699  appendPQExpBuffer(&buf,
4700  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4701  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4702  " pg_catalog.quote_ident(option_name) || ' ' || "
4703  " pg_catalog.quote_literal(option_value) FROM "
4704  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
4705  " END AS \"%s\"",
4706  gettext_noop("FDW options"));
4707 
4708  if (pset.sversion >= 90100)
4709  appendPQExpBuffer(&buf,
4710  ",\n d.description AS \"%s\" ",
4711  gettext_noop("Description"));
4712  }
4713 
4714  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4715 
4716  if (verbose && pset.sversion >= 90100)
4717  appendPQExpBufferStr(&buf,
4718  "LEFT JOIN pg_catalog.pg_description d\n"
4719  " ON d.classoid = fdw.tableoid "
4720  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4721 
4722  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4723  NULL, "fdwname", NULL, NULL);
4724 
4725  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4726 
4727  res = PSQLexec(buf.data);
4728  termPQExpBuffer(&buf);
4729  if (!res)
4730  return false;
4731 
4732  myopt.nullPrint = NULL;
4733  myopt.title = _("List of foreign-data wrappers");
4734  myopt.translate_header = true;
4735 
4736  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4737 
4738  PQclear(res);
4739  return true;
4740 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listForeignServers()

bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 4748 of file describe.c.

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

Referenced by exec_command_d().

4749 {
4751  PGresult *res;
4752  printQueryOpt myopt = pset.popt;
4753 
4754  if (pset.sversion < 80400)
4755  {
4756  char sverbuf[32];
4757 
4758  psql_error("The server (version %s) does not support foreign servers.\n",
4760  sverbuf, sizeof(sverbuf)));
4761  return true;
4762  }
4763 
4764  initPQExpBuffer(&buf);
4765  printfPQExpBuffer(&buf,
4766  "SELECT s.srvname AS \"%s\",\n"
4767  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4768  " f.fdwname AS \"%s\"",
4769  gettext_noop("Name"),
4770  gettext_noop("Owner"),
4771  gettext_noop("Foreign-data wrapper"));
4772 
4773  if (verbose)
4774  {
4775  appendPQExpBufferStr(&buf, ",\n ");
4776  printACLColumn(&buf, "s.srvacl");
4777  appendPQExpBuffer(&buf,
4778  ",\n"
4779  " s.srvtype AS \"%s\",\n"
4780  " s.srvversion AS \"%s\",\n"
4781  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4782  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4783  " pg_catalog.quote_ident(option_name) || ' ' || "
4784  " pg_catalog.quote_literal(option_value) FROM "
4785  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
4786  " END AS \"%s\",\n"
4787  " d.description AS \"%s\"",
4788  gettext_noop("Type"),
4789  gettext_noop("Version"),
4790  gettext_noop("FDW options"),
4791  gettext_noop("Description"));
4792  }
4793 
4794  appendPQExpBufferStr(&buf,
4795  "\nFROM pg_catalog.pg_foreign_server s\n"
4796  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4797 
4798  if (verbose)
4799  appendPQExpBufferStr(&buf,
4800  "LEFT JOIN pg_catalog.pg_description d\n "
4801  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4802  "AND d.objsubid = 0\n");
4803 
4804  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4805  NULL, "s.srvname", NULL, NULL);
4806 
4807  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4808 
4809  res = PSQLexec(buf.data);
4810  termPQExpBuffer(&buf);
4811  if (!res)
4812  return false;
4813 
4814  myopt.nullPrint = NULL;
4815  myopt.title = _("List of foreign servers");
4816  myopt.translate_header = true;
4817 
4818  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4819 
4820  PQclear(res);
4821  return true;
4822 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listForeignTables()

bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 4891 of file describe.c.

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

Referenced by exec_command_d().

4892 {
4894  PGresult *res;
4895  printQueryOpt myopt = pset.popt;
4896 
4897  if (pset.sversion < 90100)
4898  {
4899  char sverbuf[32];
4900 
4901  psql_error("The server (version %s) does not support foreign tables.\n",
4903  sverbuf, sizeof(sverbuf)));
4904  return true;
4905  }
4906 
4907  initPQExpBuffer(&buf);
4908  printfPQExpBuffer(&buf,
4909  "SELECT n.nspname AS \"%s\",\n"
4910  " c.relname AS \"%s\",\n"
4911  " s.srvname AS \"%s\"",
4912  gettext_noop("Schema"),
4913  gettext_noop("Table"),
4914  gettext_noop("Server"));
4915 
4916  if (verbose)
4917  appendPQExpBuffer(&buf,
4918  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4919  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4920  " pg_catalog.quote_ident(option_name) || ' ' || "
4921  " pg_catalog.quote_literal(option_value) FROM "
4922  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
4923  " END AS \"%s\",\n"
4924  " d.description AS \"%s\"",
4925  gettext_noop("FDW options"),
4926  gettext_noop("Description"));
4927 
4928  appendPQExpBufferStr(&buf,
4929  "\nFROM pg_catalog.pg_foreign_table ft\n"
4930  " INNER JOIN pg_catalog.pg_class c"
4931  " ON c.oid = ft.ftrelid\n"
4932  " INNER JOIN pg_catalog.pg_namespace n"
4933  " ON n.oid = c.relnamespace\n"
4934  " INNER JOIN pg_catalog.pg_foreign_server s"
4935  " ON s.oid = ft.ftserver\n");
4936  if (verbose)
4937  appendPQExpBufferStr(&buf,
4938  " LEFT JOIN pg_catalog.pg_description d\n"
4939  " ON d.classoid = c.tableoid AND "
4940  "d.objoid = c.oid AND d.objsubid = 0\n");
4941 
4942  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4943  "n.nspname", "c.relname", NULL,
4944  "pg_catalog.pg_table_is_visible(c.oid)");
4945 
4946  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4947 
4948  res = PSQLexec(buf.data);
4949  termPQExpBuffer(&buf);
4950  if (!res)
4951  return false;
4952 
4953  myopt.nullPrint = NULL;
4954  myopt.title = _("List of foreign tables");
4955  myopt.translate_header = true;
4956 
4957  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4958 
4959  PQclear(res);
4960  return true;
4961 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listLanguages()

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

Definition at line 3527 of file describe.c.

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

Referenced by exec_command_d().

3528 {
3530  PGresult *res;
3531  printQueryOpt myopt = pset.popt;
3532 
3533  initPQExpBuffer(&buf);
3534 
3535  printfPQExpBuffer(&buf,
3536  "SELECT l.lanname AS \"%s\",\n",
3537  gettext_noop("Name"));
3538  if (pset.sversion >= 80300)
3539  appendPQExpBuffer(&buf,
3540  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
3541  gettext_noop("Owner"));
3542 
3543  appendPQExpBuffer(&buf,
3544  " l.lanpltrusted AS \"%s\"",
3545  gettext_noop("Trusted"));
3546 
3547  if (verbose)
3548  {
3549  appendPQExpBuffer(&buf,
3550  ",\n NOT l.lanispl AS \"%s\",\n"
3551  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
3552  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n ",
3553  gettext_noop("Internal language"),
3554  gettext_noop("Call handler"),
3555  gettext_noop("Validator"));
3556  if (pset.sversion >= 90000)
3557  appendPQExpBuffer(&buf, "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
3558  gettext_noop("Inline handler"));
3559  printACLColumn(&buf, "l.lanacl");
3560  }
3561 
3562  appendPQExpBuffer(&buf,
3563  ",\n d.description AS \"%s\""
3564  "\nFROM pg_catalog.pg_language l\n"
3565  "LEFT JOIN pg_catalog.pg_description d\n"
3566  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
3567  " AND d.objsubid = 0\n",
3568  gettext_noop("Description"));
3569 
3570  if (pattern)
3571  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3572  NULL, "l.lanname", NULL, NULL);
3573 
3574  if (!showSystem && !pattern)
3575  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
3576 
3577 
3578  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3579 
3580  res = PSQLexec(buf.data);
3581  termPQExpBuffer(&buf);
3582  if (!res)
3583  return false;
3584 
3585  myopt.nullPrint = NULL;
3586  myopt.title = _("List of languages");
3587  myopt.translate_header = true;
3588 
3589  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3590 
3591  PQclear(res);
3592  return true;
3593 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listPublications()

bool listPublications ( const char *  pattern)

Definition at line 5139 of file describe.c.

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

Referenced by exec_command_d().

5140 {
5142  PGresult *res;
5143  printQueryOpt myopt = pset.popt;
5144  static const bool translate_columns[] = {false, false, false, false, false, false};
5145 
5146  if (pset.sversion < 100000)
5147  {
5148  char sverbuf[32];
5149 
5150  psql_error("The server (version %s) does not support publications.\n",
5152  sverbuf, sizeof(sverbuf)));
5153  return true;
5154  }
5155 
5156  initPQExpBuffer(&buf);
5157 
5158  printfPQExpBuffer(&buf,
5159  "SELECT pubname AS \"%s\",\n"
5160  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5161  " puballtables AS \"%s\",\n"
5162  " pubinsert AS \"%s\",\n"
5163  " pubupdate AS \"%s\",\n"
5164  " pubdelete AS \"%s\"\n",
5165  gettext_noop("Name"),
5166  gettext_noop("Owner"),
5167  gettext_noop("All tables"),
5168  gettext_noop("Inserts"),
5169  gettext_noop("Updates"),
5170  gettext_noop("Deletes"));
5171 
5172  appendPQExpBufferStr(&buf,
5173  "\nFROM pg_catalog.pg_publication\n");
5174 
5175  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5176  NULL, "pubname", NULL,
5177  NULL);
5178 
5179  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5180 
5181  res = PSQLexec(buf.data);
5182  termPQExpBuffer(&buf);
5183  if (!res)
5184  return false;
5185 
5186  myopt.nullPrint = NULL;
5187  myopt.title = _("List of publications");
5188  myopt.translate_header = true;
5189  myopt.translate_columns = translate_columns;
5190  myopt.n_translate_columns = lengthof(translate_columns);
5191 
5192  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5193 
5194  PQclear(res);
5195 
5196  return true;
5197 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listSchemas()

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

Definition at line 4013 of file describe.c.

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

Referenced by exec_command_d().

4014 {
4016  PGresult *res;
4017  printQueryOpt myopt = pset.popt;
4018 
4019  initPQExpBuffer(&buf);
4020  printfPQExpBuffer(&buf,
4021  "SELECT n.nspname AS \"%s\",\n"
4022  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4023  gettext_noop("Name"),
4024  gettext_noop("Owner"));
4025 
4026  if (verbose)
4027  {
4028  appendPQExpBufferStr(&buf, ",\n ");
4029  printACLColumn(&buf, "n.nspacl");
4030  appendPQExpBuffer(&buf,
4031  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4032  gettext_noop("Description"));
4033  }
4034 
4035  appendPQExpBuffer(&buf,
4036  "\nFROM pg_catalog.pg_namespace n\n");
4037 
4038  if (!showSystem && !pattern)
4039  appendPQExpBufferStr(&buf,
4040  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
4041 
4042  processSQLNamePattern(pset.db, &buf, pattern,
4043  !showSystem && !pattern, false,
4044  NULL, "n.nspname", NULL,
4045  NULL);
4046 
4047  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4048 
4049  res = PSQLexec(buf.data);
4050  termPQExpBuffer(&buf);
4051  if (!res)
4052  return false;
4053 
4054  myopt.nullPrint = NULL;
4055  myopt.title = _("List of schemas");
4056  myopt.translate_header = true;
4057 
4058  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4059 
4060  PQclear(res);
4061  return true;
4062 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5424
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTables()

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

Definition at line 3364 of file describe.c.

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

Referenced by exec_command_d().

3365 {
3366  bool showTables = strchr(tabtypes, 't') != NULL;
3367  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3368  bool showViews = strchr(tabtypes, 'v') != NULL;
3369  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3370  bool showSeq = strchr(tabtypes, 's') != NULL;
3371  bool showForeign = strchr(tabtypes, 'E') != NULL;
3372 
3374  PGresult *res;
3375  printQueryOpt myopt = pset.popt;
3376  static const bool translate_columns[] = {false, false, true, false, false, false, false};
3377 
3378  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3379  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3380  showTables = showViews = showMatViews = showSeq = showForeign = true;
3381 
3382  initPQExpBuffer(&buf);
3383 
3384  /*
3385  * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
3386  * it here for backwards compatibility.
3387  */
3388  printfPQExpBuffer(&buf,
3389  "SELECT n.nspname as \"%s\",\n"
3390  " c.relname as \"%s\",\n"
3391  " CASE c.relkind"
3392  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3393  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3394  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3395  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3396  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3397  " WHEN 's' THEN '%s'"
3398  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3399  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3400  " END as \"%s\",\n"
3401  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3402  gettext_noop("Schema"),
3403  gettext_noop("Name"),
3404  gettext_noop("table"),
3405  gettext_noop("view"),
3406  gettext_noop("materialized view"),
3407  gettext_noop("index"),
3408  gettext_noop("sequence"),
3409  gettext_noop("special"),
3410  gettext_noop("foreign table"),
3411  gettext_noop("table"), /* partitioned table */
3412  gettext_noop("Type"),
3413  gettext_noop("Owner"));
3414 
3415  if (showIndexes)
3416  appendPQExpBuffer(&buf,
3417  ",\n c2.relname as \"%s\"",
3418  gettext_noop("Table"));
3419 
3420  if (verbose)
3421  {
3422  /*
3423  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3424  * size of a table, including FSM, VM and TOAST tables.
3425  */
3426  if (pset.sversion >= 90000)
3427  appendPQExpBuffer(&buf,
3428  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3429  gettext_noop("Size"));
3430  else if (pset.sversion >= 80100)
3431  appendPQExpBuffer(&buf,
3432  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3433  gettext_noop("Size"));
3434 
3435  appendPQExpBuffer(&buf,
3436  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3437  gettext_noop("Description"));
3438  }
3439 
3440  appendPQExpBufferStr(&buf,
3441  "\nFROM pg_catalog.pg_class c"
3442  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3443  if (showIndexes)
3444  appendPQExpBufferStr(&buf,
3445  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3446  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3447 
3448  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3449  if (showTables)
3452  if (showViews)
3454  if (showMatViews)
3456  if (showIndexes)
3458  if (showSeq)
3460  if (showSystem || pattern)
3461  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3462  if (showForeign)
3464 
3465  appendPQExpBufferStr(&buf, "''"); /* dummy */
3466  appendPQExpBufferStr(&buf, ")\n");
3467 
3468  if (!showSystem && !pattern)
3469  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3470  " AND n.nspname <> 'information_schema'\n");
3471 
3472  /*
3473  * TOAST objects are suppressed unconditionally. Since we don't provide
3474  * any way to select RELKIND_TOASTVALUE above, we would never show toast
3475  * tables in any case; it seems a bit confusing to allow their indexes to
3476  * be shown. Use plain \d if you really need to look at a TOAST
3477  * table/index.
3478  */
3479  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3480 
3481  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3482  "n.nspname", "c.relname", NULL,
3483  "pg_catalog.pg_table_is_visible(c.oid)");
3484 
3485  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3486 
3487  res = PSQLexec(buf.data);
3488  termPQExpBuffer(&buf);
3489  if (!res)
3490  return false;
3491 
3492  /*
3493  * Most functions in this file are content to print an empty table when
3494  * there are no matching objects. We intentionally deviate from that
3495  * here, but only in !quiet mode, for historical reasons.
3496  */
3497  if (PQntuples(res) == 0 && !pset.quiet)
3498  {
3499  if (pattern)
3500  psql_error("Did not find any relation named \"%s\".\n",
3501  pattern);
3502  else
3503  psql_error("Did not find any relations.\n");
3504  }
3505  else
3506  {
3507  myopt.nullPrint = NULL;
3508  myopt.title = _("List of relations");
3509  myopt.translate_header = true;
3510  myopt.translate_columns = translate_columns;
3511  myopt.n_translate_columns = lengthof(translate_columns);
3512 
3513  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3514  }
3515 
3516  PQclear(res);
3517  return true;
3518 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define RELKIND_MATVIEW
Definition: pg_class.h:165
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
#define CppAsString2(x)
Definition: c.h:216
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RELKIND_INDEX
Definition: pg_class.h:161
const bool * translate_columns
Definition: print.h:170
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSConfigs()

bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

Definition at line 4459 of file describe.c.

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

Referenced by exec_command_d().

4460 {
4462  PGresult *res;
4463  printQueryOpt myopt = pset.popt;
4464 
4465  if (pset.sversion < 80300)
4466  {
4467  char sverbuf[32];
4468 
4469  psql_error("The server (version %s) does not support full text search.\n",
4471  sverbuf, sizeof(sverbuf)));
4472  return true;
4473  }
4474 
4475  if (verbose)
4476  return listTSConfigsVerbose(pattern);
4477 
4478  initPQExpBuffer(&buf);
4479 
4480  printfPQExpBuffer(&buf,
4481  "SELECT\n"
4482  " n.nspname as \"%s\",\n"
4483  " c.cfgname as \"%s\",\n"
4484  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4485  "FROM pg_catalog.pg_ts_config c\n"
4486  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
4487  gettext_noop("Schema"),
4488  gettext_noop("Name"),
4489  gettext_noop("Description")
4490  );
4491 
4492  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4493  "n.nspname", "c.cfgname", NULL,
4494  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4495 
4496  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4497 
4498  res = PSQLexec(buf.data);
4499  termPQExpBuffer(&buf);
4500  if (!res)
4501  return false;
4502 
4503  myopt.nullPrint = NULL;
4504  myopt.title = _("List of text search configurations");
4505  myopt.translate_header = true;
4506 
4507  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4508 
4509  PQclear(res);
4510  return true;
4511 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:4514
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSDictionaries()

bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 4317 of file describe.c.

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

Referenced by exec_command_d().

4318 {
4320  PGresult *res;
4321  printQueryOpt myopt = pset.popt;
4322 
4323  if (pset.sversion < 80300)
4324  {
4325  char sverbuf[32];
4326 
4327  psql_error("The server (version %s) does not support full text search.\n",
4329  sverbuf, sizeof(sverbuf)));
4330  return true;
4331  }
4332 
4333  initPQExpBuffer(&buf);
4334 
4335  printfPQExpBuffer(&buf,
4336  "SELECT\n"
4337  " n.nspname as \"%s\",\n"
4338  " d.dictname as \"%s\",\n",
4339  gettext_noop("Schema"),
4340  gettext_noop("Name"));
4341 
4342  if (verbose)
4343  {
4344  appendPQExpBuffer(&buf,
4345  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
4346  " pg_catalog.pg_ts_template t\n"
4347  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
4348  " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
4349  " d.dictinitoption as \"%s\",\n",
4350  gettext_noop("Template"),
4351  gettext_noop("Init options"));
4352  }
4353 
4354  appendPQExpBuffer(&buf,
4355  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
4356  gettext_noop("Description"));
4357 
4358  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
4359  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
4360 
4361  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4362  "n.nspname", "d.dictname", NULL,
4363  "pg_catalog.pg_ts_dict_is_visible(d.oid)");
4364 
4365  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4366 
4367  res = PSQLexec(buf.data);
4368  termPQExpBuffer(&buf);
4369  if (!res)
4370  return false;
4371 
4372  myopt.nullPrint = NULL;
4373  myopt.title = _("List of text search dictionaries");
4374  myopt.translate_header = true;
4375 
4376  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4377 
4378  PQclear(res);
4379  return true;
4380 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSParsers()

bool listTSParsers ( const char *  pattern,
bool  verbose 
)

Definition at line 4070 of file describe.c.

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

Referenced by exec_command_d().

4071 {
4073  PGresult *res;
4074  printQueryOpt myopt = pset.popt;
4075 
4076  if (pset.sversion < 80300)
4077  {
4078  char sverbuf[32];
4079 
4080  psql_error("The server (version %s) does not support full text search.\n",
4082  sverbuf, sizeof(sverbuf)));
4083  return true;
4084  }
4085 
4086  if (verbose)
4087  return listTSParsersVerbose(pattern);
4088 
4089  initPQExpBuffer(&buf);
4090 
4091  printfPQExpBuffer(&buf,
4092  "SELECT\n"
4093  " n.nspname as \"%s\",\n"
4094  " p.prsname as \"%s\",\n"
4095  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
4096  "FROM pg_catalog.pg_ts_parser p\n"
4097  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
4098  gettext_noop("Schema"),
4099  gettext_noop("Name"),
4100  gettext_noop("Description")
4101  );
4102 
4103  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4104  "n.nspname", "p.prsname", NULL,
4105  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
4106 
4107  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4108 
4109  res = PSQLexec(buf.data);
4110  termPQExpBuffer(&buf);
4111  if (!res)
4112  return false;
4113 
4114  myopt.nullPrint = NULL;
4115  myopt.title = _("List of text search parsers");
4116  myopt.translate_header = true;
4117 
4118  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4119 
4120  PQclear(res);
4121  return true;
4122 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:4128
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSTemplates()

bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

Definition at line 4388 of file describe.c.

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

Referenced by exec_command_d().

4389 {
4391  PGresult *res;
4392  printQueryOpt myopt = pset.popt;
4393 
4394  if (pset.sversion < 80300)
4395  {
4396  char sverbuf[32];
4397 
4398  psql_error("The server (version %s) does not support full text search.\n",
4400  sverbuf, sizeof(sverbuf)));
4401  return true;
4402  }
4403 
4404  initPQExpBuffer(&buf);
4405 
4406  if (verbose)
4407  printfPQExpBuffer(&buf,
4408  "SELECT\n"
4409  " n.nspname AS \"%s\",\n"
4410  " t.tmplname AS \"%s\",\n"
4411  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4412  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4413  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4414  gettext_noop("Schema"),
4415  gettext_noop("Name"),
4416  gettext_noop("Init"),
4417  gettext_noop("Lexize"),
4418  gettext_noop("Description"));
4419  else
4420  printfPQExpBuffer(&buf,
4421  "SELECT\n"
4422  " n.nspname AS \"%s\",\n"
4423  " t.tmplname AS \"%s\",\n"
4424  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4425  gettext_noop("Schema"),
4426  gettext_noop("Name"),
4427  gettext_noop("Description"));
4428 
4429  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4430  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4431 
4432  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4433  "n.nspname", "t.tmplname", NULL,
4434  "pg_catalog.pg_ts_template_is_visible(t.oid)");
4435 
4436  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4437 
4438  res = PSQLexec(buf.data);
4439  termPQExpBuffer(&buf);
4440  if (!res)
4441  return false;
4442 
4443  myopt.nullPrint = NULL;
4444  myopt.title = _("List of text search templates");
4445  myopt.translate_header = true;
4446 
4447  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4448 
4449  PQclear(res);
4450  return true;
4451 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listUserMappings()

bool listUserMappings ( const char *  pattern,
bool  verbose 
)

Definition at line 4830 of file describe.c.

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

Referenced by exec_command_d().

4831 {
4833  PGresult *res;
4834  printQueryOpt myopt = pset.popt;
4835 
4836  if (pset.sversion < 80400)
4837  {
4838  char sverbuf[32];
4839 
4840  psql_error("The server (version %s) does not support user mappings.\n",
4842  sverbuf, sizeof(sverbuf)));
4843  return true;
4844  }
4845 
4846  initPQExpBuffer(&buf);
4847  printfPQExpBuffer(&buf,
4848  "SELECT um.srvname AS \"%s\",\n"
4849  " um.usename AS \"%s\"",
4850  gettext_noop("Server"),
4851  gettext_noop("User name"));
4852 
4853  if (verbose)
4854  appendPQExpBuffer(&buf,
4855  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4856  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4857  " pg_catalog.quote_ident(option_name) || ' ' || "
4858  " pg_catalog.quote_literal(option_value) FROM "
4859  " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
4860  " END AS \"%s\"",
4861  gettext_noop("FDW options"));
4862 
4863  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4864 
4865  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4866  NULL, "um.srvname", "um.usename", NULL);
4867 
4868  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4869 
4870  res = PSQLexec(buf.data);
4871  termPQExpBuffer(&buf);
4872  if (!res)
4873  return false;
4874 
4875  myopt.nullPrint = NULL;
4876  myopt.title = _("List of user mappings");
4877  myopt.translate_header = true;
4878 
4879  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4880 
4881  PQclear(res);
4882  return true;
4883 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:85
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ objectDescription()

bool objectDescription ( const char *  pattern,
bool  showSystem 
)

Definition at line 1102 of file describe.c.

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

Referenced by exec_command_d().

1103 {
1105  PGresult *res;
1106  printQueryOpt myopt = pset.popt;
1107  static const bool translate_columns[] = {false, false, true, false};
1108 
1109  initPQExpBuffer(&buf);
1110 
1111  appendPQExpBuffer(&buf,
1112  "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1113  "FROM (\n",
1114  gettext_noop("Schema"),
1115  gettext_noop("Name"),
1116  gettext_noop("Object"),
1117  gettext_noop("Description"));
1118 
1119  /* Table constraint descriptions */
1120  appendPQExpBuffer(&buf,
1121  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1122  " n.nspname as nspname,\n"
1123  " CAST(pgc.conname AS pg_catalog.text) as name,"
1124  " CAST('%s' AS pg_catalog.text) as object\n"
1125  " FROM pg_catalog.pg_constraint pgc\n"
1126  " JOIN pg_catalog.pg_class c "
1127  "ON c.oid = pgc.conrelid\n"
1128  " LEFT JOIN pg_catalog.pg_namespace n "
1129  " ON n.oid = c.relnamespace\n",
1130  gettext_noop("table constraint"));
1131 
1132  if (!showSystem && !pattern)
1133  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1134  " AND n.nspname <> 'information_schema'\n");
1135 
1136  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
1137  false, "n.nspname", "pgc.conname", NULL,
1138  "pg_catalog.pg_table_is_visible(c.oid)");
1139 
1140  /* Domain constraint descriptions */
1141  appendPQExpBuffer(&buf,
1142  "UNION ALL\n"
1143  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1144  " n.nspname as nspname,\n"
1145  " CAST(pgc.conname AS pg_catalog.text) as name,"
1146  " CAST('%s' AS pg_catalog.text) as object\n"
1147  " FROM pg_catalog.pg_constraint pgc\n"
1148  " JOIN pg_catalog.pg_type t "
1149  "ON t.oid = pgc.contypid\n"
1150  " LEFT JOIN pg_catalog.pg_namespace n "
1151  " ON n.oid = t.typnamespace\n",
1152  gettext_noop("domain constraint"));
1153 
1154  if (!showSystem && !pattern)
1155  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1156  " AND n.nspname <> 'information_schema'\n");
1157 
1158  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
1159  false, "n.nspname", "pgc.conname", NULL,
1160  "pg_catalog.pg_type_is_visible(t.oid)");
1161 
1162 
1163  /*
1164  * pg_opclass.opcmethod only available in 8.3+
1165  */
1166  if (pset.sversion >= 80300)
1167  {
1168  /* Operator class descriptions */
1169  appendPQExpBuffer(&buf,
1170  "UNION ALL\n"
1171  " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1172  " n.nspname as nspname,\n"
1173  " CAST(o.opcname AS pg_catalog.text) as name,\n"
1174  " CAST('%s' AS pg_catalog.text) as object\n"
1175  " FROM pg_catalog.pg_opclass o\n"
1176  " JOIN pg_catalog.pg_am am ON "
1177  "o.opcmethod = am.oid\n"
1178  " JOIN pg_catalog.pg_namespace n ON "
1179  "n.oid = o.opcnamespace\n",
1180  gettext_noop("operator class"));
1181 
1182  if (!showSystem && !pattern)
1183  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1184  " AND n.nspname <> 'information_schema'\n");
1185 
1186  processSQLNamePattern(pset.db, &buf, pattern, true, false,
1187  "n.nspname", "o.opcname", NULL,
1188  "pg_catalog.pg_opclass_is_visible(o.oid)");
1189  }
1190 
1191  /*
1192  * although operator family comments have been around since 8.3,
1193  * pg_opfamily_is_visible is only available in 9.2+
1194  */
1195  if (pset.sversion >= 90200)
1196  {
1197  /* Operator family descriptions */
1198  appendPQExpBuffer(&buf,
1199  "UNION ALL\n"
1200  " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1201  " n.nspname as nspname,\n"
1202  " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1203  " CAST('%s' AS pg_catalog.text) as object\n"
1204  " FROM pg_catalog.pg_opfamily opf\n"
1205  " JOIN pg_catalog.pg_am am "
1206  "ON opf.opfmethod = am.oid\n"
1207  " JOIN pg_catalog.pg_namespace n "
1208  "ON opf.opfnamespace = n.oid\n",
1209  gettext_noop("operator family"));
1210 
1211  if (!showSystem && !pattern)
1212  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1213  " AND n.nspname <> 'information_schema'\n");
1214 
1215  processSQLNamePattern(pset.db, &buf, pattern, true, false,
1216  "n.nspname", "opf.opfname", NULL,
1217  "pg_catalog.pg_opfamily_is_visible(opf.oid)");
1218  }
1219 
1220  /* Rule descriptions (ignore rules for views) */
1221  appendPQExpBuffer(&buf,
1222  "UNION ALL\n"
1223  " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1224  " n.nspname as nspname,\n"
1225  " CAST(r.rulename AS pg_catalog.text) as name,"
1226  " CAST('%s' AS pg_catalog.text) as object\n"
1227  " FROM pg_catalog.pg_rewrite r\n"
1228  " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1229  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1230  " WHERE r.rulename != '_RETURN'\n",
1231  gettext_noop("rule"));
1232 
1233  if (!showSystem && !pattern)
1234  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1235  " AND n.nspname <> 'information_schema'\n");
1236 
1237  processSQLNamePattern(pset.db, &buf, pattern, true, false,
1238  "n.nspname", "r.rulename", NULL,
1239  "pg_catalog.pg_table_is_visible(c.oid)");
1240 
1241  /* Trigger descriptions */
1242  appendPQExpBuffer(&buf,
1243  "UNION ALL\n"
1244  " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1245  " n.nspname as nspname,\n"
1246  " CAST(t.tgname AS pg_catalog.text) as name,"
1247  " CAST('%s' AS pg_catalog.text) as object\n"
1248  " FROM pg_catalog.pg_trigger t\n"
1249  " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1250  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1251  gettext_noop("trigger"));
1252 
1253  if (!showSystem && !pattern)
1254  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1255  " AND n.nspname <> 'information_schema'\n");
1256 
1257  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1258  "n.nspname", "t.tgname", NULL,
1259  "pg_catalog.pg_table_is_visible(c.oid)");
1260 
1261  appendPQExpBufferStr(&buf,
1262  ") AS tt\n"
1263  " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1264 
1265  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1266 
1267  res = PSQLexec(buf.data);
1268  termPQExpBuffer(&buf);
1269  if (!res)
1270  return false;
1271 
1272  myopt.nullPrint = NULL;
1273  myopt.title = _("Object descriptions");
1274  myopt.translate_header = true;
1275  myopt.translate_columns = translate_columns;
1276  myopt.n_translate_columns = lengthof(translate_columns);
1277 
1278  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1279 
1280  PQclear(res);
1281  return true;
1282 }
PGconn * db
Definition: settings.h:82
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1005
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:610
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ permissionsList()

bool permissionsList ( const char *  pattern)

Definition at line 857 of file describe.c.

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

Referenced by exec_command_d(), and exec_command_z().

858 {
860  PGresult *res;
861  printQueryOpt myopt = pset.popt;
862  static const bool translate_columns[] = {false, false, true, false, false, false};
863 
864  initPQExpBuffer(&buf);
865 
866  /*
867  * we ignore indexes and toast tables since they have no meaningful rights
868  */
869  printfPQExpBuffer(&buf,
870  "SELECT n.nspname as \"%s\",\n"
871  " c.relname as \"%s\",\n"
872  " CASE c.relkind"
873  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
874  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
875  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
876  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
877  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
878  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
879  " END as \"%s\",\n"
880  " ",
881  gettext_noop("Schema"),
882  gettext_noop("Name"),
883  gettext_noop("table"),
884  gettext_noop("view"),
885  gettext_noop("materialized view"),
886  gettext_noop("sequence"),
887  gettext_noop("foreign table"),
888  gettext_noop("table"), /* partitioned table */
889  gettext_noop("Type"));
890 
891  printACLColumn(&buf, "c.relacl");
892 
893  if (pset.sversion >= 80400)
894  appendPQExpBuffer(&buf,
895  ",\n pg_catalog.array_to_string(ARRAY(\n"
896  " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
897  " FROM pg_catalog.pg_attribute a\n"
898  " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
899  " ), E'\\n') AS \"%s\"",
900  gettext_noop("Column privileges"));
901 
902  if (pset.sversion >= 90500 && pset.sversion < 100000)
903  appendPQExpBuffer(&buf,
904  ",\n pg_catalog.array_to_string(ARRAY(\n"
905  " SELECT polname\n"
906  " || CASE WHEN polcmd != '*' THEN\n"
907  " E' (' || polcmd || E'):'\n"
908  " ELSE E':'\n"
909  " END\n"
910  " || CASE WHEN polqual IS NOT NULL THEN\n"
911  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
912  " ELSE E''\n"
913  " END\n"
914  " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
915  " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
916  " ELSE E''\n"
917  " END"
918  " || CASE WHEN polroles <> '{0}' THEN\n"
919  " E'\\n to: ' || pg_catalog.array_to_string(\n"
920  " ARRAY(\n"
921  " SELECT rolname\n"
922  " FROM pg_catalog.pg_roles\n"
923  " WHERE oid = ANY (polroles)\n"
924  " ORDER BY 1\n"
925  " ), E', ')\n"
926  " ELSE E''\n"
927  " END\n"
928  " FROM pg_catalog.pg_policy pol\n"
929  " WHERE polrelid = c.oid), E'\\n')\n"
930  " AS \"%s\"",
931  gettext_noop("Policies"));
932 
933  if (pset.sversion >= 100000)
934  appendPQExpBuffer(&buf,
935  ",\n pg_catalog.array_to_string(ARRAY(\n"
936  " SELECT polname\n"
937  " || CASE WHEN NOT polpermissive THEN\n"
938  " E' (RESTRICTIVE)'\n"
939  " ELSE '' END\n"
940  " || CASE WHEN polcmd != '*' THEN\n"
941  " E' (' || polcmd || E'):'\n"
942  " ELSE E':'\n"
943  " END\n"
944  " || CASE WHEN polqual IS NOT NULL THEN\n"
945  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
946  " ELSE E''\n"
947  " END\n"
948  " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
949  " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
950  " ELSE E''\n"
951  " END"
952  " || CASE WHEN polroles <> '{0}' THEN\n"
953  " E'\\n to: ' || pg_catalog.array_to_string(\n"
954  " ARRAY(\n"
955  " SELECT rolname\n"
956  " FROM pg_catalog.pg_roles\n"
957  " WHERE oid = ANY (polroles)\n"
958  " ORDER BY 1\n"
959  " ), E', ')\n"
960  " ELSE E''\n"
961  " END\n"