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

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

139 {
141  PGresult *res;
142  printQueryOpt myopt = pset.popt;
143  static const bool translate_columns[] = {false, true, false, false};
144 
145  if (pset.sversion < 90600)
146  {
147  char sverbuf[32];
148 
149  psql_error("The server (version %s) does not support access methods.\n",
151  sverbuf, sizeof(sverbuf)));
152  return true;
153  }
154 
155  initPQExpBuffer(&buf);
156 
157  printfPQExpBuffer(&buf,
158  "SELECT amname AS \"%s\",\n"
159  " CASE amtype"
160  " WHEN 'i' THEN '%s'"
161  " END AS \"%s\"",
162  gettext_noop("Name"),
163  gettext_noop("Index"),
164  gettext_noop("Type"));
165 
166  if (verbose)
167  {
168  appendPQExpBuffer(&buf,
169  ",\n amhandler AS \"%s\",\n"
170  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
171  gettext_noop("Handler"),
172  gettext_noop("Description"));
173  }
174 
176  "\nFROM pg_catalog.pg_am\n");
177 
178  processSQLNamePattern(pset.db, &buf, pattern, false, false,
179  NULL, "amname", NULL,
180  NULL);
181 
182  appendPQExpBufferStr(&buf, "ORDER BY 1;");
183 
184  res = PSQLexec(buf.data);
185  termPQExpBuffer(&buf);
186  if (!res)
187  return false;
188 
189  myopt.nullPrint = NULL;
190  myopt.title = _("List of access methods");
191  myopt.translate_header = true;
192  myopt.translate_columns = translate_columns;
193  myopt.n_translate_columns = lengthof(translate_columns);
194 
195  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
196 
197  PQclear(res);
198  return true;
199 }
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:562
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
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:642
bool describeAggregates ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 61 of file describe.c.

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

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

Definition at line 299 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

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

Definition at line 703 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 5115 of file describe.c.

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

Referenced by exec_command_d().

5116 {
5118  int i;
5119  PGresult *res;
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 oid, pubname, puballtables, pubinsert,\n"
5135  " pubupdate, pubdelete\n"
5136  "FROM pg_catalog.pg_publication\n");
5137 
5138  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5139  NULL, "pubname", NULL,
5140  NULL);
5141 
5142  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5143 
5144  res = PSQLexec(buf.data);
5145  if (!res)
5146  {
5147  termPQExpBuffer(&buf);
5148  return false;
5149  }
5150 
5151  for (i = 0; i < PQntuples(res); i++)
5152  {
5153  const char align = 'l';
5154  int ncols = 4;
5155  int nrows = 1;
5156  int tables = 0;
5157  PGresult *tabres;
5158  char *pubid = PQgetvalue(res, i, 0);
5159  char *pubname = PQgetvalue(res, i, 1);
5160  bool puballtables = strcmp(PQgetvalue(res, i, 2), "t") == 0;
5161  int j;
5162  PQExpBufferData title;
5163  printTableOpt myopt = pset.popt.topt;
5164  printTableContent cont;
5165 
5166  initPQExpBuffer(&title);
5167  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5168  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5169 
5170  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
5171  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5172  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5173  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5174 
5175  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
5176  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5177  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5178  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5179 
5180  if (!puballtables)
5181  {
5182  printfPQExpBuffer(&buf,
5183  "SELECT n.nspname, c.relname\n"
5184  "FROM pg_catalog.pg_class c,\n"
5185  " pg_catalog.pg_namespace n,\n"
5186  " pg_catalog.pg_publication_rel pr\n"
5187  "WHERE c.relnamespace = n.oid\n"
5188  " AND c.oid = pr.prrelid\n"
5189  " AND pr.prpubid = '%s'\n"
5190  "ORDER BY 1,2", pubid);
5191 
5192  tabres = PSQLexec(buf.data);
5193  if (!tabres)
5194  {
5195  printTableCleanup(&cont);
5196  PQclear(res);
5197  termPQExpBuffer(&buf);
5198  termPQExpBuffer(&title);
5199  return false;
5200  }
5201  else
5202  tables = PQntuples(tabres);
5203 
5204  if (tables > 0)
5205  printTableAddFooter(&cont, _("Tables:"));
5206 
5207  for (j = 0; j < tables; j++)
5208  {
5209  printfPQExpBuffer(&buf, " \"%s.%s\"",
5210  PQgetvalue(tabres, j, 0),
5211  PQgetvalue(tabres, j, 1));
5212 
5213  printTableAddFooter(&cont, buf.data);
5214  }
5215  PQclear(tabres);
5216  }
5217 
5218  printTable(&cont, pset.queryFout, false, pset.logfile);
5219  printTableCleanup(&cont);
5220 
5221  termPQExpBuffer(&title);
5222  }
5223 
5224  termPQExpBuffer(&buf);
5225  PQclear(res);
5226 
5227  return true;
5228 }
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:3099
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2968
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3008
static char * buf
Definition: pg_test_fsync.c:66
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3188
void psql_error(const char *fmt,...)
Definition: common.c:220
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3056
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
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:2931
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:642
bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3053 {
3055  PGresult *res;
3056  printTableContent cont;
3057  printTableOpt myopt = pset.popt.topt;
3058  int ncols = 3;
3059  int nrows = 0;
3060  int i;
3061  int conns;
3062  const char align = 'l';
3063  char **attr;
3064 
3065  myopt.default_footer = false;
3066 
3067  initPQExpBuffer(&buf);
3068 
3069  if (pset.sversion >= 80100)
3070  {
3071  printfPQExpBuffer(&buf,
3072  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3073  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3074  " r.rolconnlimit, r.rolvaliduntil,\n"
3075  " ARRAY(SELECT b.rolname\n"
3076  " FROM pg_catalog.pg_auth_members m\n"
3077  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3078  " WHERE m.member = r.oid) as memberof");
3079 
3080  if (verbose && pset.sversion >= 80200)
3081  {
3082  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3083  ncols++;
3084  }
3085  if (pset.sversion >= 90100)
3086  {
3087  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3088  }
3089 
3090  if (pset.sversion >= 90500)
3091  {
3092  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3093  }
3094 
3095  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3096 
3097  if (!showSystem && !pattern)
3098  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3099 
3100  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3101  NULL, "r.rolname", NULL, NULL);
3102  }
3103  else
3104  {
3105  printfPQExpBuffer(&buf,
3106  "SELECT u.usename AS rolname,\n"
3107  " u.usesuper AS rolsuper,\n"
3108  " true AS rolinherit, false AS rolcreaterole,\n"
3109  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3110  " -1 AS rolconnlimit,"
3111  " u.valuntil as rolvaliduntil,\n"
3112  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3113  "\nFROM pg_catalog.pg_user u\n");
3114 
3115  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3116  NULL, "u.usename", NULL, NULL);
3117  }
3118 
3119  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3120 
3121  res = PSQLexec(buf.data);
3122  if (!res)
3123  return false;
3124 
3125  nrows = PQntuples(res);
3126  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3127 
3128  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3129 
3130  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3131  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3132  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3133 
3134  if (verbose && pset.sversion >= 80200)
3135  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3136 
3137  for (i = 0; i < nrows; i++)
3138  {
3139  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3140 
3141  resetPQExpBuffer(&buf);
3142  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3143  add_role_attribute(&buf, _("Superuser"));
3144 
3145  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3146  add_role_attribute(&buf, _("No inheritance"));
3147 
3148  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3149  add_role_attribute(&buf, _("Create role"));
3150 
3151  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3152  add_role_attribute(&buf, _("Create DB"));
3153 
3154  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3155  add_role_attribute(&buf, _("Cannot login"));
3156 
3157  if (pset.sversion >= 90100)
3158  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3159  add_role_attribute(&buf, _("Replication"));
3160 
3161  if (pset.sversion >= 90500)
3162  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3163  add_role_attribute(&buf, _("Bypass RLS"));
3164 
3165  conns = atoi(PQgetvalue(res, i, 6));
3166  if (conns >= 0)
3167  {
3168  if (buf.len > 0)
3169  appendPQExpBufferChar(&buf, '\n');
3170 
3171  if (conns == 0)
3172  appendPQExpBufferStr(&buf, _("No connections"));
3173  else
3174  appendPQExpBuffer(&buf, ngettext("%d connection",
3175  "%d connections",
3176  conns),
3177  conns);
3178  }
3179 
3180  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3181  {
3182  if (buf.len > 0)
3183  appendPQExpBufferStr(&buf, "\n");
3184  appendPQExpBufferStr(&buf, _("Password valid until "));
3185  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3186  }
3187 
3188  attr[i] = pg_strdup(buf.data);
3189 
3190  printTableAddCell(&cont, attr[i], false, false);
3191 
3192  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3193 
3194  if (verbose && pset.sversion >= 80200)
3195  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3196  }
3197  termPQExpBuffer(&buf);
3198 
3199  printTable(&cont, pset.queryFout, false, pset.logfile);
3200  printTableCleanup(&cont);
3201 
3202  for (i = 0; i < nrows; i++)
3203  free(attr[i]);
3204  free(attr);
3205 
3206  PQclear(res);
3207  return true;
3208 }
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:3099
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
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:2673
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3211
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2968
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:3008
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
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:3188
static int verbose
Definition: pg_basebackup.c:84
#define ngettext(s, p, n)
Definition: c.h:127
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define free(a)
Definition: header.h:65
bool default_footer
Definition: print.h:110
#define NULL
Definition: c.h:229
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:2931
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:642
bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 5236 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

5237 {
5239  PGresult *res;
5240  printQueryOpt myopt = pset.popt;
5241  static const bool translate_columns[] = {false, false, false, false,
5242  false, false};
5243 
5244  if (pset.sversion < 100000)
5245  {
5246  char sverbuf[32];
5247 
5248  psql_error("The server (version %s) does not support subscriptions.\n",
5250  sverbuf, sizeof(sverbuf)));
5251  return true;
5252  }
5253 
5254  initPQExpBuffer(&buf);
5255 
5256  printfPQExpBuffer(&buf,
5257  "SELECT subname AS \"%s\"\n"
5258  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5259  ", subenabled AS \"%s\"\n"
5260  ", subpublications AS \"%s\"\n",
5261  gettext_noop("Name"),
5262  gettext_noop("Owner"),
5263  gettext_noop("Enabled"),
5264  gettext_noop("Publication"));
5265 
5266  if (verbose)
5267  {
5268  appendPQExpBuffer(&buf,
5269  ", subsynccommit AS \"%s\"\n"
5270  ", subconninfo AS \"%s\"\n",
5271  gettext_noop("Synchronous commit"),
5272  gettext_noop("Conninfo"));
5273  }
5274 
5275  /* Only display subscriptions in current database. */
5276  appendPQExpBufferStr(&buf,
5277  "FROM pg_catalog.pg_subscription\n"
5278  "WHERE subdbid = (SELECT oid\n"
5279  " FROM pg_catalog.pg_database\n"
5280  " WHERE datname = current_database())");
5281 
5282  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5283  NULL, "subname", NULL,
5284  NULL);
5285 
5286  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5287 
5288  res = PSQLexec(buf.data);
5289  termPQExpBuffer(&buf);
5290  if (!res)
5291  return false;
5292 
5293  myopt.nullPrint = NULL;
5294  myopt.title = _("List of subscriptions");
5295  myopt.translate_header = true;
5296  myopt.translate_columns = translate_columns;
5297  myopt.n_translate_columns = lengthof(translate_columns);
5298 
5299  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5300 
5301  PQclear(res);
5302  return true;
5303 }
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:562
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
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:642
bool describeTableDetails ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 1287 of file describe.c.

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

Referenced by exec_command_d().

1288 {
1290  PGresult *res;
1291  int i;
1292 
1293  initPQExpBuffer(&buf);
1294 
1295  printfPQExpBuffer(&buf,
1296  "SELECT c.oid,\n"
1297  " n.nspname,\n"
1298  " c.relname\n"
1299  "FROM pg_catalog.pg_class c\n"
1300  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1301 
1302  if (!showSystem && !pattern)
1303  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1304  " AND n.nspname <> 'information_schema'\n");
1305 
1306  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1307  "n.nspname", "c.relname", NULL,
1308  "pg_catalog.pg_table_is_visible(c.oid)");
1309 
1310  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1311 
1312  res = PSQLexec(buf.data);
1313  termPQExpBuffer(&buf);
1314  if (!res)
1315  return false;
1316 
1317  if (PQntuples(res) == 0)
1318  {
1319  if (!pset.quiet)
1320  psql_error("Did not find any relation named \"%s\".\n",
1321  pattern);
1322  PQclear(res);
1323  return false;
1324  }
1325 
1326  for (i = 0; i < PQntuples(res); i++)
1327  {
1328  const char *oid;
1329  const char *nspname;
1330  const char *relname;
1331 
1332  oid = PQgetvalue(res, i, 0);
1333  nspname = PQgetvalue(res, i, 1);
1334  relname = PQgetvalue(res, i, 2);
1335 
1336  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1337  {
1338  PQclear(res);
1339  return false;
1340  }
1341  if (cancel_pressed)
1342  {
1343  PQclear(res);
1344  return false;
1345  }
1346  }
1347 
1348  PQclear(res);
1349  return true;
1350 }
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:3067
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:2673
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:66
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1360
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 205 of file describe.c.

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

206 {
208  PGresult *res;
209  printQueryOpt myopt = pset.popt;
210 
211  if (pset.sversion < 80000)
212  {
213  char sverbuf[32];
214 
215  psql_error("The server (version %s) does not support tablespaces.\n",
217  sverbuf, sizeof(sverbuf)));
218  return true;
219  }
220 
221  initPQExpBuffer(&buf);
222 
223  if (pset.sversion >= 90200)
224  printfPQExpBuffer(&buf,
225  "SELECT spcname AS \"%s\",\n"
226  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
227  " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
228  gettext_noop("Name"),
229  gettext_noop("Owner"),
230  gettext_noop("Location"));
231  else
232  printfPQExpBuffer(&buf,
233  "SELECT spcname AS \"%s\",\n"
234  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
235  " spclocation AS \"%s\"",
236  gettext_noop("Name"),
237  gettext_noop("Owner"),
238  gettext_noop("Location"));
239 
240  if (verbose)
241  {
242  appendPQExpBufferStr(&buf, ",\n ");
243  printACLColumn(&buf, "spcacl");
244  }
245 
246  if (verbose && pset.sversion >= 90000)
247  appendPQExpBuffer(&buf,
248  ",\n spcoptions AS \"%s\"",
249  gettext_noop("Options"));
250 
251  if (verbose && pset.sversion >= 90200)
252  appendPQExpBuffer(&buf,
253  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"",
254  gettext_noop("Size"));
255 
256  if (verbose && pset.sversion >= 80200)
257  appendPQExpBuffer(&buf,
258  ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
259  gettext_noop("Description"));
260 
262  "\nFROM pg_catalog.pg_tablespace\n");
263 
264  processSQLNamePattern(pset.db, &buf, pattern, false, false,
265  NULL, "spcname", NULL,
266  NULL);
267 
268  appendPQExpBufferStr(&buf, "ORDER BY 1;");
269 
270  res = PSQLexec(buf.data);
271  termPQExpBuffer(&buf);
272  if (!res)
273  return false;
274 
275  myopt.nullPrint = NULL;
276  myopt.title = _("List of tablespaces");
277  myopt.translate_header = true;
278 
279  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
280 
281  PQclear(res);
282  return true;
283 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5313
#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:642
bool describeTypes ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 588 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, NULL, 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().

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

Definition at line 780 of file describe.c.

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

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

Definition at line 3757 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

3758 {
3760  PGresult *res;
3761  printQueryOpt myopt = pset.popt;
3762  static const bool translate_columns[] = {false, false, false, true, false};
3763 
3764  initPQExpBuffer(&buf);
3765 
3766  /*
3767  * We need a left join to pg_proc for binary casts; the others are just
3768  * paranoia. Also note that we don't attempt to localize '(binary
3769  * coercible)', because there's too much risk of gettext translating a
3770  * function name that happens to match some string in the PO database.
3771  */
3772  printfPQExpBuffer(&buf,
3773  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3774  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3775  " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3776  " ELSE p.proname\n"
3777  " END as \"%s\",\n"
3778  " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3779  " WHEN c.castcontext = 'a' THEN '%s'\n"
3780  " ELSE '%s'\n"
3781  " END as \"%s\"",
3782  gettext_noop("Source type"),
3783  gettext_noop("Target type"),
3784  gettext_noop("Function"),
3785  gettext_noop("no"),
3786  gettext_noop("in assignment"),
3787  gettext_noop("yes"),
3788  gettext_noop("Implicit?"));
3789 
3790  if (verbose)
3791  appendPQExpBuffer(&buf,
3792  ",\n d.description AS \"%s\"\n",
3793  gettext_noop("Description"));
3794 
3795  appendPQExpBufferStr(&buf,
3796  "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
3797  " ON c.castfunc = p.oid\n"
3798  " LEFT JOIN pg_catalog.pg_type ts\n"
3799  " ON c.castsource = ts.oid\n"
3800  " LEFT JOIN pg_catalog.pg_namespace ns\n"
3801  " ON ns.oid = ts.typnamespace\n"
3802  " LEFT JOIN pg_catalog.pg_type tt\n"
3803  " ON c.casttarget = tt.oid\n"
3804  " LEFT JOIN pg_catalog.pg_namespace nt\n"
3805  " ON nt.oid = tt.typnamespace\n");
3806 
3807  if (verbose)
3808  appendPQExpBufferStr(&buf,
3809  " LEFT JOIN pg_catalog.pg_description d\n"
3810  " ON d.classoid = c.tableoid AND d.objoid = "
3811  "c.oid AND d.objsubid = 0\n");
3812 
3813  appendPQExpBufferStr(&buf, "WHERE ( (true");
3814 
3815  /*
3816  * Match name pattern against either internal or external name of either
3817  * castsource or casttarget
3818  */
3819  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3820  "ns.nspname", "ts.typname",
3821  "pg_catalog.format_type(ts.oid, NULL)",
3822  "pg_catalog.pg_type_is_visible(ts.oid)");
3823 
3824  appendPQExpBufferStr(&buf, ") OR (true");
3825 
3826  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3827  "nt.nspname", "tt.typname",
3828  "pg_catalog.format_type(tt.oid, NULL)",
3829  "pg_catalog.pg_type_is_visible(tt.oid)");
3830 
3831  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
3832 
3833  res = PSQLexec(buf.data);
3834  termPQExpBuffer(&buf);
3835  if (!res)
3836  return false;
3837 
3838  myopt.nullPrint = NULL;
3839  myopt.title = _("List of casts");
3840  myopt.translate_header = true;
3841  myopt.translate_columns = translate_columns;
3842  myopt.n_translate_columns = lengthof(translate_columns);
3843 
3844  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3845 
3846  PQclear(res);
3847  return true;
3848 }
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:562
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
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:642
bool listCollations ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3856 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

3857 {
3859  PGresult *res;
3860  printQueryOpt myopt = pset.popt;
3861  static const bool translate_columns[] = {false, false, false, false, false, false};
3862 
3863  if (pset.sversion < 90100)
3864  {
3865  char sverbuf[32];
3866 
3867  psql_error("The server (version %s) does not support collations.\n",
3869  sverbuf, sizeof(sverbuf)));
3870  return true;
3871  }
3872 
3873  initPQExpBuffer(&buf);
3874 
3875  printfPQExpBuffer(&buf,
3876  "SELECT n.nspname AS \"%s\",\n"
3877  " c.collname AS \"%s\",\n"
3878  " c.collcollate AS \"%s\",\n"
3879  " c.collctype AS \"%s\"",
3880  gettext_noop("Schema"),
3881  gettext_noop("Name"),
3882  gettext_noop("Collate"),
3883  gettext_noop("Ctype"));
3884 
3885  if (pset.sversion >= 100000)
3886  appendPQExpBuffer(&buf,
3887  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
3888  gettext_noop("Provider"));
3889 
3890  if (verbose)
3891  appendPQExpBuffer(&buf,
3892  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
3893  gettext_noop("Description"));
3894 
3895  appendPQExpBufferStr(&buf,
3896  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
3897  "WHERE n.oid = c.collnamespace\n");
3898 
3899  if (!showSystem && !pattern)
3900  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3901  " AND n.nspname <> 'information_schema'\n");
3902 
3903  /*
3904  * Hide collations that aren't usable in the current database's encoding.
3905  * If you think to change this, note that pg_collation_is_visible rejects
3906  * unusable collations, so you will need to hack name pattern processing
3907  * somehow to avoid inconsistent behavior.
3908  */
3909  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
3910 
3911  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3912  "n.nspname", "c.collname", NULL,
3913  "pg_catalog.pg_collation_is_visible(c.oid)");
3914 
3915  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3916 
3917  res = PSQLexec(buf.data);
3918  termPQExpBuffer(&buf);
3919  if (!res)
3920  return false;
3921 
3922  myopt.nullPrint = NULL;
3923  myopt.title = _("List of collations");
3924  myopt.translate_header = true;
3925  myopt.translate_columns = translate_columns;
3926  myopt.n_translate_columns = lengthof(translate_columns);
3927 
3928  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3929 
3930  PQclear(res);
3931  return true;
3932 }
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:562
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
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:642
bool listConversions ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3615 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

3616 {
3618  PGresult *res;
3619  printQueryOpt myopt = pset.popt;
3620  static const bool translate_columns[] =
3621  {false, false, false, false, true, false};
3622 
3623  initPQExpBuffer(&buf);
3624 
3625  printfPQExpBuffer(&buf,
3626  "SELECT n.nspname AS \"%s\",\n"
3627  " c.conname AS \"%s\",\n"
3628  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
3629  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
3630  " CASE WHEN c.condefault THEN '%s'\n"
3631  " ELSE '%s' END AS \"%s\"",
3632  gettext_noop("Schema"),
3633  gettext_noop("Name"),
3634  gettext_noop("Source"),
3635  gettext_noop("Destination"),
3636  gettext_noop("yes"), gettext_noop("no"),
3637  gettext_noop("Default?"));
3638 
3639  if (verbose)
3640  appendPQExpBuffer(&buf,
3641  ",\n d.description AS \"%s\"",
3642  gettext_noop("Description"));
3643 
3644  appendPQExpBufferStr(&buf,
3645  "\nFROM pg_catalog.pg_conversion c\n"
3646  " JOIN pg_catalog.pg_namespace n "
3647  "ON n.oid = c.connamespace\n");
3648 
3649  if (verbose)
3650  appendPQExpBufferStr(&buf,
3651  "LEFT JOIN pg_catalog.pg_description d "
3652  "ON d.classoid = c.tableoid\n"
3653  " AND d.objoid = c.oid "
3654  "AND d.objsubid = 0\n");
3655 
3656  appendPQExpBufferStr(&buf, "WHERE true\n");
3657 
3658  if (!showSystem && !pattern)
3659  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3660  " AND n.nspname <> 'information_schema'\n");
3661 
3662  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3663  "n.nspname", "c.conname", NULL,
3664  "pg_catalog.pg_conversion_is_visible(c.oid)");
3665 
3666  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3667 
3668  res = PSQLexec(buf.data);
3669  termPQExpBuffer(&buf);
3670  if (!res)
3671  return false;
3672 
3673  myopt.nullPrint = NULL;
3674  myopt.title = _("List of conversions");
3675  myopt.translate_header = true;
3676  myopt.translate_columns = translate_columns;
3677  myopt.n_translate_columns = lengthof(translate_columns);
3678 
3679  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3680 
3681  PQclear(res);
3682  return true;
3683 }
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:562
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
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:642
bool listDbRoleSettings ( const char *  pattern1,
const char *  pattern2 
)

Definition at line 3223 of file describe.c.

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

Referenced by exec_command_d().

3224 {
3226  PGresult *res;
3227  printQueryOpt myopt = pset.popt;
3228 
3229  initPQExpBuffer(&buf);
3230 
3231  if (pset.sversion >= 90000)
3232  {
3233  bool havewhere;
3234 
3235  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3236  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3237  "FROM pg_db_role_setting AS s\n"
3238  "LEFT JOIN pg_database ON pg_database.oid = setdatabase\n"
3239  "LEFT JOIN pg_roles ON pg_roles.oid = setrole\n",
3240  gettext_noop("Role"),
3241  gettext_noop("Database"),
3242  gettext_noop("Settings"));
3243  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3244  NULL, "pg_roles.rolname", NULL, NULL);
3245  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3246  NULL, "pg_database.datname", NULL, NULL);
3247  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3248  }
3249  else
3250  {
3251  fprintf(pset.queryFout,
3252  _("No per-database role settings support in this server version.\n"));
3253  return false;
3254  }
3255 
3256  res = PSQLexec(buf.data);
3257  if (!res)
3258  return false;
3259 
3260  if (PQntuples(res) == 0 && !pset.quiet)
3261  {
3262  if (pattern)
3263  fprintf(pset.queryFout, _("No matching settings found.\n"));
3264  else
3265  fprintf(pset.queryFout, _("No settings found.\n"));
3266  }
3267  else
3268  {
3269  myopt.nullPrint = NULL;
3270  myopt.title = _("List of settings");
3271  myopt.translate_header = true;
3272 
3273  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3274  }
3275 
3276  PQclear(res);
3277  resetPQExpBuffer(&buf);
3278  return true;
3279 }
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 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:2673
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
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:642
bool listDefaultACLs ( const char *  pattern)

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

1011 {
1013  PGresult *res;
1014  printQueryOpt myopt = pset.popt;
1015  static const bool translate_columns[] = {false, false, true, false};
1016 
1017  if (pset.sversion < 90000)
1018  {
1019  char sverbuf[32];
1020 
1021  psql_error("The server (version %s) does not support altering default privileges.\n",
1023  sverbuf, sizeof(sverbuf)));
1024  return true;
1025  }
1026 
1027  initPQExpBuffer(&buf);
1028 
1029  printfPQExpBuffer(&buf,
1030  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1031  " n.nspname AS \"%s\",\n"
1032  " 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"
1033  " ",
1034  gettext_noop("Owner"),
1035  gettext_noop("Schema"),
1037  gettext_noop("table"),
1039  gettext_noop("sequence"),
1041  gettext_noop("function"),
1043  gettext_noop("type"),
1045  gettext_noop("schema"),
1046  gettext_noop("Type"));
1047 
1048  printACLColumn(&buf, "d.defaclacl");
1049 
1050  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1051  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1052 
1053  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1054  NULL,
1055  "n.nspname",
1056  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1057  NULL);
1058 
1059  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1060 
1061  res = PSQLexec(buf.data);
1062  if (!res)
1063  {
1064  termPQExpBuffer(&buf);
1065  return false;
1066  }
1067 
1068  myopt.nullPrint = NULL;
1069  printfPQExpBuffer(&buf, _("Default access privileges"));
1070  myopt.title = buf.data;
1071  myopt.translate_header = true;
1072  myopt.translate_columns = translate_columns;
1073  myopt.n_translate_columns = lengthof(translate_columns);
1074 
1075  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1076 
1077  termPQExpBuffer(&buf);
1078  PQclear(res);
1079  return true;
1080 }
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:562
#define DEFACLOBJ_SEQUENCE
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
#define DEFACLOBJ_TYPE
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
#define DEFACLOBJ_NAMESPACE
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DEFACLOBJ_RELATION
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
#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:3285
const bool * translate_columns
Definition: print.h:170
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5313
#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:642
bool listDomains ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3529 of file describe.c.

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

3530 {
3532  PGresult *res;
3533  printQueryOpt myopt = pset.popt;
3534 
3535  initPQExpBuffer(&buf);
3536 
3537  printfPQExpBuffer(&buf,
3538  "SELECT n.nspname as \"%s\",\n"
3539  " t.typname as \"%s\",\n"
3540  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
3541  gettext_noop("Schema"),
3542  gettext_noop("Name"),
3543  gettext_noop("Type"));
3544 
3545  if (pset.sversion >= 90100)
3546  appendPQExpBuffer(&buf,
3547  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
3548  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
3549  gettext_noop("Collation"));
3550  appendPQExpBuffer(&buf,
3551  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
3552  " t.typdefault as \"%s\",\n"
3553  " pg_catalog.array_to_string(ARRAY(\n"
3554  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
3555  " ), ' ') as \"%s\"",
3556  gettext_noop("Nullable"),
3557  gettext_noop("Default"),
3558  gettext_noop("Check"));
3559 
3560  if (verbose)
3561  {
3562  if (pset.sversion >= 90200)
3563  {
3564  appendPQExpBufferStr(&buf, ",\n ");
3565  printACLColumn(&buf, "t.typacl");
3566  }
3567  appendPQExpBuffer(&buf,
3568  ",\n d.description as \"%s\"",
3569  gettext_noop("Description"));
3570  }
3571 
3572  appendPQExpBufferStr(&buf,
3573  "\nFROM pg_catalog.pg_type t\n"
3574  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
3575 
3576  if (verbose)
3577  appendPQExpBufferStr(&buf,
3578  " LEFT JOIN pg_catalog.pg_description d "
3579  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
3580  "AND d.objsubid = 0\n");
3581 
3582  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
3583 
3584  if (!showSystem && !pattern)
3585  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3586  " AND n.nspname <> 'information_schema'\n");
3587 
3588  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3589  "n.nspname", "t.typname", NULL,
3590  "pg_catalog.pg_type_is_visible(t.oid)");
3591 
3592  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3593 
3594  res = PSQLexec(buf.data);
3595  termPQExpBuffer(&buf);
3596  if (!res)
3597  return false;
3598 
3599  myopt.nullPrint = NULL;
3600  myopt.title = _("List of domains");
3601  myopt.translate_header = true;
3602 
3603  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3604 
3605  PQclear(res);
3606  return true;
3607 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5313
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 3691 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

3692 {
3694  PGresult *res;
3695  printQueryOpt myopt = pset.popt;
3696  static const bool translate_columns[] =
3697  {false, false, false, true, false, false, false};
3698 
3699  initPQExpBuffer(&buf);
3700 
3701  printfPQExpBuffer(&buf,
3702  "SELECT evtname as \"%s\", "
3703  "evtevent as \"%s\", "
3704  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
3705  " case evtenabled when 'O' then '%s'"
3706  " when 'R' then '%s'"
3707  " when 'A' then '%s'"
3708  " when 'D' then '%s' end as \"%s\",\n"
3709  " e.evtfoid::pg_catalog.regproc as \"%s\", "
3710  "pg_catalog.array_to_string(array(select x"
3711  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
3712  gettext_noop("Name"),
3713  gettext_noop("Event"),
3714  gettext_noop("Owner"),
3715  gettext_noop("enabled"),
3716  gettext_noop("replica"),
3717  gettext_noop("always"),
3718  gettext_noop("disabled"),
3719  gettext_noop("Enabled"),
3720  gettext_noop("Procedure"),
3721  gettext_noop("Tags"));
3722  if (verbose)
3723  appendPQExpBuffer(&buf,
3724  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
3725  gettext_noop("Description"));
3726  appendPQExpBufferStr(&buf,
3727  "\nFROM pg_catalog.pg_event_trigger e ");
3728 
3729  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3730  NULL, "evtname", NULL, NULL);
3731 
3732  appendPQExpBufferStr(&buf, "ORDER BY 1");
3733 
3734  res = PSQLexec(buf.data);
3735  termPQExpBuffer(&buf);
3736  if (!res)
3737  return false;
3738 
3739  myopt.nullPrint = NULL;
3740  myopt.title = _("List of event triggers");
3741  myopt.translate_header = true;
3742  myopt.translate_columns = translate_columns;
3743  myopt.n_translate_columns = lengthof(translate_columns);
3744 
3745  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3746 
3747  PQclear(res);
3748  return true;
3749 }
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:562
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
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:642
bool listExtensionContents ( const char *  pattern)

Definition at line 4939 of file describe.c.

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

Referenced by exec_command_d().

4940 {
4942  PGresult *res;
4943  int i;
4944 
4945  if (pset.sversion < 90100)
4946  {
4947  char sverbuf[32];
4948 
4949  psql_error("The server (version %s) does not support extensions.\n",
4951  sverbuf, sizeof(sverbuf)));
4952  return true;
4953  }
4954 
4955  initPQExpBuffer(&buf);
4956  printfPQExpBuffer(&buf,
4957  "SELECT e.extname, e.oid\n"
4958  "FROM pg_catalog.pg_extension e\n");
4959 
4960  processSQLNamePattern(pset.db, &buf, pattern,
4961  false, false,
4962  NULL, "e.extname", NULL,
4963  NULL);
4964 
4965  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4966 
4967  res = PSQLexec(buf.data);
4968  termPQExpBuffer(&buf);
4969  if (!res)
4970  return false;
4971 
4972  if (PQntuples(res) == 0)
4973  {
4974  if (!pset.quiet)
4975  {
4976  if (pattern)
4977  psql_error("Did not find any extension named \"%s\".\n",
4978  pattern);
4979  else
4980  psql_error("Did not find any extensions.\n");
4981  }
4982  PQclear(res);
4983  return false;
4984  }
4985 
4986  for (i = 0; i < PQntuples(res); i++)
4987  {
4988  const char *extname;
4989  const char *oid;
4990 
4991  extname = PQgetvalue(res, i, 0);
4992  oid = PQgetvalue(res, i, 1);
4993 
4994  if (!listOneExtensionContents(extname, oid))
4995  {
4996  PQclear(res);
4997  return false;
4998  }
4999  if (cancel_pressed)
5000  {
5001  PQclear(res);
5002  return false;
5003  }
5004  }
5005 
5006  PQclear(res);
5007  return true;
5008 }
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:3067
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:2673
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:66
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5011
void psql_error(const char *fmt,...)
Definition: common.c:220
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
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:642
bool listExtensions ( const char *  pattern)

Definition at line 4882 of file describe.c.

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

4883 {
4885  PGresult *res;
4886  printQueryOpt myopt = pset.popt;
4887 
4888  if (pset.sversion < 90100)
4889  {
4890  char sverbuf[32];
4891 
4892  psql_error("The server (version %s) does not support extensions.\n",
4894  sverbuf, sizeof(sverbuf)));
4895  return true;
4896  }
4897 
4898  initPQExpBuffer(&buf);
4899  printfPQExpBuffer(&buf,
4900  "SELECT e.extname AS \"%s\", "
4901  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4902  "FROM pg_catalog.pg_extension e "
4903  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4904  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4905  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4906  gettext_noop("Name"),
4907  gettext_noop("Version"),
4908  gettext_noop("Schema"),
4909  gettext_noop("Description"));
4910 
4911  processSQLNamePattern(pset.db, &buf, pattern,
4912  false, false,
4913  NULL, "e.extname", NULL,
4914  NULL);
4915 
4916  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4917 
4918  res = PSQLexec(buf.data);
4919  termPQExpBuffer(&buf);
4920  if (!res)
4921  return false;
4922 
4923  myopt.nullPrint = NULL;
4924  myopt.title = _("List of installed extensions");
4925  myopt.translate_header = true;
4926 
4927  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4928 
4929  PQclear(res);
4930  return true;
4931 }
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:66
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#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:642
bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 4578 of file describe.c.

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

4579 {
4581  PGresult *res;
4582  printQueryOpt myopt = pset.popt;
4583 
4584  if (pset.sversion < 80400)
4585  {
4586  char sverbuf[32];
4587 
4588  psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4590  sverbuf, sizeof(sverbuf)));
4591  return true;
4592  }
4593 
4594  initPQExpBuffer(&buf);
4595  printfPQExpBuffer(&buf,
4596  "SELECT fdw.fdwname AS \"%s\",\n"
4597  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4598  gettext_noop("Name"),
4599  gettext_noop("Owner"));
4600  if (pset.sversion >= 90100)
4601  appendPQExpBuffer(&buf,
4602  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4603  gettext_noop("Handler"));
4604  appendPQExpBuffer(&buf,
4605  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4606  gettext_noop("Validator"));
4607 
4608  if (verbose)
4609  {
4610  appendPQExpBufferStr(&buf, ",\n ");
4611  printACLColumn(&buf, "fdwacl");
4612  appendPQExpBuffer(&buf,
4613  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4614  " '(' || array_to_string(ARRAY(SELECT "
4615  " quote_ident(option_name) || ' ' || "
4616  " quote_literal(option_value) FROM "
4617  " pg_options_to_table(fdwoptions)), ', ') || ')' "
4618  " END AS \"%s\"",
4619  gettext_noop("FDW options"));
4620 
4621  if (pset.sversion >= 90100)
4622  appendPQExpBuffer(&buf,
4623  ",\n d.description AS \"%s\" ",
4624  gettext_noop("Description"));
4625  }
4626 
4627  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4628 
4629  if (verbose && pset.sversion >= 90100)
4630  appendPQExpBufferStr(&buf,
4631  "LEFT JOIN pg_catalog.pg_description d\n"
4632  " ON d.classoid = fdw.tableoid "
4633  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4634 
4635  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4636  NULL, "fdwname", NULL, NULL);
4637 
4638  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4639 
4640  res = PSQLexec(buf.data);
4641  termPQExpBuffer(&buf);
4642  if (!res)
4643  return false;
4644 
4645  myopt.nullPrint = NULL;
4646  myopt.title = _("List of foreign-data wrappers");
4647  myopt.translate_header = true;
4648 
4649  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4650 
4651  PQclear(res);
4652  return true;
4653 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5313
#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:642
bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 4661 of file describe.c.

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

4662 {
4664  PGresult *res;
4665  printQueryOpt myopt = pset.popt;
4666 
4667  if (pset.sversion < 80400)
4668  {
4669  char sverbuf[32];
4670 
4671  psql_error("The server (version %s) does not support foreign servers.\n",
4673  sverbuf, sizeof(sverbuf)));
4674  return true;
4675  }
4676 
4677  initPQExpBuffer(&buf);
4678  printfPQExpBuffer(&buf,
4679  "SELECT s.srvname AS \"%s\",\n"
4680  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4681  " f.fdwname AS \"%s\"",
4682  gettext_noop("Name"),
4683  gettext_noop("Owner"),
4684  gettext_noop("Foreign-data wrapper"));
4685 
4686  if (verbose)
4687  {
4688  appendPQExpBufferStr(&buf, ",\n ");
4689  printACLColumn(&buf, "s.srvacl");
4690  appendPQExpBuffer(&buf,
4691  ",\n"
4692  " s.srvtype AS \"%s\",\n"
4693  " s.srvversion AS \"%s\",\n"
4694  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4695  " '(' || array_to_string(ARRAY(SELECT "
4696  " quote_ident(option_name) || ' ' || "
4697  " quote_literal(option_value) FROM "
4698  " pg_options_to_table(srvoptions)), ', ') || ')' "
4699  " END AS \"%s\",\n"
4700  " d.description AS \"%s\"",
4701  gettext_noop("Type"),
4702  gettext_noop("Version"),
4703  gettext_noop("FDW options"),
4704  gettext_noop("Description"));
4705  }
4706 
4707  appendPQExpBufferStr(&buf,
4708  "\nFROM pg_catalog.pg_foreign_server s\n"
4709  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4710 
4711  if (verbose)
4712  appendPQExpBufferStr(&buf,
4713  "LEFT JOIN pg_description d\n "
4714  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4715  "AND d.objsubid = 0\n");
4716 
4717  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4718  NULL, "s.srvname", NULL, NULL);
4719 
4720  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4721 
4722  res = PSQLexec(buf.data);
4723  termPQExpBuffer(&buf);
4724  if (!res)
4725  return false;
4726 
4727  myopt.nullPrint = NULL;
4728  myopt.title = _("List of foreign servers");
4729  myopt.translate_header = true;
4730 
4731  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4732 
4733  PQclear(res);
4734  return true;
4735 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5313
#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:642
bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 4804 of file describe.c.

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

4805 {
4807  PGresult *res;
4808  printQueryOpt myopt = pset.popt;
4809 
4810  if (pset.sversion < 90100)
4811  {
4812  char sverbuf[32];
4813 
4814  psql_error("The server (version %s) does not support foreign tables.\n",
4816  sverbuf, sizeof(sverbuf)));
4817  return true;
4818  }
4819 
4820  initPQExpBuffer(&buf);
4821  printfPQExpBuffer(&buf,
4822  "SELECT n.nspname AS \"%s\",\n"
4823  " c.relname AS \"%s\",\n"
4824  " s.srvname AS \"%s\"",
4825  gettext_noop("Schema"),
4826  gettext_noop("Table"),
4827  gettext_noop("Server"));
4828 
4829  if (verbose)
4830  appendPQExpBuffer(&buf,
4831  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4832  " '(' || array_to_string(ARRAY(SELECT "
4833  " quote_ident(option_name) || ' ' || "
4834  " quote_literal(option_value) FROM "
4835  " pg_options_to_table(ftoptions)), ', ') || ')' "
4836  " END AS \"%s\",\n"
4837  " d.description AS \"%s\"",
4838  gettext_noop("FDW options"),
4839  gettext_noop("Description"));
4840 
4841  appendPQExpBufferStr(&buf,
4842  "\nFROM pg_catalog.pg_foreign_table ft\n"
4843  " INNER JOIN pg_catalog.pg_class c"
4844  " ON c.oid = ft.ftrelid\n"
4845  " INNER JOIN pg_catalog.pg_namespace n"
4846  " ON n.oid = c.relnamespace\n"
4847  " INNER JOIN pg_catalog.pg_foreign_server s"
4848  " ON s.oid = ft.ftserver\n");
4849  if (verbose)
4850  appendPQExpBufferStr(&buf,
4851  " LEFT JOIN pg_catalog.pg_description d\n"
4852  " ON d.classoid = c.tableoid AND "
4853  "d.objoid = c.oid AND d.objsubid = 0\n");
4854 
4855  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4856  "n.nspname", "c.relname", NULL,
4857  "pg_catalog.pg_table_is_visible(c.oid)");
4858 
4859  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4860 
4861  res = PSQLexec(buf.data);
4862  termPQExpBuffer(&buf);
4863  if (!res)
4864  return false;
4865 
4866  myopt.nullPrint = NULL;
4867  myopt.title = _("List of foreign tables");
4868  myopt.translate_header = true;
4869 
4870  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4871 
4872  PQclear(res);
4873  return true;
4874 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#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:642
bool listLanguages ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3454 of file describe.c.

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

3455 {
3457  PGresult *res;
3458  printQueryOpt myopt = pset.popt;
3459 
3460  initPQExpBuffer(&buf);
3461 
3462  printfPQExpBuffer(&buf,
3463  "SELECT l.lanname AS \"%s\",\n",
3464  gettext_noop("Name"));
3465  if (pset.sversion >= 80300)
3466  appendPQExpBuffer(&buf,
3467  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
3468  gettext_noop("Owner"));
3469 
3470  appendPQExpBuffer(&buf,
3471  " l.lanpltrusted AS \"%s\"",
3472  gettext_noop("Trusted"));
3473 
3474  if (verbose)
3475  {
3476  appendPQExpBuffer(&buf,
3477  ",\n NOT l.lanispl AS \"%s\",\n"
3478  " l.lanplcallfoid::regprocedure AS \"%s\",\n"
3479  " l.lanvalidator::regprocedure AS \"%s\",\n ",
3480  gettext_noop("Internal language"),
3481  gettext_noop("Call handler"),
3482  gettext_noop("Validator"));
3483  if (pset.sversion >= 90000)
3484  appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n ",
3485  gettext_noop("Inline handler"));
3486  printACLColumn(&buf, "l.lanacl");
3487  }
3488 
3489  appendPQExpBuffer(&buf,
3490  ",\n d.description AS \"%s\""
3491  "\nFROM pg_catalog.pg_language l\n"
3492  "LEFT JOIN pg_catalog.pg_description d\n"
3493  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
3494  " AND d.objsubid = 0\n",
3495  gettext_noop("Description"));
3496 
3497  if (pattern)
3498  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3499  NULL, "l.lanname", NULL, NULL);
3500 
3501  if (!showSystem && !pattern)
3502  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
3503 
3504 
3505  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3506 
3507  res = PSQLexec(buf.data);
3508  termPQExpBuffer(&buf);
3509  if (!res)
3510  return false;
3511 
3512  myopt.nullPrint = NULL;
3513  myopt.title = _("List of languages");
3514  myopt.translate_header = true;
3515 
3516  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3517 
3518  PQclear(res);
3519  return true;
3520 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5313
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listPublications ( const char *  pattern)

Definition at line 5049 of file describe.c.

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

5050 {
5052  PGresult *res;
5053  printQueryOpt myopt = pset.popt;
5054  static const bool translate_columns[] = {false, false, false, false, false, false};
5055 
5056  if (pset.sversion < 100000)
5057  {
5058  char sverbuf[32];
5059 
5060  psql_error("The server (version %s) does not support publications.\n",
5062  sverbuf, sizeof(sverbuf)));
5063  return true;
5064  }
5065 
5066  initPQExpBuffer(&buf);
5067 
5068  printfPQExpBuffer(&buf,
5069  "SELECT pubname AS \"%s\",\n"
5070  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5071  " puballtables AS \"%s\",\n"
5072  " pubinsert AS \"%s\",\n"
5073  " pubupdate AS \"%s\",\n"
5074  " pubdelete AS \"%s\"\n",
5075  gettext_noop("Name"),
5076  gettext_noop("Owner"),
5077  gettext_noop("All tables"),
5078  gettext_noop("Inserts"),
5079  gettext_noop("Updates"),
5080  gettext_noop("Deletes"));
5081 
5082  appendPQExpBufferStr(&buf,
5083  "\nFROM pg_catalog.pg_publication\n");
5084 
5085  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5086  NULL, "pubname", NULL,
5087  NULL);
5088 
5089  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5090 
5091  res = PSQLexec(buf.data);
5092  termPQExpBuffer(&buf);
5093  if (!res)
5094  return false;
5095 
5096  myopt.nullPrint = NULL;
5097  myopt.title = _("List of publications");
5098  myopt.translate_header = true;
5099  myopt.translate_columns = translate_columns;
5100  myopt.n_translate_columns = lengthof(translate_columns);
5101 
5102  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5103 
5104  PQclear(res);
5105 
5106  return true;
5107 }
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:562
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
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:642
bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3940 of file describe.c.

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

3941 {
3943  PGresult *res;
3944  printQueryOpt myopt = pset.popt;
3945 
3946  initPQExpBuffer(&buf);
3947  printfPQExpBuffer(&buf,
3948  "SELECT n.nspname AS \"%s\",\n"
3949  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
3950  gettext_noop("Name"),
3951  gettext_noop("Owner"));
3952 
3953  if (verbose)
3954  {
3955  appendPQExpBufferStr(&buf, ",\n ");
3956  printACLColumn(&buf, "n.nspacl");
3957  appendPQExpBuffer(&buf,
3958  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
3959  gettext_noop("Description"));
3960  }
3961 
3962  appendPQExpBuffer(&buf,
3963  "\nFROM pg_catalog.pg_namespace n\n");
3964 
3965  if (!showSystem && !pattern)
3966  appendPQExpBufferStr(&buf,
3967  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
3968 
3969  processSQLNamePattern(pset.db, &buf, pattern,
3970  !showSystem && !pattern, false,
3971  NULL, "n.nspname", NULL,
3972  NULL);
3973 
3974  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3975 
3976  res = PSQLexec(buf.data);
3977  termPQExpBuffer(&buf);
3978  if (!res)
3979  return false;
3980 
3981  myopt.nullPrint = NULL;
3982  myopt.title = _("List of schemas");
3983  myopt.translate_header = true;
3984 
3985  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3986 
3987  PQclear(res);
3988  return true;
3989 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5313
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listTables ( const char *  tabtypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3297 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, printQueryOpt::nullPrint, _psqlSettings::popt, PQclear(), PQntuples(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, 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().

3298 {
3299  bool showTables = strchr(tabtypes, 't') != NULL;
3300  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3301  bool showViews = strchr(tabtypes, 'v') != NULL;
3302  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3303  bool showSeq = strchr(tabtypes, 's') != NULL;
3304  bool showForeign = strchr(tabtypes, 'E') != NULL;
3305 
3307  PGresult *res;
3308  printQueryOpt myopt = pset.popt;
3309  static const bool translate_columns[] = {false, false, true, false, false, false, false};
3310 
3311  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3312  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3313  showTables = showViews = showMatViews = showSeq = showForeign = true;
3314 
3315  initPQExpBuffer(&buf);
3316 
3317  /*
3318  * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
3319  * it here for backwards compatibility.
3320  */
3321  printfPQExpBuffer(&buf,
3322  "SELECT n.nspname as \"%s\",\n"
3323  " c.relname as \"%s\",\n"
3324  " CASE c.relkind"
3325  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3326  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3327  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3328  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3329  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3330  " WHEN 's' THEN '%s'"
3331  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3332  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3333  " END as \"%s\",\n"
3334  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3335  gettext_noop("Schema"),
3336  gettext_noop("Name"),
3337  gettext_noop("table"),
3338  gettext_noop("view"),
3339  gettext_noop("materialized view"),
3340  gettext_noop("index"),
3341  gettext_noop("sequence"),
3342  gettext_noop("special"),
3343  gettext_noop("foreign table"),
3344  gettext_noop("table"), /* partitioned table */
3345  gettext_noop("Type"),
3346  gettext_noop("Owner"));
3347 
3348  if (showIndexes)
3349  appendPQExpBuffer(&buf,
3350  ",\n c2.relname as \"%s\"",
3351  gettext_noop("Table"));
3352 
3353  if (verbose)
3354  {
3355  /*
3356  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3357  * size of a table, including FSM, VM and TOAST tables.
3358  */
3359  if (pset.sversion >= 90000)
3360  appendPQExpBuffer(&buf,
3361  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3362  gettext_noop("Size"));
3363  else if (pset.sversion >= 80100)
3364  appendPQExpBuffer(&buf,
3365  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3366  gettext_noop("Size"));
3367 
3368  appendPQExpBuffer(&buf,
3369  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3370  gettext_noop("Description"));
3371  }
3372 
3373  appendPQExpBufferStr(&buf,
3374  "\nFROM pg_catalog.pg_class c"
3375  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3376  if (showIndexes)
3377  appendPQExpBufferStr(&buf,
3378  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3379  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3380 
3381  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3382  if (showTables)
3385  if (showViews)
3387  if (showMatViews)
3389  if (showIndexes)
3391  if (showSeq)
3393  if (showSystem || pattern)
3394  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3395  if (showForeign)
3397 
3398  appendPQExpBufferStr(&buf, "''"); /* dummy */
3399  appendPQExpBufferStr(&buf, ")\n");
3400 
3401  if (!showSystem && !pattern)
3402  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3403  " AND n.nspname <> 'information_schema'\n");
3404 
3405  /*
3406  * TOAST objects are suppressed unconditionally. Since we don't provide
3407  * any way to select RELKIND_TOASTVALUE above, we would never show toast
3408  * tables in any case; it seems a bit confusing to allow their indexes to
3409  * be shown. Use plain \d if you really need to look at a TOAST
3410  * table/index.
3411  */
3412  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3413 
3414  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3415  "n.nspname", "c.relname", NULL,
3416  "pg_catalog.pg_table_is_visible(c.oid)");
3417 
3418  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3419 
3420  res = PSQLexec(buf.data);
3421  termPQExpBuffer(&buf);
3422  if (!res)
3423  return false;
3424 
3425  if (PQntuples(res) == 0 && !pset.quiet)
3426  {
3427  if (pattern)
3428  fprintf(pset.queryFout, _("No matching relations found.\n"));
3429  else
3430  fprintf(pset.queryFout, _("No relations found.\n"));
3431  }
3432  else
3433  {
3434  myopt.nullPrint = NULL;
3435  myopt.title = _("List of relations");
3436  myopt.translate_header = true;
3437  myopt.translate_columns = translate_columns;
3438  myopt.n_translate_columns = lengthof(translate_columns);
3439 
3440  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3441  }
3442 
3443  PQclear(res);
3444  return true;
3445 }
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:562
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
#define CppAsString2(x)
Definition: c.h:162
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
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:3285
#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:642
bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

Definition at line 4377 of file describe.c.

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

4378 {
4380  PGresult *res;
4381  printQueryOpt myopt = pset.popt;
4382 
4383  if (pset.sversion < 80300)
4384  {
4385  char sverbuf[32];
4386 
4387  psql_error("The server (version %s) does not support full text search.\n",
4389  sverbuf, sizeof(sverbuf)));
4390  return true;
4391  }
4392 
4393  if (verbose)
4394  return listTSConfigsVerbose(pattern);
4395 
4396  initPQExpBuffer(&buf);
4397 
4398  printfPQExpBuffer(&buf,
4399  "SELECT\n"
4400  " n.nspname as \"%s\",\n"
4401  " c.cfgname as \"%s\",\n"
4402  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4403  "FROM pg_catalog.pg_ts_config c\n"
4404  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
4405  gettext_noop("Schema"),
4406  gettext_noop("Name"),
4407  gettext_noop("Description")
4408  );
4409 
4410  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4411  "n.nspname", "c.cfgname", NULL,
4412  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4413 
4414  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4415 
4416  res = PSQLexec(buf.data);
4417  termPQExpBuffer(&buf);
4418  if (!res)
4419  return false;
4420 
4421  myopt.nullPrint = NULL;
4422  myopt.title = _("List of text search configurations");
4423  myopt.translate_header = true;
4424 
4425  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4426 
4427  PQclear(res);
4428  return true;
4429 }
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:4432
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#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:642
bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 4235 of file describe.c.

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

4236 {
4238  PGresult *res;
4239  printQueryOpt myopt = pset.popt;
4240 
4241  if (pset.sversion < 80300)
4242  {
4243  char sverbuf[32];
4244 
4245  psql_error("The server (version %s) does not support full text search.\n",
4247  sverbuf, sizeof(sverbuf)));
4248  return true;
4249  }
4250 
4251  initPQExpBuffer(&buf);
4252 
4253  printfPQExpBuffer(&buf,
4254  "SELECT\n"
4255  " n.nspname as \"%s\",\n"
4256  " d.dictname as \"%s\",\n",
4257  gettext_noop("Schema"),
4258  gettext_noop("Name"));
4259 
4260  if (verbose)
4261  {
4262  appendPQExpBuffer(&buf,
4263  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
4264  " pg_catalog.pg_ts_template t\n"
4265  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
4266  " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
4267  " d.dictinitoption as \"%s\",\n",
4268  gettext_noop("Template"),
4269  gettext_noop("Init options"));
4270  }
4271 
4272  appendPQExpBuffer(&buf,
4273  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
4274  gettext_noop("Description"));
4275 
4276  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
4277  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
4278 
4279  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4280  "n.nspname", "d.dictname", NULL,
4281  "pg_catalog.pg_ts_dict_is_visible(d.oid)");
4282 
4283  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4284 
4285  res = PSQLexec(buf.data);
4286  termPQExpBuffer(&buf);
4287  if (!res)
4288  return false;
4289 
4290  myopt.nullPrint = NULL;
4291  myopt.title = _("List of text search dictionaries");
4292  myopt.translate_header = true;
4293 
4294  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4295 
4296  PQclear(res);
4297  return true;
4298 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#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:642
bool listTSParsers ( const char *  pattern,
bool  verbose 
)

Definition at line 3997 of file describe.c.

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

3998 {
4000  PGresult *res;
4001  printQueryOpt myopt = pset.popt;
4002 
4003  if (pset.sversion < 80300)
4004  {
4005  char sverbuf[32];
4006 
4007  psql_error("The server (version %s) does not support full text search.\n",
4009  sverbuf, sizeof(sverbuf)));
4010  return true;
4011  }
4012 
4013  if (verbose)
4014  return listTSParsersVerbose(pattern);
4015 
4016  initPQExpBuffer(&buf);
4017 
4018  printfPQExpBuffer(&buf,
4019  "SELECT\n"
4020  " n.nspname as \"%s\",\n"
4021  " p.prsname as \"%s\",\n"
4022  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
4023  "FROM pg_catalog.pg_ts_parser p\n"
4024  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
4025  gettext_noop("Schema"),
4026  gettext_noop("Name"),
4027  gettext_noop("Description")
4028  );
4029 
4030  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4031  "n.nspname", "p.prsname", NULL,
4032  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
4033 
4034  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4035 
4036  res = PSQLexec(buf.data);
4037  termPQExpBuffer(&buf);
4038  if (!res)
4039  return false;
4040 
4041  myopt.nullPrint = NULL;
4042  myopt.title = _("List of text search parsers");
4043  myopt.translate_header = true;
4044 
4045  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4046 
4047  PQclear(res);
4048  return true;
4049 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:4055
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#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:642
bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

Definition at line 4306 of file describe.c.

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

4307 {
4309  PGresult *res;
4310  printQueryOpt myopt = pset.popt;
4311 
4312  if (pset.sversion < 80300)
4313  {
4314  char sverbuf[32];
4315 
4316  psql_error("The server (version %s) does not support full text search.\n",
4318  sverbuf, sizeof(sverbuf)));
4319  return true;
4320  }
4321 
4322  initPQExpBuffer(&buf);
4323 
4324  if (verbose)
4325  printfPQExpBuffer(&buf,
4326  "SELECT\n"
4327  " n.nspname AS \"%s\",\n"
4328  " t.tmplname AS \"%s\",\n"
4329  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4330  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4331  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4332  gettext_noop("Schema"),
4333  gettext_noop("Name"),
4334  gettext_noop("Init"),
4335  gettext_noop("Lexize"),
4336  gettext_noop("Description"));
4337  else
4338  printfPQExpBuffer(&buf,
4339  "SELECT\n"
4340  " n.nspname AS \"%s\",\n"
4341  " t.tmplname AS \"%s\",\n"
4342  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4343  gettext_noop("Schema"),
4344  gettext_noop("Name"),
4345  gettext_noop("Description"));
4346 
4347  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4348  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4349 
4350  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4351  "n.nspname", "t.tmplname", NULL,
4352  "pg_catalog.pg_ts_template_is_visible(t.oid)");
4353 
4354  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4355 
4356  res = PSQLexec(buf.data);
4357  termPQExpBuffer(&buf);
4358  if (!res)
4359  return false;
4360 
4361  myopt.nullPrint = NULL;
4362  myopt.title = _("List of text search templates");
4363  myopt.translate_header = true;
4364 
4365  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4366 
4367  PQclear(res);
4368  return true;
4369 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#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:642
bool listUserMappings ( const char *  pattern,
bool  verbose 
)

Definition at line 4743 of file describe.c.

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

4744 {
4746  PGresult *res;
4747  printQueryOpt myopt = pset.popt;
4748 
4749  if (pset.sversion < 80400)
4750  {
4751  char sverbuf[32];
4752 
4753  psql_error("The server (version %s) does not support user mappings.\n",
4755  sverbuf, sizeof(sverbuf)));
4756  return true;
4757  }
4758 
4759  initPQExpBuffer(&buf);
4760  printfPQExpBuffer(&buf,
4761  "SELECT um.srvname AS \"%s\",\n"
4762  " um.usename AS \"%s\"",
4763  gettext_noop("Server"),
4764  gettext_noop("User name"));
4765 
4766  if (verbose)
4767  appendPQExpBuffer(&buf,
4768  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4769  " '(' || array_to_string(ARRAY(SELECT "
4770  " quote_ident(option_name) || ' ' || "
4771  " quote_literal(option_value) FROM "
4772  " pg_options_to_table(umoptions)), ', ') || ')' "
4773  " END AS \"%s\"",
4774  gettext_noop("FDW options"));
4775 
4776  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4777 
4778  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4779  NULL, "um.srvname", "um.usename", NULL);
4780 
4781  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4782 
4783  res = PSQLexec(buf.data);
4784  termPQExpBuffer(&buf);
4785  if (!res)
4786  return false;
4787 
4788  myopt.nullPrint = NULL;
4789  myopt.title = _("List of user mappings");
4790  myopt.translate_header = true;
4791 
4792  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4793 
4794  PQclear(res);
4795  return true;
4796 }
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:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#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:642
bool objectDescription ( const char *  pattern,
bool  showSystem 
)

Definition at line 1095 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

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

Definition at line 850 of file describe.c.

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, PQExpBufferData::data, _psqlSettings::db, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, NULL, 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().

851 {
853  PGresult *res;
854  printQueryOpt myopt = pset.popt;
855  static const bool translate_columns[] = {false, false, true, false, false, false};
856 
857  initPQExpBuffer(&buf);
858 
859  /*
860  * we ignore indexes and toast tables since they have no meaningful rights
861  */
862  printfPQExpBuffer(&buf,
863  "SELECT n.nspname as \"%s\",\n"
864  " c.relname as \"%s\",\n"
865  " CASE c.relkind"
866  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
867  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
868  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
869  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
870  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
871  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
872  " END as \"%s\",\n"
873  " ",
874  gettext_noop("Schema"),
875  gettext_noop("Name"),
876  gettext_noop("table"),
877  gettext_noop("view"),
878  gettext_noop("materialized view"),
879  gettext_noop("sequence"),
880  gettext_noop("foreign table"),
881  gettext_noop("table"), /* partitioned table */
882  gettext_noop("Type"));
883 
884  printACLColumn(&buf, "c.relacl");
885 
886  if (pset.sversion >= 80400)
887  appendPQExpBuffer(&buf,
888  ",\n pg_catalog.array_to_string(ARRAY(\n"
889  " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
890  " FROM pg_catalog.pg_attribute a\n"
891  " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
892  " ), E'\\n') AS \"%s\"",
893  gettext_noop("Column privileges"));
894 
895  if (pset.sversion >= 90500 && pset.sversion < 100000)
896  appendPQExpBuffer(&buf,
897  ",\n pg_catalog.array_to_string(ARRAY(\n"
898  " SELECT polname\n"
899  " || CASE WHEN polcmd != '*' THEN\n"
900  " E' (' || polcmd || E'):'\n"
901  " ELSE E':'\n"
902  " END\n"
903  " || CASE WHEN polqual IS NOT NULL THEN\n"
904  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
905  " ELSE E''\n"
906  " END\n"