PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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:139
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:556
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
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:139
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
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 = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
357  " ELSE '%s'\n"
358  " END as \"%s\"",
359  gettext_noop("Result data type"),
360  gettext_noop("Argument data types"),
361  /* translator: "agg" is short for "aggregate" */
362  gettext_noop("agg"),
363  gettext_noop("window"),
364  gettext_noop("trigger"),
365  gettext_noop("normal"),
366  gettext_noop("Type"));
367  else if (pset.sversion >= 80100)
368  appendPQExpBuffer(&buf,
369  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
370  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
371  " CASE WHEN proallargtypes IS NOT NULL THEN\n"
372  " pg_catalog.array_to_string(ARRAY(\n"
373  " SELECT\n"
374  " CASE\n"
375  " WHEN p.proargmodes[s.i] = 'i' THEN ''\n"
376  " WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n"
377  " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n"
378  " WHEN p.proargmodes[s.i] = 'v' THEN 'VARIADIC '\n"
379  " END ||\n"
380  " CASE\n"
381  " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n"
382  " ELSE p.proargnames[s.i] || ' '\n"
383  " END ||\n"
384  " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n"
385  " FROM\n"
386  " pg_catalog.generate_series(1, pg_catalog.array_upper(p.proallargtypes, 1)) AS s(i)\n"
387  " ), ', ')\n"
388  " ELSE\n"
389  " pg_catalog.array_to_string(ARRAY(\n"
390  " SELECT\n"
391  " CASE\n"
392  " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n"
393  " ELSE p.proargnames[s.i+1] || ' '\n"
394  " END ||\n"
395  " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
396  " FROM\n"
397  " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
398  " ), ', ')\n"
399  " END AS \"%s\",\n"
400  " CASE\n"
401  " WHEN p.proisagg THEN '%s'\n"
402  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
403  " ELSE '%s'\n"
404  " END AS \"%s\"",
405  gettext_noop("Result data type"),
406  gettext_noop("Argument data types"),
407  /* translator: "agg" is short for "aggregate" */
408  gettext_noop("agg"),
409  gettext_noop("trigger"),
410  gettext_noop("normal"),
411  gettext_noop("Type"));
412  else
413  appendPQExpBuffer(&buf,
414  " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
415  " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
416  " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
417  " CASE\n"
418  " WHEN p.proisagg THEN '%s'\n"
419  " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
420  " ELSE '%s'\n"
421  " END AS \"%s\"",
422  gettext_noop("Result data type"),
423  gettext_noop("Argument data types"),
424  /* translator: "agg" is short for "aggregate" */
425  gettext_noop("agg"),
426  gettext_noop("trigger"),
427  gettext_noop("normal"),
428  gettext_noop("Type"));
429 
430  if (verbose)
431  {
432  appendPQExpBuffer(&buf,
433  ",\n CASE\n"
434  " WHEN p.provolatile = 'i' THEN '%s'\n"
435  " WHEN p.provolatile = 's' THEN '%s'\n"
436  " WHEN p.provolatile = 'v' THEN '%s'\n"
437  " END as \"%s\"",
438  gettext_noop("immutable"),
439  gettext_noop("stable"),
440  gettext_noop("volatile"),
441  gettext_noop("Volatility"));
442  if (pset.sversion >= 90600)
443  appendPQExpBuffer(&buf,
444  ",\n CASE\n"
445  " WHEN p.proparallel = 'r' THEN '%s'\n"
446  " WHEN p.proparallel = 's' THEN '%s'\n"
447  " WHEN p.proparallel = 'u' THEN '%s'\n"
448  " END as \"%s\"",
449  gettext_noop("restricted"),
450  gettext_noop("safe"),
451  gettext_noop("unsafe"),
452  gettext_noop("Parallel"));
453  appendPQExpBuffer(&buf,
454  ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
455  ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
456  gettext_noop("Owner"),
457  gettext_noop("definer"),
458  gettext_noop("invoker"),
459  gettext_noop("Security"));
460  appendPQExpBufferStr(&buf, ",\n ");
461  printACLColumn(&buf, "p.proacl");
462  appendPQExpBuffer(&buf,
463  ",\n l.lanname as \"%s\""
464  ",\n p.prosrc as \"%s\""
465  ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
466  gettext_noop("Language"),
467  gettext_noop("Source code"),
468  gettext_noop("Description"));
469  }
470 
472  "\nFROM pg_catalog.pg_proc p"
473  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
474 
475  if (verbose)
477  " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
478 
479  have_where = false;
480 
481  /* filter by function type, if requested */
482  if (showNormal && showAggregate && showTrigger && showWindow)
483  /* Do nothing */ ;
484  else if (showNormal)
485  {
486  if (!showAggregate)
487  {
488  if (have_where)
489  appendPQExpBufferStr(&buf, " AND ");
490  else
491  {
492  appendPQExpBufferStr(&buf, "WHERE ");
493  have_where = true;
494  }
495  appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
496  }
497  if (!showTrigger)
498  {
499  if (have_where)
500  appendPQExpBufferStr(&buf, " AND ");
501  else
502  {
503  appendPQExpBufferStr(&buf, "WHERE ");
504  have_where = true;
505  }
506  appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
507  }
508  if (!showWindow && pset.sversion >= 80400)
509  {
510  if (have_where)
511  appendPQExpBufferStr(&buf, " AND ");
512  else
513  {
514  appendPQExpBufferStr(&buf, "WHERE ");
515  have_where = true;
516  }
517  appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
518  }
519  }
520  else
521  {
522  bool needs_or = false;
523 
524  appendPQExpBufferStr(&buf, "WHERE (\n ");
525  have_where = true;
526  /* Note: at least one of these must be true ... */
527  if (showAggregate)
528  {
529  appendPQExpBufferStr(&buf, "p.proisagg\n");
530  needs_or = true;
531  }
532  if (showTrigger)
533  {
534  if (needs_or)
535  appendPQExpBufferStr(&buf, " OR ");
537  "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
538  needs_or = true;
539  }
540  if (showWindow)
541  {
542  if (needs_or)
543  appendPQExpBufferStr(&buf, " OR ");
544  appendPQExpBufferStr(&buf, "p.proiswindow\n");
545  needs_or = true;
546  }
547  appendPQExpBufferStr(&buf, " )\n");
548  }
549 
550  processSQLNamePattern(pset.db, &buf, pattern, have_where, false,
551  "n.nspname", "p.proname", NULL,
552  "pg_catalog.pg_function_is_visible(p.oid)");
553 
554  if (!showSystem && !pattern)
555  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
556  " AND n.nspname <> 'information_schema'\n");
557 
558  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
559 
560  res = PSQLexec(buf.data);
561  termPQExpBuffer(&buf);
562  if (!res)
563  return false;
564 
565  myopt.nullPrint = NULL;
566  myopt.title = _("List of functions");
567  myopt.translate_header = true;
568  if (pset.sversion >= 90600)
569  {
570  myopt.translate_columns = translate_columns;
571  myopt.n_translate_columns = lengthof(translate_columns);
572  }
573  else
574  {
575  myopt.translate_columns = translate_columns_pre_96;
576  myopt.n_translate_columns = lengthof(translate_columns_pre_96);
577  }
578 
579  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
580 
581  PQclear(res);
582  return true;
583 }
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:139
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:556
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:5399
#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
bool describeOperators ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

709 {
711  PGresult *res;
712  printQueryOpt myopt = pset.popt;
713 
714  initPQExpBuffer(&buf);
715 
716  /*
717  * Note: before Postgres 9.1, we did not assign comments to any built-in
718  * operators, preferring to let the comment on the underlying function
719  * suffice. The coalesce() on the obj_description() calls below supports
720  * this convention by providing a fallback lookup of a comment on the
721  * operator's function. As of 9.1 there is a policy that every built-in
722  * operator should have a comment; so the coalesce() is no longer
723  * necessary so far as built-in operators are concerned. We keep it
724  * anyway, for now, because (1) third-party modules may still be following
725  * the old convention, and (2) we'd need to do it anyway when talking to a
726  * pre-9.1 server.
727  */
728 
729  printfPQExpBuffer(&buf,
730  "SELECT n.nspname as \"%s\",\n"
731  " o.oprname AS \"%s\",\n"
732  " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
733  " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
734  " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
735  gettext_noop("Schema"),
736  gettext_noop("Name"),
737  gettext_noop("Left arg type"),
738  gettext_noop("Right arg type"),
739  gettext_noop("Result type"));
740 
741  if (verbose)
742  appendPQExpBuffer(&buf,
743  " o.oprcode AS \"%s\",\n",
744  gettext_noop("Function"));
745 
746  appendPQExpBuffer(&buf,
747  " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
748  " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
749  "FROM pg_catalog.pg_operator o\n"
750  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
751  gettext_noop("Description"));
752 
753  if (!showSystem && !pattern)
754  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
755  " AND n.nspname <> 'information_schema'\n");
756 
757  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
758  "n.nspname", "o.oprname", NULL,
759  "pg_catalog.pg_operator_is_visible(o.oid)");
760 
761  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
762 
763  res = PSQLexec(buf.data);
764  termPQExpBuffer(&buf);
765  if (!res)
766  return false;
767 
768  myopt.nullPrint = NULL;
769  myopt.title = _("List of operators");
770  myopt.translate_header = true;
771 
772  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
773 
774  PQclear(res);
775  return true;
776 }
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:139
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
bool describePublications ( const char *  pattern)

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

5182 {
5184  int i;
5185  PGresult *res;
5186 
5187  if (pset.sversion < 100000)
5188  {
5189  char sverbuf[32];
5190 
5191  psql_error("The server (version %s) does not support publications.\n",
5193  sverbuf, sizeof(sverbuf)));
5194  return true;
5195  }
5196 
5197  initPQExpBuffer(&buf);
5198 
5199  printfPQExpBuffer(&buf,
5200  "SELECT oid, pubname,\n"
5201  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
5202  " puballtables, pubinsert, pubupdate, pubdelete\n"
5203  "FROM pg_catalog.pg_publication\n");
5204 
5205  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5206  NULL, "pubname", NULL,
5207  NULL);
5208 
5209  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5210 
5211  res = PSQLexec(buf.data);
5212  if (!res)
5213  {
5214  termPQExpBuffer(&buf);
5215  return false;
5216  }
5217 
5218  if (PQntuples(res) == 0)
5219  {
5220  if (!pset.quiet)
5221  {
5222  if (pattern)
5223  psql_error("Did not find any publication named \"%s\".\n",
5224  pattern);
5225  else
5226  psql_error("Did not find any publications.\n");
5227  }
5228 
5229  termPQExpBuffer(&buf);
5230  PQclear(res);
5231  return false;
5232  }
5233 
5234  for (i = 0; i < PQntuples(res); i++)
5235  {
5236  const char align = 'l';
5237  int ncols = 5;
5238  int nrows = 1;
5239  int tables = 0;
5240  PGresult *tabres;
5241  char *pubid = PQgetvalue(res, i, 0);
5242  char *pubname = PQgetvalue(res, i, 1);
5243  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
5244  int j;
5245  PQExpBufferData title;
5246  printTableOpt myopt = pset.popt.topt;
5247  printTableContent cont;
5248 
5249  initPQExpBuffer(&title);
5250  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5251  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5252 
5253  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
5254  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
5255  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5256  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5257  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5258 
5259  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
5260  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5261  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5262  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5263  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
5264 
5265  if (!puballtables)
5266  {
5267  printfPQExpBuffer(&buf,
5268  "SELECT n.nspname, c.relname\n"
5269  "FROM pg_catalog.pg_class c,\n"
5270  " pg_catalog.pg_namespace n,\n"
5271  " pg_catalog.pg_publication_rel pr\n"
5272  "WHERE c.relnamespace = n.oid\n"
5273  " AND c.oid = pr.prrelid\n"
5274  " AND pr.prpubid = '%s'\n"
5275  "ORDER BY 1,2", pubid);
5276 
5277  tabres = PSQLexec(buf.data);
5278  if (!tabres)
5279  {
5280  printTableCleanup(&cont);
5281  PQclear(res);
5282  termPQExpBuffer(&buf);
5283  termPQExpBuffer(&title);
5284  return false;
5285  }
5286  else
5287  tables = PQntuples(tabres);
5288 
5289  if (tables > 0)
5290  printTableAddFooter(&cont, _("Tables:"));
5291 
5292  for (j = 0; j < tables; j++)
5293  {
5294  printfPQExpBuffer(&buf, " \"%s.%s\"",
5295  PQgetvalue(tabres, j, 0),
5296  PQgetvalue(tabres, j, 1));
5297 
5298  printTableAddFooter(&cont, buf.data);
5299  }
5300  PQclear(tabres);
5301  }
5302 
5303  printTable(&cont, pset.queryFout, false, pset.logfile);
5304  printTableCleanup(&cont);
5305 
5306  termPQExpBuffer(&title);
5307  }
5308 
5309  termPQExpBuffer(&buf);
5310  PQclear(res);
5311 
5312  return true;
5313 }
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:139
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
bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3085 {
3087  PGresult *res;
3088  printTableContent cont;
3089  printTableOpt myopt = pset.popt.topt;
3090  int ncols = 3;
3091  int nrows = 0;
3092  int i;
3093  int conns;
3094  const char align = 'l';
3095  char **attr;
3096 
3097  myopt.default_footer = false;
3098 
3099  initPQExpBuffer(&buf);
3100 
3101  if (pset.sversion >= 80100)
3102  {
3103  printfPQExpBuffer(&buf,
3104  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3105  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3106  " r.rolconnlimit, r.rolvaliduntil,\n"
3107  " ARRAY(SELECT b.rolname\n"
3108  " FROM pg_catalog.pg_auth_members m\n"
3109  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3110  " WHERE m.member = r.oid) as memberof");
3111 
3112  if (verbose && pset.sversion >= 80200)
3113  {
3114  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3115  ncols++;
3116  }
3117  if (pset.sversion >= 90100)
3118  {
3119  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3120  }
3121 
3122  if (pset.sversion >= 90500)
3123  {
3124  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3125  }
3126 
3127  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3128 
3129  if (!showSystem && !pattern)
3130  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3131 
3132  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3133  NULL, "r.rolname", NULL, NULL);
3134  }
3135  else
3136  {
3137  printfPQExpBuffer(&buf,
3138  "SELECT u.usename AS rolname,\n"
3139  " u.usesuper AS rolsuper,\n"
3140  " true AS rolinherit, false AS rolcreaterole,\n"
3141  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3142  " -1 AS rolconnlimit,"
3143  " u.valuntil as rolvaliduntil,\n"
3144  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3145  "\nFROM pg_catalog.pg_user u\n");
3146 
3147  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3148  NULL, "u.usename", NULL, NULL);
3149  }
3150 
3151  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3152 
3153  res = PSQLexec(buf.data);
3154  if (!res)
3155  return false;
3156 
3157  nrows = PQntuples(res);
3158  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3159 
3160  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3161 
3162  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3163  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3164  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3165 
3166  if (verbose && pset.sversion >= 80200)
3167  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3168 
3169  for (i = 0; i < nrows; i++)
3170  {
3171  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3172 
3173  resetPQExpBuffer(&buf);
3174  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3175  add_role_attribute(&buf, _("Superuser"));
3176 
3177  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3178  add_role_attribute(&buf, _("No inheritance"));
3179 
3180  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3181  add_role_attribute(&buf, _("Create role"));
3182 
3183  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3184  add_role_attribute(&buf, _("Create DB"));
3185 
3186  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3187  add_role_attribute(&buf, _("Cannot login"));
3188 
3189  if (pset.sversion >= 90100)
3190  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3191  add_role_attribute(&buf, _("Replication"));
3192 
3193  if (pset.sversion >= 90500)
3194  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3195  add_role_attribute(&buf, _("Bypass RLS"));
3196 
3197  conns = atoi(PQgetvalue(res, i, 6));
3198  if (conns >= 0)
3199  {
3200  if (buf.len > 0)
3201  appendPQExpBufferChar(&buf, '\n');
3202 
3203  if (conns == 0)
3204  appendPQExpBufferStr(&buf, _("No connections"));
3205  else
3206  appendPQExpBuffer(&buf, ngettext("%d connection",
3207  "%d connections",
3208  conns),
3209  conns);
3210  }
3211 
3212  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3213  {
3214  if (buf.len > 0)
3215  appendPQExpBufferChar(&buf, '\n');
3216  appendPQExpBufferStr(&buf, _("Password valid until "));
3217  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3218  }
3219 
3220  attr[i] = pg_strdup(buf.data);
3221 
3222  printTableAddCell(&cont, attr[i], false, false);
3223 
3224  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3225 
3226  if (verbose && pset.sversion >= 80200)
3227  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3228  }
3229  termPQExpBuffer(&buf);
3230 
3231  printTable(&cont, pset.queryFout, false, pset.logfile);
3232  printTableCleanup(&cont);
3233 
3234  for (i = 0; i < nrows; i++)
3235  free(attr[i]);
3236  free(attr);
3237 
3238  PQclear(res);
3239  return true;
3240 }
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:139
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:3243
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:127
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
bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

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

5323 {
5325  PGresult *res;
5326  printQueryOpt myopt = pset.popt;
5327  static const bool translate_columns[] = {false, false, false, false,
5328  false, false};
5329 
5330  if (pset.sversion < 100000)
5331  {
5332  char sverbuf[32];
5333 
5334  psql_error("The server (version %s) does not support subscriptions.\n",
5336  sverbuf, sizeof(sverbuf)));
5337  return true;
5338  }
5339 
5340  initPQExpBuffer(&buf);
5341 
5342  printfPQExpBuffer(&buf,
5343  "SELECT subname AS \"%s\"\n"
5344  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5345  ", subenabled AS \"%s\"\n"
5346  ", subpublications AS \"%s\"\n",
5347  gettext_noop("Name"),
5348  gettext_noop("Owner"),
5349  gettext_noop("Enabled"),
5350  gettext_noop("Publication"));
5351 
5352  if (verbose)
5353  {
5354  appendPQExpBuffer(&buf,
5355  ", subsynccommit AS \"%s\"\n"
5356  ", subconninfo AS \"%s\"\n",
5357  gettext_noop("Synchronous commit"),
5358  gettext_noop("Conninfo"));
5359  }
5360 
5361  /* Only display subscriptions in current database. */
5362  appendPQExpBufferStr(&buf,
5363  "FROM pg_catalog.pg_subscription\n"
5364  "WHERE subdbid = (SELECT oid\n"
5365  " FROM pg_catalog.pg_database\n"
5366  " WHERE datname = current_database())");
5367 
5368  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5369  NULL, "subname", NULL,
5370  NULL);
5371 
5372  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5373 
5374  res = PSQLexec(buf.data);
5375  termPQExpBuffer(&buf);
5376  if (!res)
5377  return false;
5378 
5379  myopt.nullPrint = NULL;
5380  myopt.title = _("List of subscriptions");
5381  myopt.translate_header = true;
5382  myopt.translate_columns = translate_columns;
5383  myopt.n_translate_columns = lengthof(translate_columns);
5384 
5385  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5386 
5387  PQclear(res);
5388  return true;
5389 }
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:139
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:556
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
bool describeTableDetails ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

1293 {
1295  PGresult *res;
1296  int i;
1297 
1298  initPQExpBuffer(&buf);
1299 
1300  printfPQExpBuffer(&buf,
1301  "SELECT c.oid,\n"
1302  " n.nspname,\n"
1303  " c.relname\n"
1304  "FROM pg_catalog.pg_class c\n"
1305  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1306 
1307  if (!showSystem && !pattern)
1308  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1309  " AND n.nspname <> 'information_schema'\n");
1310 
1311  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1312  "n.nspname", "c.relname", NULL,
1313  "pg_catalog.pg_table_is_visible(c.oid)");
1314 
1315  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1316 
1317  res = PSQLexec(buf.data);
1318  termPQExpBuffer(&buf);
1319  if (!res)
1320  return false;
1321 
1322  if (PQntuples(res) == 0)
1323  {
1324  if (!pset.quiet)
1325  {
1326  if (pattern)
1327  psql_error("Did not find any relation named \"%s\".\n",
1328  pattern);
1329  else
1330  psql_error("Did not find any relations.\n");
1331  }
1332  PQclear(res);
1333  return false;
1334  }
1335 
1336  for (i = 0; i < PQntuples(res); i++)
1337  {
1338  const char *oid;
1339  const char *nspname;
1340  const char *relname;
1341 
1342  oid = PQgetvalue(res, i, 0);
1343  nspname = PQgetvalue(res, i, 1);
1344  relname = PQgetvalue(res, i, 2);
1345 
1346  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1347  {
1348  PQclear(res);
1349  return false;
1350  }
1351  if (cancel_pressed)
1352  {
1353  PQclear(res);
1354  return false;
1355  }
1356  }
1357 
1358  PQclear(res);
1359  return true;
1360 }
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:1370
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
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:139
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:5399
#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
bool describeTypes ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

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

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

786 {
787  PGresult *res;
789  printQueryOpt myopt = pset.popt;
790 
791  initPQExpBuffer(&buf);
792 
793  printfPQExpBuffer(&buf,
794  "SELECT d.datname as \"%s\",\n"
795  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
796  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
797  gettext_noop("Name"),
798  gettext_noop("Owner"),
799  gettext_noop("Encoding"));
800  if (pset.sversion >= 80400)
801  appendPQExpBuffer(&buf,
802  " d.datcollate as \"%s\",\n"
803  " d.datctype as \"%s\",\n",
804  gettext_noop("Collate"),
805  gettext_noop("Ctype"));
806  appendPQExpBufferStr(&buf, " ");
807  printACLColumn(&buf, "d.datacl");
808  if (verbose && pset.sversion >= 80200)
809  appendPQExpBuffer(&buf,
810  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
811  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
812  " ELSE 'No Access'\n"
813  " END as \"%s\"",
814  gettext_noop("Size"));
815  if (verbose && pset.sversion >= 80000)
816  appendPQExpBuffer(&buf,
817  ",\n t.spcname as \"%s\"",
818  gettext_noop("Tablespace"));
819  if (verbose && pset.sversion >= 80200)
820  appendPQExpBuffer(&buf,
821  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
822  gettext_noop("Description"));
824  "\nFROM pg_catalog.pg_database d\n");
825  if (verbose && pset.sversion >= 80000)
827  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
828 
829  if (pattern)
830  processSQLNamePattern(pset.db, &buf, pattern, false, false,
831  NULL, "d.datname", NULL, NULL);
832 
833  appendPQExpBufferStr(&buf, "ORDER BY 1;");
834  res = PSQLexec(buf.data);
835  termPQExpBuffer(&buf);
836  if (!res)
837  return false;
838 
839  myopt.nullPrint = NULL;
840  myopt.title = _("List of databases");
841  myopt.translate_header = true;
842 
843  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
844 
845  PQclear(res);
846  return true;
847 }
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:139
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:5399
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690
bool listCasts ( const char *  pattern,
bool  verbose 
)

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

3806 {
3808  PGresult *res;
3809  printQueryOpt myopt = pset.popt;
3810  static const bool translate_columns[] = {false, false, false, true, false};
3811 
3812  initPQExpBuffer(&buf);
3813 
3814  /*
3815  * We need a left join to pg_proc for binary casts; the others are just
3816  * paranoia. Also note that we don't attempt to localize '(binary
3817  * coercible)', because there's too much risk of gettext translating a
3818  * function name that happens to match some string in the PO database.
3819  */
3820  printfPQExpBuffer(&buf,
3821  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3822  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3823  " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3824  " ELSE p.proname\n"
3825  " END as \"%s\",\n"
3826  " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3827  " WHEN c.castcontext = 'a' THEN '%s'\n"
3828  " ELSE '%s'\n"
3829  " END as \"%s\"",
3830  gettext_noop("Source type"),
3831  gettext_noop("Target type"),
3832  gettext_noop("Function"),
3833  gettext_noop("no"),
3834  gettext_noop("in assignment"),
3835  gettext_noop("yes"),
3836  gettext_noop("Implicit?"));
3837 
3838  if (verbose)
3839  appendPQExpBuffer(&buf,
3840  ",\n d.description AS \"%s\"\n",
3841  gettext_noop("Description"));
3842 
3843  appendPQExpBufferStr(&buf,
3844  "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
3845  " ON c.castfunc = p.oid\n"
3846  " LEFT JOIN pg_catalog.pg_type ts\n"
3847  " ON c.castsource = ts.oid\n"
3848  " LEFT JOIN pg_catalog.pg_namespace ns\n"
3849  " ON ns.oid = ts.typnamespace\n"
3850  " LEFT JOIN pg_catalog.pg_type tt\n"
3851  " ON c.casttarget = tt.oid\n"
3852  " LEFT JOIN pg_catalog.pg_namespace nt\n"
3853  " ON nt.oid = tt.typnamespace\n");
3854 
3855  if (verbose)
3856  appendPQExpBufferStr(&buf,
3857  " LEFT JOIN pg_catalog.pg_description d\n"
3858  " ON d.classoid = c.tableoid AND d.objoid = "
3859  "c.oid AND d.objsubid = 0\n");
3860 
3861  appendPQExpBufferStr(&buf, "WHERE ( (true");
3862 
3863  /*
3864  * Match name pattern against either internal or external name of either
3865  * castsource or casttarget
3866  */
3867  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3868  "ns.nspname", "ts.typname",
3869  "pg_catalog.format_type(ts.oid, NULL)",
3870  "pg_catalog.pg_type_is_visible(ts.oid)");
3871 
3872  appendPQExpBufferStr(&buf, ") OR (true");
3873 
3874  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3875  "nt.nspname", "tt.typname",
3876  "pg_catalog.format_type(tt.oid, NULL)",
3877  "pg_catalog.pg_type_is_visible(tt.oid)");
3878 
3879  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
3880 
3881  res = PSQLexec(buf.data);
3882  termPQExpBuffer(&buf);
3883  if (!res)
3884  return false;
3885 
3886  myopt.nullPrint = NULL;
3887  myopt.title = _("List of casts");
3888  myopt.translate_header = true;
3889  myopt.translate_columns = translate_columns;
3890  myopt.n_translate_columns = lengthof(translate_columns);
3891 
3892  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3893 
3894  PQclear(res);
3895  return true;
3896 }
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:139
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:556
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
bool listCollations ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3905 {
3907  PGresult *res;
3908  printQueryOpt myopt = pset.popt;
3909  static const bool translate_columns[] = {false, false, false, false, false, false};
3910 
3911  if (pset.sversion < 90100)
3912  {
3913  char sverbuf[32];
3914 
3915  psql_error("The server (version %s) does not support collations.\n",
3917  sverbuf, sizeof(sverbuf)));
3918  return true;
3919  }
3920 
3921  initPQExpBuffer(&buf);
3922 
3923  printfPQExpBuffer(&buf,
3924  "SELECT n.nspname AS \"%s\",\n"
3925  " c.collname AS \"%s\",\n"
3926  " c.collcollate AS \"%s\",\n"
3927  " c.collctype AS \"%s\"",
3928  gettext_noop("Schema"),
3929  gettext_noop("Name"),
3930  gettext_noop("Collate"),
3931  gettext_noop("Ctype"));
3932 
3933  if (pset.sversion >= 100000)
3934  appendPQExpBuffer(&buf,
3935  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
3936  gettext_noop("Provider"));
3937 
3938  if (verbose)
3939  appendPQExpBuffer(&buf,
3940  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
3941  gettext_noop("Description"));
3942 
3943  appendPQExpBufferStr(&buf,
3944  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
3945  "WHERE n.oid = c.collnamespace\n");
3946 
3947  if (!showSystem && !pattern)
3948  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3949  " AND n.nspname <> 'information_schema'\n");
3950 
3951  /*
3952  * Hide collations that aren't usable in the current database's encoding.
3953  * If you think to change this, note that pg_collation_is_visible rejects
3954  * unusable collations, so you will need to hack name pattern processing
3955  * somehow to avoid inconsistent behavior.
3956  */
3957  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
3958 
3959  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3960  "n.nspname", "c.collname", NULL,
3961  "pg_catalog.pg_collation_is_visible(c.oid)");
3962 
3963  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3964 
3965  res = PSQLexec(buf.data);
3966  termPQExpBuffer(&buf);
3967  if (!res)
3968  return false;
3969 
3970  myopt.nullPrint = NULL;
3971  myopt.title = _("List of collations");
3972  myopt.translate_header = true;
3973  myopt.translate_columns = translate_columns;
3974  myopt.n_translate_columns = lengthof(translate_columns);
3975 
3976  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3977 
3978  PQclear(res);
3979  return true;
3980 }
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:139
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:556
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
bool listConversions ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3664 {
3666  PGresult *res;
3667  printQueryOpt myopt = pset.popt;
3668  static const bool translate_columns[] =
3669  {false, false, false, false, true, false};
3670 
3671  initPQExpBuffer(&buf);
3672 
3673  printfPQExpBuffer(&buf,
3674  "SELECT n.nspname AS \"%s\",\n"
3675  " c.conname AS \"%s\",\n"
3676  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
3677  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
3678  " CASE WHEN c.condefault THEN '%s'\n"
3679  " ELSE '%s' END AS \"%s\"",
3680  gettext_noop("Schema"),
3681  gettext_noop("Name"),
3682  gettext_noop("Source"),
3683  gettext_noop("Destination"),
3684  gettext_noop("yes"), gettext_noop("no"),
3685  gettext_noop("Default?"));
3686 
3687  if (verbose)
3688  appendPQExpBuffer(&buf,
3689  ",\n d.description AS \"%s\"",
3690  gettext_noop("Description"));
3691 
3692  appendPQExpBufferStr(&buf,
3693  "\nFROM pg_catalog.pg_conversion c\n"
3694  " JOIN pg_catalog.pg_namespace n "
3695  "ON n.oid = c.connamespace\n");
3696 
3697  if (verbose)
3698  appendPQExpBufferStr(&buf,
3699  "LEFT JOIN pg_catalog.pg_description d "
3700  "ON d.classoid = c.tableoid\n"
3701  " AND d.objoid = c.oid "
3702  "AND d.objsubid = 0\n");
3703 
3704  appendPQExpBufferStr(&buf, "WHERE true\n");
3705 
3706  if (!showSystem && !pattern)
3707  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3708  " AND n.nspname <> 'information_schema'\n");
3709 
3710  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3711  "n.nspname", "c.conname", NULL,
3712  "pg_catalog.pg_conversion_is_visible(c.oid)");
3713 
3714  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3715 
3716  res = PSQLexec(buf.data);
3717  termPQExpBuffer(&buf);
3718  if (!res)
3719  return false;
3720 
3721  myopt.nullPrint = NULL;
3722  myopt.title = _("List of conversions");
3723  myopt.translate_header = true;
3724  myopt.translate_columns = translate_columns;
3725  myopt.n_translate_columns = lengthof(translate_columns);
3726 
3727  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3728 
3729  PQclear(res);
3730  return true;
3731 }
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:139
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:556
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
bool listDbRoleSettings ( const char *  pattern1,
const char *  pattern2 
)

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

3256 {
3258  PGresult *res;
3259  printQueryOpt myopt = pset.popt;
3260  bool havewhere;
3261 
3262  if (pset.sversion < 90000)
3263  {
3264  char sverbuf[32];
3265 
3266  psql_error("The server (version %s) does not support per-database role settings.\n",
3268  sverbuf, sizeof(sverbuf)));
3269  return true;
3270  }
3271 
3272  initPQExpBuffer(&buf);
3273 
3274  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3275  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3276  "FROM pg_catalog.pg_db_role_setting s\n"
3277  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3278  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3279  gettext_noop("Role"),
3280  gettext_noop("Database"),
3281  gettext_noop("Settings"));
3282  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3283  NULL, "r.rolname", NULL, NULL);
3284  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3285  NULL, "d.datname", NULL, NULL);
3286  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3287 
3288  res = PSQLexec(buf.data);
3289  termPQExpBuffer(&buf);
3290  if (!res)
3291  return false;
3292 
3293  /*
3294  * Most functions in this file are content to print an empty table when
3295  * there are no matching objects. We intentionally deviate from that
3296  * here, but only in !quiet mode, because of the possibility that the user
3297  * is confused about what the two pattern arguments mean.
3298  */
3299  if (PQntuples(res) == 0 && !pset.quiet)
3300  {
3301  if (pattern && pattern2)
3302  psql_error("Did not find any settings for role \"%s\" and database \"%s\".\n",
3303  pattern, pattern2);
3304  else if (pattern)
3305  psql_error("Did not find any settings for role \"%s\".\n",
3306  pattern);
3307  else
3308  psql_error("Did not find any settings.\n");
3309  }
3310  else
3311  {
3312  myopt.nullPrint = NULL;
3313  myopt.title = _("List of settings");
3314  myopt.translate_header = true;
3315 
3316  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3317  }
3318 
3319  PQclear(res);
3320  return true;
3321 }
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:139
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
bool listDefaultACLs ( const char *  pattern)

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

1016 {
1018  PGresult *res;
1019  printQueryOpt myopt = pset.popt;
1020  static const bool translate_columns[] = {false, false, true, false};
1021 
1022  if (pset.sversion < 90000)
1023  {
1024  char sverbuf[32];
1025 
1026  psql_error("The server (version %s) does not support altering default privileges.\n",
1028  sverbuf, sizeof(sverbuf)));
1029  return true;
1030  }
1031 
1032  initPQExpBuffer(&buf);
1033 
1034  printfPQExpBuffer(&buf,
1035  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1036  " n.nspname AS \"%s\",\n"
1037  " 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"
1038  " ",
1039  gettext_noop("Owner"),
1040  gettext_noop("Schema"),
1042  gettext_noop("table"),
1044  gettext_noop("sequence"),
1046  gettext_noop("function"),
1048  gettext_noop("type"),
1050  gettext_noop("schema"),
1051  gettext_noop("Type"));
1052 
1053  printACLColumn(&buf, "d.defaclacl");
1054 
1055  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1056  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1057 
1058  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1059  NULL,
1060  "n.nspname",
1061  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1062  NULL);
1063 
1064  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1065 
1066  res = PSQLexec(buf.data);
1067  if (!res)
1068  {
1069  termPQExpBuffer(&buf);
1070  return false;
1071  }
1072 
1073  myopt.nullPrint = NULL;
1074  printfPQExpBuffer(&buf, _("Default access privileges"));
1075  myopt.title = buf.data;
1076  myopt.translate_header = true;
1077  myopt.translate_columns = translate_columns;
1078  myopt.n_translate_columns = lengthof(translate_columns);
1079 
1080  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1081 
1082  termPQExpBuffer(&buf);
1083  PQclear(res);
1084  return true;
1085 }
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:139
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:556
#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:5399
#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
bool listDomains ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3578 {
3580  PGresult *res;
3581  printQueryOpt myopt = pset.popt;
3582 
3583  initPQExpBuffer(&buf);
3584 
3585  printfPQExpBuffer(&buf,
3586  "SELECT n.nspname as \"%s\",\n"
3587  " t.typname as \"%s\",\n"
3588  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
3589  gettext_noop("Schema"),
3590  gettext_noop("Name"),
3591  gettext_noop("Type"));
3592 
3593  if (pset.sversion >= 90100)
3594  appendPQExpBuffer(&buf,
3595  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
3596  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
3597  gettext_noop("Collation"));
3598  appendPQExpBuffer(&buf,
3599  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
3600  " t.typdefault as \"%s\",\n"
3601  " pg_catalog.array_to_string(ARRAY(\n"
3602  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
3603  " ), ' ') as \"%s\"",
3604  gettext_noop("Nullable"),
3605  gettext_noop("Default"),
3606  gettext_noop("Check"));
3607 
3608  if (verbose)
3609  {
3610  if (pset.sversion >= 90200)
3611  {
3612  appendPQExpBufferStr(&buf, ",\n ");
3613  printACLColumn(&buf, "t.typacl");
3614  }
3615  appendPQExpBuffer(&buf,
3616  ",\n d.description as \"%s\"",
3617  gettext_noop("Description"));
3618  }
3619 
3620  appendPQExpBufferStr(&buf,
3621  "\nFROM pg_catalog.pg_type t\n"
3622  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
3623 
3624  if (verbose)
3625  appendPQExpBufferStr(&buf,
3626  " LEFT JOIN pg_catalog.pg_description d "
3627  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
3628  "AND d.objsubid = 0\n");
3629 
3630  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
3631 
3632  if (!showSystem && !pattern)
3633  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3634  " AND n.nspname <> 'information_schema'\n");
3635 
3636  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3637  "n.nspname", "t.typname", NULL,
3638  "pg_catalog.pg_type_is_visible(t.oid)");
3639 
3640  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3641 
3642  res = PSQLexec(buf.data);
3643  termPQExpBuffer(&buf);
3644  if (!res)
3645  return false;
3646 
3647  myopt.nullPrint = NULL;
3648  myopt.title = _("List of domains");
3649  myopt.translate_header = true;
3650 
3651  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3652 
3653  PQclear(res);
3654  return true;
3655 }
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:139
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:5399
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690
bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

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

3740 {
3742  PGresult *res;
3743  printQueryOpt myopt = pset.popt;
3744  static const bool translate_columns[] =
3745  {false, false, false, true, false, false, false};
3746 
3747  initPQExpBuffer(&buf);
3748 
3749  printfPQExpBuffer(&buf,
3750  "SELECT evtname as \"%s\", "
3751  "evtevent as \"%s\", "
3752  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
3753  " case evtenabled when 'O' then '%s'"
3754  " when 'R' then '%s'"
3755  " when 'A' then '%s'"
3756  " when 'D' then '%s' end as \"%s\",\n"
3757  " e.evtfoid::pg_catalog.regproc as \"%s\", "
3758  "pg_catalog.array_to_string(array(select x"
3759  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
3760  gettext_noop("Name"),
3761  gettext_noop("Event"),
3762  gettext_noop("Owner"),
3763  gettext_noop("enabled"),
3764  gettext_noop("replica"),
3765  gettext_noop("always"),
3766  gettext_noop("disabled"),
3767  gettext_noop("Enabled"),
3768  gettext_noop("Procedure"),
3769  gettext_noop("Tags"));
3770  if (verbose)
3771  appendPQExpBuffer(&buf,
3772  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
3773  gettext_noop("Description"));
3774  appendPQExpBufferStr(&buf,
3775  "\nFROM pg_catalog.pg_event_trigger e ");
3776 
3777  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3778  NULL, "evtname", NULL, NULL);
3779 
3780  appendPQExpBufferStr(&buf, "ORDER BY 1");
3781 
3782  res = PSQLexec(buf.data);
3783  termPQExpBuffer(&buf);
3784  if (!res)
3785  return false;
3786 
3787  myopt.nullPrint = NULL;
3788  myopt.title = _("List of event triggers");
3789  myopt.translate_header = true;
3790  myopt.translate_columns = translate_columns;
3791  myopt.n_translate_columns = lengthof(translate_columns);
3792 
3793  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3794 
3795  PQclear(res);
3796  return true;
3797 }
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:139
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:556
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
bool listExtensionContents ( const char *  pattern)

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

5002 {
5004  PGresult *res;
5005  int i;
5006 
5007  if (pset.sversion < 90100)
5008  {
5009  char sverbuf[32];
5010 
5011  psql_error("The server (version %s) does not support extensions.\n",
5013  sverbuf, sizeof(sverbuf)));
5014  return true;
5015  }
5016 
5017  initPQExpBuffer(&buf);
5018  printfPQExpBuffer(&buf,
5019  "SELECT e.extname, e.oid\n"
5020  "FROM pg_catalog.pg_extension e\n");
5021 
5022  processSQLNamePattern(pset.db, &buf, pattern,
5023  false, false,
5024  NULL, "e.extname", NULL,
5025  NULL);
5026 
5027  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5028 
5029  res = PSQLexec(buf.data);
5030  termPQExpBuffer(&buf);
5031  if (!res)
5032  return false;
5033 
5034  if (PQntuples(res) == 0)
5035  {
5036  if (!pset.quiet)
5037  {
5038  if (pattern)
5039  psql_error("Did not find any extension named \"%s\".\n",
5040  pattern);
5041  else
5042  psql_error("Did not find any extensions.\n");
5043  }
5044  PQclear(res);
5045  return false;
5046  }
5047 
5048  for (i = 0; i < PQntuples(res); i++)
5049  {
5050  const char *extname;
5051  const char *oid;
5052 
5053  extname = PQgetvalue(res, i, 0);
5054  oid = PQgetvalue(res, i, 1);
5055 
5056  if (!listOneExtensionContents(extname, oid))
5057  {
5058  PQclear(res);
5059  return false;
5060  }
5061  if (cancel_pressed)
5062  {
5063  PQclear(res);
5064  return false;
5065  }
5066  }
5067 
5068  PQclear(res);
5069  return true;
5070 }
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:5073
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
bool listExtensions ( const char *  pattern)

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

4945 {
4947  PGresult *res;
4948  printQueryOpt myopt = pset.popt;
4949 
4950  if (pset.sversion < 90100)
4951  {
4952  char sverbuf[32];
4953 
4954  psql_error("The server (version %s) does not support extensions.\n",
4956  sverbuf, sizeof(sverbuf)));
4957  return true;
4958  }
4959 
4960  initPQExpBuffer(&buf);
4961  printfPQExpBuffer(&buf,
4962  "SELECT e.extname AS \"%s\", "
4963  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4964  "FROM pg_catalog.pg_extension e "
4965  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4966  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4967  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4968  gettext_noop("Name"),
4969  gettext_noop("Version"),
4970  gettext_noop("Schema"),
4971  gettext_noop("Description"));
4972 
4973  processSQLNamePattern(pset.db, &buf, pattern,
4974  false, false,
4975  NULL, "e.extname", NULL,
4976  NULL);
4977 
4978  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4979 
4980  res = PSQLexec(buf.data);
4981  termPQExpBuffer(&buf);
4982  if (!res)
4983  return false;
4984 
4985  myopt.nullPrint = NULL;
4986  myopt.title = _("List of installed extensions");
4987  myopt.translate_header = true;
4988 
4989  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4990 
4991  PQclear(res);
4992  return true;
4993 }
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:139
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
bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

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

4641 {
4643  PGresult *res;
4644  printQueryOpt myopt = pset.popt;
4645 
4646  if (pset.sversion < 80400)
4647  {
4648  char sverbuf[32];
4649 
4650  psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4652  sverbuf, sizeof(sverbuf)));
4653  return true;
4654  }
4655 
4656  initPQExpBuffer(&buf);
4657  printfPQExpBuffer(&buf,
4658  "SELECT fdw.fdwname AS \"%s\",\n"
4659  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4660  gettext_noop("Name"),
4661  gettext_noop("Owner"));
4662  if (pset.sversion >= 90100)
4663  appendPQExpBuffer(&buf,
4664  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4665  gettext_noop("Handler"));
4666  appendPQExpBuffer(&buf,
4667  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4668  gettext_noop("Validator"));
4669 
4670  if (verbose)
4671  {
4672  appendPQExpBufferStr(&buf, ",\n ");
4673  printACLColumn(&buf, "fdwacl");
4674  appendPQExpBuffer(&buf,
4675  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4676  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4677  " pg_catalog.quote_ident(option_name) || ' ' || "
4678  " pg_catalog.quote_literal(option_value) FROM "
4679  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
4680  " END AS \"%s\"",
4681  gettext_noop("FDW options"));
4682 
4683  if (pset.sversion >= 90100)
4684  appendPQExpBuffer(&buf,
4685  ",\n d.description AS \"%s\" ",
4686  gettext_noop("Description"));
4687  }
4688 
4689  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4690 
4691  if (verbose && pset.sversion >= 90100)
4692  appendPQExpBufferStr(&buf,
4693  "LEFT JOIN pg_catalog.pg_description d\n"
4694  " ON d.classoid = fdw.tableoid "
4695  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4696 
4697  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4698  NULL, "fdwname", NULL, NULL);
4699 
4700  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4701 
4702  res = PSQLexec(buf.data);
4703  termPQExpBuffer(&buf);
4704  if (!res)
4705  return false;
4706 
4707  myopt.nullPrint = NULL;
4708  myopt.title = _("List of foreign-data wrappers");
4709  myopt.translate_header = true;
4710 
4711  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4712 
4713  PQclear(res);
4714  return true;
4715 }
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:139
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:5399
#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
bool listForeignServers ( const char *  pattern,
bool  verbose 
)

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

4724 {
4726  PGresult *res;
4727  printQueryOpt myopt = pset.popt;
4728 
4729  if (pset.sversion < 80400)
4730  {
4731  char sverbuf[32];
4732 
4733  psql_error("The server (version %s) does not support foreign servers.\n",
4735  sverbuf, sizeof(sverbuf)));
4736  return true;
4737  }
4738 
4739  initPQExpBuffer(&buf);
4740  printfPQExpBuffer(&buf,
4741  "SELECT s.srvname AS \"%s\",\n"
4742  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4743  " f.fdwname AS \"%s\"",
4744  gettext_noop("Name"),
4745  gettext_noop("Owner"),
4746  gettext_noop("Foreign-data wrapper"));
4747 
4748  if (verbose)
4749  {
4750  appendPQExpBufferStr(&buf, ",\n ");
4751  printACLColumn(&buf, "s.srvacl");
4752  appendPQExpBuffer(&buf,
4753  ",\n"
4754  " s.srvtype AS \"%s\",\n"
4755  " s.srvversion AS \"%s\",\n"
4756  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4757  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4758  " pg_catalog.quote_ident(option_name) || ' ' || "
4759  " pg_catalog.quote_literal(option_value) FROM "
4760  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
4761  " END AS \"%s\",\n"
4762  " d.description AS \"%s\"",
4763  gettext_noop("Type"),
4764  gettext_noop("Version"),
4765  gettext_noop("FDW options"),
4766  gettext_noop("Description"));
4767  }
4768 
4769  appendPQExpBufferStr(&buf,
4770  "\nFROM pg_catalog.pg_foreign_server s\n"
4771  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4772 
4773  if (verbose)
4774  appendPQExpBufferStr(&buf,
4775  "LEFT JOIN pg_catalog.pg_description d\n "
4776  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4777  "AND d.objsubid = 0\n");
4778 
4779  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4780  NULL, "s.srvname", NULL, NULL);
4781 
4782  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4783 
4784  res = PSQLexec(buf.data);
4785  termPQExpBuffer(&buf);
4786  if (!res)
4787  return false;
4788 
4789  myopt.nullPrint = NULL;
4790  myopt.title = _("List of foreign servers");
4791  myopt.translate_header = true;
4792 
4793  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4794 
4795  PQclear(res);
4796  return true;
4797 }
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:139
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:5399
#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
bool listForeignTables ( const char *  pattern,
bool  verbose 
)

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

4867 {
4869  PGresult *res;
4870  printQueryOpt myopt = pset.popt;
4871 
4872  if (pset.sversion < 90100)
4873  {
4874  char sverbuf[32];
4875 
4876  psql_error("The server (version %s) does not support foreign tables.\n",
4878  sverbuf, sizeof(sverbuf)));
4879  return true;
4880  }
4881 
4882  initPQExpBuffer(&buf);
4883  printfPQExpBuffer(&buf,
4884  "SELECT n.nspname AS \"%s\",\n"
4885  " c.relname AS \"%s\",\n"
4886  " s.srvname AS \"%s\"",
4887  gettext_noop("Schema"),
4888  gettext_noop("Table"),
4889  gettext_noop("Server"));
4890 
4891  if (verbose)
4892  appendPQExpBuffer(&buf,
4893  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4894  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4895  " pg_catalog.quote_ident(option_name) || ' ' || "
4896  " pg_catalog.quote_literal(option_value) FROM "
4897  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
4898  " END AS \"%s\",\n"
4899  " d.description AS \"%s\"",
4900  gettext_noop("FDW options"),
4901  gettext_noop("Description"));
4902 
4903  appendPQExpBufferStr(&buf,
4904  "\nFROM pg_catalog.pg_foreign_table ft\n"
4905  " INNER JOIN pg_catalog.pg_class c"
4906  " ON c.oid = ft.ftrelid\n"
4907  " INNER JOIN pg_catalog.pg_namespace n"
4908  " ON n.oid = c.relnamespace\n"
4909  " INNER JOIN pg_catalog.pg_foreign_server s"
4910  " ON s.oid = ft.ftserver\n");
4911  if (verbose)
4912  appendPQExpBufferStr(&buf,
4913  " LEFT JOIN pg_catalog.pg_description d\n"
4914  " ON d.classoid = c.tableoid AND "
4915  "d.objoid = c.oid AND d.objsubid = 0\n");
4916 
4917  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4918  "n.nspname", "c.relname", NULL,
4919  "pg_catalog.pg_table_is_visible(c.oid)");
4920 
4921  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4922 
4923  res = PSQLexec(buf.data);
4924  termPQExpBuffer(&buf);
4925  if (!res)
4926  return false;
4927 
4928  myopt.nullPrint = NULL;
4929  myopt.title = _("List of foreign tables");
4930  myopt.translate_header = true;
4931 
4932  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4933 
4934  PQclear(res);
4935  return true;
4936 }
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:139
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
bool listLanguages ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3503 {
3505  PGresult *res;
3506  printQueryOpt myopt = pset.popt;
3507 
3508  initPQExpBuffer(&buf);
3509 
3510  printfPQExpBuffer(&buf,
3511  "SELECT l.lanname AS \"%s\",\n",
3512  gettext_noop("Name"));
3513  if (pset.sversion >= 80300)
3514  appendPQExpBuffer(&buf,
3515  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
3516  gettext_noop("Owner"));
3517 
3518  appendPQExpBuffer(&buf,
3519  " l.lanpltrusted AS \"%s\"",
3520  gettext_noop("Trusted"));
3521 
3522  if (verbose)
3523  {
3524  appendPQExpBuffer(&buf,
3525  ",\n NOT l.lanispl AS \"%s\",\n"
3526  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
3527  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n ",
3528  gettext_noop("Internal language"),
3529  gettext_noop("Call handler"),
3530  gettext_noop("Validator"));
3531  if (pset.sversion >= 90000)
3532  appendPQExpBuffer(&buf, "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
3533  gettext_noop("Inline handler"));
3534  printACLColumn(&buf, "l.lanacl");
3535  }
3536 
3537  appendPQExpBuffer(&buf,
3538  ",\n d.description AS \"%s\""
3539  "\nFROM pg_catalog.pg_language l\n"
3540  "LEFT JOIN pg_catalog.pg_description d\n"
3541  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
3542  " AND d.objsubid = 0\n",
3543  gettext_noop("Description"));
3544 
3545  if (pattern)
3546  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3547  NULL, "l.lanname", NULL, NULL);
3548 
3549  if (!showSystem && !pattern)
3550  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
3551 
3552 
3553  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3554 
3555  res = PSQLexec(buf.data);
3556  termPQExpBuffer(&buf);
3557  if (!res)
3558  return false;
3559 
3560  myopt.nullPrint = NULL;
3561  myopt.title = _("List of languages");
3562  myopt.translate_header = true;
3563 
3564  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3565 
3566  PQclear(res);
3567  return true;
3568 }
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:139
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:5399
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690
bool listPublications ( const char *  pattern)

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

5115 {
5117  PGresult *res;
5118  printQueryOpt myopt = pset.popt;
5119  static const bool translate_columns[] = {false, false, false, false, false, false};
5120 
5121  if (pset.sversion < 100000)
5122  {
5123  char sverbuf[32];
5124 
5125  psql_error("The server (version %s) does not support publications.\n",
5127  sverbuf, sizeof(sverbuf)));
5128  return true;
5129  }
5130 
5131  initPQExpBuffer(&buf);
5132 
5133  printfPQExpBuffer(&buf,
5134  "SELECT pubname AS \"%s\",\n"
5135  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5136  " puballtables AS \"%s\",\n"
5137  " pubinsert AS \"%s\",\n"
5138  " pubupdate AS \"%s\",\n"
5139  " pubdelete AS \"%s\"\n",
5140  gettext_noop("Name"),
5141  gettext_noop("Owner"),
5142  gettext_noop("All tables"),
5143  gettext_noop("Inserts"),
5144  gettext_noop("Updates"),
5145  gettext_noop("Deletes"));
5146 
5147  appendPQExpBufferStr(&buf,
5148  "\nFROM pg_catalog.pg_publication\n");
5149 
5150  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5151  NULL, "pubname", NULL,
5152  NULL);
5153 
5154  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5155 
5156  res = PSQLexec(buf.data);
5157  termPQExpBuffer(&buf);
5158  if (!res)
5159  return false;
5160 
5161  myopt.nullPrint = NULL;
5162  myopt.title = _("List of publications");
5163  myopt.translate_header = true;
5164  myopt.translate_columns = translate_columns;
5165  myopt.n_translate_columns = lengthof(translate_columns);
5166 
5167  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5168 
5169  PQclear(res);
5170 
5171  return true;
5172 }
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:139
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:556
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
bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3989 {
3991  PGresult *res;
3992  printQueryOpt myopt = pset.popt;
3993 
3994  initPQExpBuffer(&buf);
3995  printfPQExpBuffer(&buf,
3996  "SELECT n.nspname AS \"%s\",\n"
3997  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
3998  gettext_noop("Name"),
3999  gettext_noop("Owner"));
4000 
4001  if (verbose)
4002  {
4003  appendPQExpBufferStr(&buf, ",\n ");
4004  printACLColumn(&buf, "n.nspacl");
4005  appendPQExpBuffer(&buf,
4006  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4007  gettext_noop("Description"));
4008  }
4009 
4010  appendPQExpBuffer(&buf,
4011  "\nFROM pg_catalog.pg_namespace n\n");
4012 
4013  if (!showSystem && !pattern)
4014  appendPQExpBufferStr(&buf,
4015  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
4016 
4017  processSQLNamePattern(pset.db, &buf, pattern,
4018  !showSystem && !pattern, false,
4019  NULL, "n.nspname", NULL,
4020  NULL);
4021 
4022  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4023 
4024  res = PSQLexec(buf.data);
4025  termPQExpBuffer(&buf);
4026  if (!res)
4027  return false;
4028 
4029  myopt.nullPrint = NULL;
4030  myopt.title = _("List of schemas");
4031  myopt.translate_header = true;
4032 
4033  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4034 
4035  PQclear(res);
4036  return true;
4037 }
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:139
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:5399
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690
bool listTables ( const char *  tabtypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3340 {
3341  bool showTables = strchr(tabtypes, 't') != NULL;
3342  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3343  bool showViews = strchr(tabtypes, 'v') != NULL;
3344  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3345  bool showSeq = strchr(tabtypes, 's') != NULL;
3346  bool showForeign = strchr(tabtypes, 'E') != NULL;
3347 
3349  PGresult *res;
3350  printQueryOpt myopt = pset.popt;
3351  static const bool translate_columns[] = {false, false, true, false, false, false, false};
3352 
3353  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3354  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3355  showTables = showViews = showMatViews = showSeq = showForeign = true;
3356 
3357  initPQExpBuffer(&buf);
3358 
3359  /*
3360  * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
3361  * it here for backwards compatibility.
3362  */
3363  printfPQExpBuffer(&buf,
3364  "SELECT n.nspname as \"%s\",\n"
3365  " c.relname as \"%s\",\n"
3366  " CASE c.relkind"
3367  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3368  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3369  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3370  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3371  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3372  " WHEN 's' THEN '%s'"
3373  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3374  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3375  " END as \"%s\",\n"
3376  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3377  gettext_noop("Schema"),
3378  gettext_noop("Name"),
3379  gettext_noop("table"),
3380  gettext_noop("view"),
3381  gettext_noop("materialized view"),
3382  gettext_noop("index"),
3383  gettext_noop("sequence"),
3384  gettext_noop("special"),
3385  gettext_noop("foreign table"),
3386  gettext_noop("table"), /* partitioned table */
3387  gettext_noop("Type"),
3388  gettext_noop("Owner"));
3389 
3390  if (showIndexes)
3391  appendPQExpBuffer(&buf,
3392  ",\n c2.relname as \"%s\"",
3393  gettext_noop("Table"));
3394 
3395  if (verbose)
3396  {
3397  /*
3398  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3399  * size of a table, including FSM, VM and TOAST tables.
3400  */
3401  if (pset.sversion >= 90000)
3402  appendPQExpBuffer(&buf,
3403  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3404  gettext_noop("Size"));
3405  else if (pset.sversion >= 80100)
3406  appendPQExpBuffer(&buf,
3407  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3408  gettext_noop("Size"));
3409 
3410  appendPQExpBuffer(&buf,
3411  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3412  gettext_noop("Description"));
3413  }
3414 
3415  appendPQExpBufferStr(&buf,
3416  "\nFROM pg_catalog.pg_class c"
3417  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3418  if (showIndexes)
3419  appendPQExpBufferStr(&buf,
3420  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3421  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3422 
3423  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3424  if (showTables)
3427  if (showViews)
3429  if (showMatViews)
3431  if (showIndexes)
3433  if (showSeq)
3435  if (showSystem || pattern)
3436  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3437  if (showForeign)
3439 
3440  appendPQExpBufferStr(&buf, "''"); /* dummy */
3441  appendPQExpBufferStr(&buf, ")\n");
3442 
3443  if (!showSystem && !pattern)
3444  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3445  " AND n.nspname <> 'information_schema'\n");
3446 
3447  /*
3448  * TOAST objects are suppressed unconditionally. Since we don't provide
3449  * any way to select RELKIND_TOASTVALUE above, we would never show toast
3450  * tables in any case; it seems a bit confusing to allow their indexes to
3451  * be shown. Use plain \d if you really need to look at a TOAST
3452  * table/index.
3453  */
3454  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3455 
3456  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3457  "n.nspname", "c.relname", NULL,
3458  "pg_catalog.pg_table_is_visible(c.oid)");
3459 
3460  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3461 
3462  res = PSQLexec(buf.data);
3463  termPQExpBuffer(&buf);
3464  if (!res)
3465  return false;
3466 
3467  /*
3468  * Most functions in this file are content to print an empty table when
3469  * there are no matching objects. We intentionally deviate from that
3470  * here, but only in !quiet mode, for historical reasons.
3471  */
3472  if (PQntuples(res) == 0 && !pset.quiet)
3473  {
3474  if (pattern)
3475  psql_error("Did not find any relation named \"%s\".\n",
3476  pattern);
3477  else
3478  psql_error("Did not find any relations.\n");
3479  }
3480  else
3481  {
3482  myopt.nullPrint = NULL;
3483  myopt.title = _("List of relations");
3484  myopt.translate_header = true;
3485  myopt.translate_columns = translate_columns;
3486  myopt.n_translate_columns = lengthof(translate_columns);
3487 
3488  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3489  }
3490 
3491  PQclear(res);
3492  return true;
3493 }
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:139
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:556
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:162
#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
bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

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

4435 {
4437  PGresult *res;
4438  printQueryOpt myopt = pset.popt;
4439 
4440  if (pset.sversion < 80300)
4441  {
4442  char sverbuf[32];
4443 
4444  psql_error("The server (version %s) does not support full text search.\n",
4446  sverbuf, sizeof(sverbuf)));
4447  return true;
4448  }
4449 
4450  if (verbose)
4451  return listTSConfigsVerbose(pattern);
4452 
4453  initPQExpBuffer(&buf);
4454 
4455  printfPQExpBuffer(&buf,
4456  "SELECT\n"
4457  " n.nspname as \"%s\",\n"
4458  " c.cfgname as \"%s\",\n"
4459  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4460  "FROM pg_catalog.pg_ts_config c\n"
4461  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
4462  gettext_noop("Schema"),
4463  gettext_noop("Name"),
4464  gettext_noop("Description")
4465  );
4466 
4467  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4468  "n.nspname", "c.cfgname", NULL,
4469  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4470 
4471  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4472 
4473  res = PSQLexec(buf.data);
4474  termPQExpBuffer(&buf);
4475  if (!res)
4476  return false;
4477 
4478  myopt.nullPrint = NULL;
4479  myopt.title = _("List of text search configurations");
4480  myopt.translate_header = true;
4481 
4482  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4483 
4484  PQclear(res);
4485  return true;
4486 }
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:139
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:4489
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
bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

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

4293 {
4295  PGresult *res;
4296  printQueryOpt myopt = pset.popt;
4297 
4298  if (pset.sversion < 80300)
4299  {
4300  char sverbuf[32];
4301 
4302  psql_error("The server (version %s) does not support full text search.\n",
4304  sverbuf, sizeof(sverbuf)));
4305  return true;
4306  }
4307 
4308  initPQExpBuffer(&buf);
4309 
4310  printfPQExpBuffer(&buf,
4311  "SELECT\n"
4312  " n.nspname as \"%s\",\n"
4313  " d.dictname as \"%s\",\n",
4314  gettext_noop("Schema"),
4315  gettext_noop("Name"));
4316 
4317  if (verbose)
4318  {
4319  appendPQExpBuffer(&buf,
4320  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
4321  " pg_catalog.pg_ts_template t\n"
4322  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
4323  " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
4324  " d.dictinitoption as \"%s\",\n",
4325  gettext_noop("Template"),
4326  gettext_noop("Init options"));
4327  }
4328 
4329  appendPQExpBuffer(&buf,
4330  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
4331  gettext_noop("Description"));
4332 
4333  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
4334  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
4335 
4336  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4337  "n.nspname", "d.dictname", NULL,
4338  "pg_catalog.pg_ts_dict_is_visible(d.oid)");
4339 
4340  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4341 
4342  res = PSQLexec(buf.data);
4343  termPQExpBuffer(&buf);
4344  if (!res)
4345  return false;
4346 
4347  myopt.nullPrint = NULL;
4348  myopt.title = _("List of text search dictionaries");
4349  myopt.translate_header = true;
4350 
4351  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4352 
4353  PQclear(res);
4354  return true;
4355 }
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:139
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
bool listTSParsers ( const char *  pattern,
bool  verbose 
)

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

4046 {
4048  PGresult *res;
4049  printQueryOpt myopt = pset.popt;
4050 
4051  if (pset.sversion < 80300)
4052  {
4053  char sverbuf[32];
4054 
4055  psql_error("The server (version %s) does not support full text search.\n",
4057  sverbuf, sizeof(sverbuf)));
4058  return true;
4059  }
4060 
4061  if (verbose)
4062  return listTSParsersVerbose(pattern);
4063 
4064  initPQExpBuffer(&buf);
4065 
4066  printfPQExpBuffer(&buf,
4067  "SELECT\n"
4068  " n.nspname as \"%s\",\n"
4069  " p.prsname as \"%s\",\n"
4070  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
4071  "FROM pg_catalog.pg_ts_parser p\n"
4072  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
4073  gettext_noop("Schema"),
4074  gettext_noop("Name"),
4075  gettext_noop("Description")
4076  );
4077 
4078  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4079  "n.nspname", "p.prsname", NULL,
4080  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
4081 
4082  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4083 
4084  res = PSQLexec(buf.data);
4085  termPQExpBuffer(&buf);
4086  if (!res)
4087  return false;
4088 
4089  myopt.nullPrint = NULL;
4090  myopt.title = _("List of text search parsers");
4091  myopt.translate_header = true;
4092 
4093  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4094 
4095  PQclear(res);
4096  return true;
4097 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:4103
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:139
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
bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

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

4364 {
4366  PGresult *res;
4367  printQueryOpt myopt = pset.popt;
4368 
4369  if (pset.sversion < 80300)
4370  {
4371  char sverbuf[32];
4372 
4373  psql_error("The server (version %s) does not support full text search.\n",
4375  sverbuf, sizeof(sverbuf)));
4376  return true;
4377  }
4378 
4379  initPQExpBuffer(&buf);
4380 
4381  if (verbose)
4382  printfPQExpBuffer(&buf,
4383  "SELECT\n"
4384  " n.nspname AS \"%s\",\n"
4385  " t.tmplname AS \"%s\",\n"
4386  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4387  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4388  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4389  gettext_noop("Schema"),
4390  gettext_noop("Name"),
4391  gettext_noop("Init"),
4392  gettext_noop("Lexize"),
4393  gettext_noop("Description"));
4394  else
4395  printfPQExpBuffer(&buf,
4396  "SELECT\n"
4397  " n.nspname AS \"%s\",\n"
4398  " t.tmplname AS \"%s\",\n"
4399  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4400  gettext_noop("Schema"),
4401  gettext_noop("Name"),
4402  gettext_noop("Description"));
4403 
4404  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4405  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4406 
4407  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4408  "n.nspname", "t.tmplname", NULL,
4409  "pg_catalog.pg_ts_template_is_visible(t.oid)");
4410 
4411  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4412 
4413  res = PSQLexec(buf.data);
4414  termPQExpBuffer(&buf);
4415  if (!res)
4416  return false;
4417 
4418  myopt.nullPrint = NULL;
4419  myopt.title = _("List of text search templates");
4420  myopt.translate_header = true;
4421 
4422  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4423 
4424  PQclear(res);
4425  return true;
4426 }
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:139
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
bool listUserMappings ( const char *  pattern,
bool  verbose 
)

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

4806 {
4808  PGresult *res;
4809  printQueryOpt myopt = pset.popt;
4810 
4811  if (pset.sversion < 80400)
4812  {
4813  char sverbuf[32];
4814 
4815  psql_error("The server (version %s) does not support user mappings.\n",
4817  sverbuf, sizeof(sverbuf)));
4818  return true;
4819  }
4820 
4821  initPQExpBuffer(&buf);
4822  printfPQExpBuffer(&buf,
4823  "SELECT um.srvname AS \"%s\",\n"
4824  " um.usename AS \"%s\"",
4825  gettext_noop("Server"),
4826  gettext_noop("User name"));
4827 
4828  if (verbose)
4829  appendPQExpBuffer(&buf,
4830  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4831  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4832  " pg_catalog.quote_ident(option_name) || ' ' || "
4833  " pg_catalog.quote_literal(option_value) FROM "
4834  " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
4835  " END AS \"%s\"",
4836  gettext_noop("FDW options"));
4837 
4838  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4839 
4840  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4841  NULL, "um.srvname", "um.usename", NULL);
4842 
4843  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4844 
4845  res = PSQLexec(buf.data);
4846  termPQExpBuffer(&buf);
4847  if (!res)
4848  return false;
4849 
4850  myopt.nullPrint = NULL;
4851  myopt.title = _("List of user mappings");
4852  myopt.translate_header = true;
4853 
4854  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4855 
4856  PQclear(res);
4857  return true;
4858 }
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:139
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
bool objectDescription ( const char *  pattern,
bool  showSystem 
)

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

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

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

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