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

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

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

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

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

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

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

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

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

4951 {
4953  int i;
4954  PGresult *res;
4955 
4956  if (pset.sversion < 100000)
4957  {
4958  char sverbuf[32];
4959  psql_error("The server (version %s) does not support publications.\n",
4961  sverbuf, sizeof(sverbuf)));
4962  return true;
4963  }
4964 
4965  initPQExpBuffer(&buf);
4966 
4967  printfPQExpBuffer(&buf,
4968  "SELECT oid, pubname, puballtables, pubinsert,\n"
4969  " pubupdate, pubdelete\n"
4970  "FROM pg_catalog.pg_publication\n");
4971 
4972  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4973  NULL, "pubname", NULL,
4974  NULL);
4975 
4976  appendPQExpBufferStr(&buf, "ORDER BY 2;");
4977 
4978  res = PSQLexec(buf.data);
4979  if (!res)
4980  {
4981  termPQExpBuffer(&buf);
4982  return false;
4983  }
4984 
4985  for (i = 0; i < PQntuples(res); i++)
4986  {
4987  const char align = 'l';
4988  int ncols = 3;
4989  int nrows = 1;
4990  int tables = 0;
4991  PGresult *tabres;
4992  char *pubid = PQgetvalue(res, i, 0);
4993  char *pubname = PQgetvalue(res, i, 1);
4994  bool puballtables = strcmp(PQgetvalue(res, i, 2), "t") == 0;
4995  int j;
4996  PQExpBufferData title;
4997  printTableOpt myopt = pset.popt.topt;
4998  printTableContent cont;
4999 
5000  initPQExpBuffer(&title);
5001  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5002  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5003 
5004  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5005  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5006  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5007 
5008  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5009  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5010  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5011 
5012  if (puballtables)
5013  printfPQExpBuffer(&buf,
5014  "SELECT n.nspname, c.relname\n"
5015  "FROM pg_catalog.pg_class c,\n"
5016  " pg_catalog.pg_namespace n\n"
5017  "WHERE c.relnamespace = n.oid\n"
5018  " AND c.relkind = 'r'\n"
5019  " AND n.nspname <> 'pg_catalog'\n"
5020  " AND n.nspname <> 'information_schema'\n"
5021  "ORDER BY 1,2");
5022  else
5023  printfPQExpBuffer(&buf,
5024  "SELECT n.nspname, c.relname\n"
5025  "FROM pg_catalog.pg_class c,\n"
5026  " pg_catalog.pg_namespace n,\n"
5027  " pg_catalog.pg_publication_rel pr\n"
5028  "WHERE c.relnamespace = n.oid\n"
5029  " AND c.oid = pr.prrelid\n"
5030  " AND pr.prpubid = '%s'\n"
5031  "ORDER BY 1,2", pubid);
5032 
5033  tabres = PSQLexec(buf.data);
5034  if (!tabres)
5035  {
5036  printTableCleanup(&cont);
5037  PQclear(res);
5038  termPQExpBuffer(&buf);
5039  termPQExpBuffer(&title);
5040  return false;
5041  }
5042  else
5043  tables = PQntuples(tabres);
5044 
5045  if (tables > 0)
5046  printTableAddFooter(&cont, _("Tables:"));
5047 
5048  for (j = 0; j < tables; j++)
5049  {
5050  printfPQExpBuffer(&buf, " \"%s.%s\"",
5051  PQgetvalue(tabres, j, 0),
5052  PQgetvalue(tabres, j, 1));
5053 
5054  printTableAddFooter(&cont, buf.data);
5055  }
5056  PQclear(tabres);
5057 
5058  printTable(&cont, pset.queryFout, false, pset.logfile);
5059  printTableCleanup(&cont);
5060 
5061  termPQExpBuffer(&title);
5062  }
5063 
5064  termPQExpBuffer(&buf);
5065  PQclear(res);
5066 
5067  return true;
5068 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:37
void printTableCleanup(printTableContent *const content)
Definition: print.c:3100
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:817
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:2969
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3009
static char * buf
Definition: pg_test_fsync.c:65
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3189
void psql_error(const char *fmt,...)
Definition: common.c:177
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3057
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:226
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:2932
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:599
bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

2897 {
2899  PGresult *res;
2900  printTableContent cont;
2901  printTableOpt myopt = pset.popt.topt;
2902  int ncols = 3;
2903  int nrows = 0;
2904  int i;
2905  int conns;
2906  const char align = 'l';
2907  char **attr;
2908 
2909  myopt.default_footer = false;
2910 
2911  initPQExpBuffer(&buf);
2912 
2913  if (pset.sversion >= 80100)
2914  {
2915  printfPQExpBuffer(&buf,
2916  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
2917  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
2918  " r.rolconnlimit, r.rolvaliduntil,\n"
2919  " ARRAY(SELECT b.rolname\n"
2920  " FROM pg_catalog.pg_auth_members m\n"
2921  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
2922  " WHERE m.member = r.oid) as memberof");
2923 
2924  if (verbose && pset.sversion >= 80200)
2925  {
2926  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
2927  ncols++;
2928  }
2929  if (pset.sversion >= 90100)
2930  {
2931  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
2932  }
2933 
2934  if (pset.sversion >= 90500)
2935  {
2936  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
2937  }
2938 
2939  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
2940 
2941  if (!showSystem && !pattern)
2942  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
2943 
2944  processSQLNamePattern(pset.db, &buf, pattern, false, false,
2945  NULL, "r.rolname", NULL, NULL);
2946  }
2947  else
2948  {
2949  printfPQExpBuffer(&buf,
2950  "SELECT u.usename AS rolname,\n"
2951  " u.usesuper AS rolsuper,\n"
2952  " true AS rolinherit, false AS rolcreaterole,\n"
2953  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
2954  " -1 AS rolconnlimit,"
2955  " u.valuntil as rolvaliduntil,\n"
2956  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
2957  "\nFROM pg_catalog.pg_user u\n");
2958 
2959  processSQLNamePattern(pset.db, &buf, pattern, false, false,
2960  NULL, "u.usename", NULL, NULL);
2961  }
2962 
2963  appendPQExpBufferStr(&buf, "ORDER BY 1;");
2964 
2965  res = PSQLexec(buf.data);
2966  if (!res)
2967  return false;
2968 
2969  nrows = PQntuples(res);
2970  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
2971 
2972  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
2973 
2974  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
2975  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
2976  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
2977 
2978  if (verbose && pset.sversion >= 80200)
2979  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
2980 
2981  for (i = 0; i < nrows; i++)
2982  {
2983  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
2984 
2985  resetPQExpBuffer(&buf);
2986  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
2987  add_role_attribute(&buf, _("Superuser"));
2988 
2989  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
2990  add_role_attribute(&buf, _("No inheritance"));
2991 
2992  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
2993  add_role_attribute(&buf, _("Create role"));
2994 
2995  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
2996  add_role_attribute(&buf, _("Create DB"));
2997 
2998  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
2999  add_role_attribute(&buf, _("Cannot login"));
3000 
3001  if (pset.sversion >= 90100)
3002  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3003  add_role_attribute(&buf, _("Replication"));
3004 
3005  if (pset.sversion >= 90500)
3006  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3007  add_role_attribute(&buf, _("Bypass RLS"));
3008 
3009  conns = atoi(PQgetvalue(res, i, 6));
3010  if (conns >= 0)
3011  {
3012  if (buf.len > 0)
3013  appendPQExpBufferChar(&buf, '\n');
3014 
3015  if (conns == 0)
3016  appendPQExpBufferStr(&buf, _("No connections"));
3017  else
3018  appendPQExpBuffer(&buf, ngettext("%d connection",
3019  "%d connections",
3020  conns),
3021  conns);
3022  }
3023 
3024  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3025  {
3026  if (buf.len > 0)
3027  appendPQExpBufferStr(&buf, "\n");
3028  appendPQExpBufferStr(&buf, _("Password valid until "));
3029  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3030  }
3031 
3032  attr[i] = pg_strdup(buf.data);
3033 
3034  printTableAddCell(&cont, attr[i], false, false);
3035 
3036  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3037 
3038  if (verbose && pset.sversion >= 80200)
3039  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3040  }
3041  termPQExpBuffer(&buf);
3042 
3043  printTable(&cont, pset.queryFout, false, pset.logfile);
3044  printTableCleanup(&cont);
3045 
3046  for (i = 0; i < nrows; i++)
3047  free(attr[i]);
3048  free(attr);
3049 
3050  PQclear(res);
3051  return true;
3052 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:37
void printTableCleanup(printTableContent *const content)
Definition: print.c:3100
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:817
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3055
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2969
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:3009
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
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:3189
static int verbose
Definition: pg_basebackup.c:87
#define ngettext(s, p, n)
Definition: c.h:127
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define free(a)
Definition: header.h:60
bool default_footer
Definition: print.h:110
#define NULL
Definition: c.h:226
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:2932
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:599
bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

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

5077 {
5079  PGresult *res;
5080  printQueryOpt myopt = pset.popt;
5081  static const bool translate_columns[] = {false, false, false, false, false};
5082 
5083  if (pset.sversion < 100000)
5084  {
5085  char sverbuf[32];
5086  psql_error("The server (version %s) does not support subscriptions.\n",
5088  sverbuf, sizeof(sverbuf)));
5089  return true;
5090  }
5091 
5092  initPQExpBuffer(&buf);
5093 
5094  printfPQExpBuffer(&buf,
5095  "SELECT subname AS \"%s\"\n"
5096  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5097  ", subenabled AS \"%s\"\n"
5098  ", subpublications AS \"%s\"\n",
5099  gettext_noop("Name"),
5100  gettext_noop("Owner"),
5101  gettext_noop("Enabled"),
5102  gettext_noop("Publication"));
5103 
5104  if (verbose)
5105  {
5106  appendPQExpBuffer(&buf,
5107  ", subconninfo AS \"%s\"\n",
5108  gettext_noop("Conninfo"));
5109  }
5110 
5111  /* Only display subscriptions in current database. */
5112  appendPQExpBufferStr(&buf,
5113  "FROM pg_catalog.pg_subscription\n"
5114  "WHERE subdbid = (SELECT oid\n"
5115  " FROM pg_catalog.pg_database\n"
5116  " WHERE datname = current_database())");
5117 
5118  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5119  NULL, "subname", NULL,
5120  NULL);
5121 
5122  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5123 
5124  res = PSQLexec(buf.data);
5125  termPQExpBuffer(&buf);
5126  if (!res)
5127  return false;
5128 
5129  myopt.nullPrint = NULL;
5130  myopt.title = _("List of subscriptions");
5131  myopt.translate_header = true;
5132  myopt.translate_columns = translate_columns;
5133  myopt.n_translate_columns = lengthof(translate_columns);
5134 
5135  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5136 
5137  PQclear(res);
5138  return true;
5139 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
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:3286
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:599
bool describeTableDetails ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

1277 {
1279  PGresult *res;
1280  int i;
1281 
1282  initPQExpBuffer(&buf);
1283 
1284  printfPQExpBuffer(&buf,
1285  "SELECT c.oid,\n"
1286  " n.nspname,\n"
1287  " c.relname\n"
1288  "FROM pg_catalog.pg_class c\n"
1289  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1290 
1291  if (!showSystem && !pattern)
1292  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1293  " AND n.nspname <> 'information_schema'\n");
1294 
1295  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1296  "n.nspname", "c.relname", NULL,
1297  "pg_catalog.pg_table_is_visible(c.oid)");
1298 
1299  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1300 
1301  res = PSQLexec(buf.data);
1302  termPQExpBuffer(&buf);
1303  if (!res)
1304  return false;
1305 
1306  if (PQntuples(res) == 0)
1307  {
1308  if (!pset.quiet)
1309  psql_error("Did not find any relation named \"%s\".\n",
1310  pattern);
1311  PQclear(res);
1312  return false;
1313  }
1314 
1315  for (i = 0; i < PQntuples(res); i++)
1316  {
1317  const char *oid;
1318  const char *nspname;
1319  const char *relname;
1320 
1321  oid = PQgetvalue(res, i, 0);
1322  nspname = PQgetvalue(res, i, 1);
1323  relname = PQgetvalue(res, i, 2);
1324 
1325  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1326  {
1327  PQclear(res);
1328  return false;
1329  }
1330  if (cancel_pressed)
1331  {
1332  PQclear(res);
1333  return false;
1334  }
1335  }
1336 
1337  PQclear(res);
1338  return true;
1339 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:37
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:817
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
volatile bool cancel_pressed
Definition: print.c:47
static char * buf
Definition: pg_test_fsync.c:65
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1349
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:226
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:599
bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

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

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

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

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

Definition at line 777 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(), and main().

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

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

3601 {
3603  PGresult *res;
3604  printQueryOpt myopt = pset.popt;
3605  static const bool translate_columns[] = {false, false, false, true, false};
3606 
3607  initPQExpBuffer(&buf);
3608 
3609  /*
3610  * We need a left join to pg_proc for binary casts; the others are just
3611  * paranoia. Also note that we don't attempt to localize '(binary
3612  * coercible)', because there's too much risk of gettext translating a
3613  * function name that happens to match some string in the PO database.
3614  */
3615  printfPQExpBuffer(&buf,
3616  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3617  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3618  " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3619  " ELSE p.proname\n"
3620  " END as \"%s\",\n"
3621  " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3622  " WHEN c.castcontext = 'a' THEN '%s'\n"
3623  " ELSE '%s'\n"
3624  " END as \"%s\"",
3625  gettext_noop("Source type"),
3626  gettext_noop("Target type"),
3627  gettext_noop("Function"),
3628  gettext_noop("no"),
3629  gettext_noop("in assignment"),
3630  gettext_noop("yes"),
3631  gettext_noop("Implicit?"));
3632 
3633  if (verbose)
3634  appendPQExpBuffer(&buf,
3635  ",\n d.description AS \"%s\"\n",
3636  gettext_noop("Description"));
3637 
3638  appendPQExpBufferStr(&buf,
3639  "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
3640  " ON c.castfunc = p.oid\n"
3641  " LEFT JOIN pg_catalog.pg_type ts\n"
3642  " ON c.castsource = ts.oid\n"
3643  " LEFT JOIN pg_catalog.pg_namespace ns\n"
3644  " ON ns.oid = ts.typnamespace\n"
3645  " LEFT JOIN pg_catalog.pg_type tt\n"
3646  " ON c.casttarget = tt.oid\n"
3647  " LEFT JOIN pg_catalog.pg_namespace nt\n"
3648  " ON nt.oid = tt.typnamespace\n");
3649 
3650  if (verbose)
3651  appendPQExpBufferStr(&buf,
3652  " LEFT JOIN pg_catalog.pg_description d\n"
3653  " ON d.classoid = c.tableoid AND d.objoid = "
3654  "c.oid AND d.objsubid = 0\n");
3655 
3656  appendPQExpBufferStr(&buf, "WHERE ( (true");
3657 
3658  /*
3659  * Match name pattern against either internal or external name of either
3660  * castsource or casttarget
3661  */
3662  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3663  "ns.nspname", "ts.typname",
3664  "pg_catalog.format_type(ts.oid, NULL)",
3665  "pg_catalog.pg_type_is_visible(ts.oid)");
3666 
3667  appendPQExpBufferStr(&buf, ") OR (true");
3668 
3669  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3670  "nt.nspname", "tt.typname",
3671  "pg_catalog.format_type(tt.oid, NULL)",
3672  "pg_catalog.pg_type_is_visible(tt.oid)");
3673 
3674  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
3675 
3676  res = PSQLexec(buf.data);
3677  termPQExpBuffer(&buf);
3678  if (!res)
3679  return false;
3680 
3681  myopt.nullPrint = NULL;
3682  myopt.title = _("List of casts");
3683  myopt.translate_header = true;
3684  myopt.translate_columns = translate_columns;
3685  myopt.n_translate_columns = lengthof(translate_columns);
3686 
3687  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3688 
3689  PQclear(res);
3690  return true;
3691 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
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:3286
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:599
bool listCollations ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3700 {
3702  PGresult *res;
3703  printQueryOpt myopt = pset.popt;
3704  static const bool translate_columns[] = {false, false, false, false, false};
3705 
3706  if (pset.sversion < 90100)
3707  {
3708  char sverbuf[32];
3709 
3710  psql_error("The server (version %s) does not support collations.\n",
3712  sverbuf, sizeof(sverbuf)));
3713  return true;
3714  }
3715 
3716  initPQExpBuffer(&buf);
3717 
3718  printfPQExpBuffer(&buf,
3719  "SELECT n.nspname AS \"%s\",\n"
3720  " c.collname AS \"%s\",\n"
3721  " c.collcollate AS \"%s\",\n"
3722  " c.collctype AS \"%s\"",
3723  gettext_noop("Schema"),
3724  gettext_noop("Name"),
3725  gettext_noop("Collate"),
3726  gettext_noop("Ctype"));
3727 
3728  if (verbose)
3729  appendPQExpBuffer(&buf,
3730  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
3731  gettext_noop("Description"));
3732 
3733  appendPQExpBufferStr(&buf,
3734  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
3735  "WHERE n.oid = c.collnamespace\n");
3736 
3737  if (!showSystem && !pattern)
3738  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3739  " AND n.nspname <> 'information_schema'\n");
3740 
3741  /*
3742  * Hide collations that aren't usable in the current database's encoding.
3743  * If you think to change this, note that pg_collation_is_visible rejects
3744  * unusable collations, so you will need to hack name pattern processing
3745  * somehow to avoid inconsistent behavior.
3746  */
3747  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
3748 
3749  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3750  "n.nspname", "c.collname", NULL,
3751  "pg_catalog.pg_collation_is_visible(c.oid)");
3752 
3753  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3754 
3755  res = PSQLexec(buf.data);
3756  termPQExpBuffer(&buf);
3757  if (!res)
3758  return false;
3759 
3760  myopt.nullPrint = NULL;
3761  myopt.title = _("List of collations");
3762  myopt.translate_header = true;
3763  myopt.translate_columns = translate_columns;
3764  myopt.n_translate_columns = lengthof(translate_columns);
3765 
3766  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3767 
3768  PQclear(res);
3769  return true;
3770 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
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:3286
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:599
bool listConversions ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3459 {
3461  PGresult *res;
3462  printQueryOpt myopt = pset.popt;
3463  static const bool translate_columns[] =
3464  {false, false, false, false, true, false};
3465 
3466  initPQExpBuffer(&buf);
3467 
3468  printfPQExpBuffer(&buf,
3469  "SELECT n.nspname AS \"%s\",\n"
3470  " c.conname AS \"%s\",\n"
3471  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
3472  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
3473  " CASE WHEN c.condefault THEN '%s'\n"
3474  " ELSE '%s' END AS \"%s\"",
3475  gettext_noop("Schema"),
3476  gettext_noop("Name"),
3477  gettext_noop("Source"),
3478  gettext_noop("Destination"),
3479  gettext_noop("yes"), gettext_noop("no"),
3480  gettext_noop("Default?"));
3481 
3482  if (verbose)
3483  appendPQExpBuffer(&buf,
3484  ",\n d.description AS \"%s\"",
3485  gettext_noop("Description"));
3486 
3487  appendPQExpBufferStr(&buf,
3488  "\nFROM pg_catalog.pg_conversion c\n"
3489  " JOIN pg_catalog.pg_namespace n "
3490  "ON n.oid = c.connamespace\n");
3491 
3492  if (verbose)
3493  appendPQExpBufferStr(&buf,
3494  "LEFT JOIN pg_catalog.pg_description d "
3495  "ON d.classoid = c.tableoid\n"
3496  " AND d.objoid = c.oid "
3497  "AND d.objsubid = 0\n");
3498 
3499  appendPQExpBufferStr(&buf, "WHERE true\n");
3500 
3501  if (!showSystem && !pattern)
3502  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3503  " AND n.nspname <> 'information_schema'\n");
3504 
3505  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3506  "n.nspname", "c.conname", NULL,
3507  "pg_catalog.pg_conversion_is_visible(c.oid)");
3508 
3509  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3510 
3511  res = PSQLexec(buf.data);
3512  termPQExpBuffer(&buf);
3513  if (!res)
3514  return false;
3515 
3516  myopt.nullPrint = NULL;
3517  myopt.title = _("List of conversions");
3518  myopt.translate_header = true;
3519  myopt.translate_columns = translate_columns;
3520  myopt.n_translate_columns = lengthof(translate_columns);
3521 
3522  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3523 
3524  PQclear(res);
3525  return true;
3526 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
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:3286
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:599
bool listDbRoleSettings ( const char *  pattern1,
const char *  pattern2 
)

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

3068 {
3070  PGresult *res;
3071  printQueryOpt myopt = pset.popt;
3072 
3073  initPQExpBuffer(&buf);
3074 
3075  if (pset.sversion >= 90000)
3076  {
3077  bool havewhere;
3078 
3079  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3080  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3081  "FROM pg_db_role_setting AS s\n"
3082  "LEFT JOIN pg_database ON pg_database.oid = setdatabase\n"
3083  "LEFT JOIN pg_roles ON pg_roles.oid = setrole\n",
3084  gettext_noop("Role"),
3085  gettext_noop("Database"),
3086  gettext_noop("Settings"));
3087  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3088  NULL, "pg_roles.rolname", NULL, NULL);
3089  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3090  NULL, "pg_database.datname", NULL, NULL);
3091  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3092  }
3093  else
3094  {
3095  fprintf(pset.queryFout,
3096  _("No per-database role settings support in this server version.\n"));
3097  return false;
3098  }
3099 
3100  res = PSQLexec(buf.data);
3101  if (!res)
3102  return false;
3103 
3104  if (PQntuples(res) == 0 && !pset.quiet)
3105  {
3106  if (pattern)
3107  fprintf(pset.queryFout, _("No matching settings found.\n"));
3108  else
3109  fprintf(pset.queryFout, _("No settings found.\n"));
3110  }
3111  else
3112  {
3113  myopt.nullPrint = NULL;
3114  myopt.title = _("List of settings");
3115  myopt.translate_header = true;
3116 
3117  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3118  }
3119 
3120  PQclear(res);
3121  resetPQExpBuffer(&buf);
3122  return true;
3123 }
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:37
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:817
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
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:599
bool listDefaultACLs ( const char *  pattern)

Definition at line 1001 of file describe.c.

References _, appendPQExpBufferStr(), buf, PQExpBufferData::data, _psqlSettings::db, DEFACLOBJ_FUNCTION, 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().

1002 {
1004  PGresult *res;
1005  printQueryOpt myopt = pset.popt;
1006  static const bool translate_columns[] = {false, false, true, false};
1007 
1008  if (pset.sversion < 90000)
1009  {
1010  char sverbuf[32];
1011 
1012  psql_error("The server (version %s) does not support altering default privileges.\n",
1014  sverbuf, sizeof(sverbuf)));
1015  return true;
1016  }
1017 
1018  initPQExpBuffer(&buf);
1019 
1020  printfPQExpBuffer(&buf,
1021  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1022  " n.nspname AS \"%s\",\n"
1023  " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1024  " ",
1025  gettext_noop("Owner"),
1026  gettext_noop("Schema"),
1028  gettext_noop("table"),
1030  gettext_noop("sequence"),
1032  gettext_noop("function"),
1034  gettext_noop("type"),
1035  gettext_noop("Type"));
1036 
1037  printACLColumn(&buf, "d.defaclacl");
1038 
1039  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1040  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1041 
1042  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1043  NULL,
1044  "n.nspname",
1045  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1046  NULL);
1047 
1048  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1049 
1050  res = PSQLexec(buf.data);
1051  if (!res)
1052  {
1053  termPQExpBuffer(&buf);
1054  return false;
1055  }
1056 
1057  myopt.nullPrint = NULL;
1058  printfPQExpBuffer(&buf, _("Default access privileges"));
1059  myopt.title = buf.data;
1060  myopt.translate_header = true;
1061  myopt.translate_columns = translate_columns;
1062  myopt.n_translate_columns = lengthof(translate_columns);
1063 
1064  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1065 
1066  termPQExpBuffer(&buf);
1067  PQclear(res);
1068  return true;
1069 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
#define DEFACLOBJ_SEQUENCE
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
#define DEFACLOBJ_TYPE
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DEFACLOBJ_RELATION
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
#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:3286
const bool * translate_columns
Definition: print.h:170
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5149
#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:599
bool listDomains ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3373 {
3375  PGresult *res;
3376  printQueryOpt myopt = pset.popt;
3377 
3378  initPQExpBuffer(&buf);
3379 
3380  printfPQExpBuffer(&buf,
3381  "SELECT n.nspname as \"%s\",\n"
3382  " t.typname as \"%s\",\n"
3383  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
3384  gettext_noop("Schema"),
3385  gettext_noop("Name"),
3386  gettext_noop("Type"));
3387 
3388  if (pset.sversion >= 90100)
3389  appendPQExpBuffer(&buf,
3390  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
3391  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
3392  gettext_noop("Collation"));
3393  appendPQExpBuffer(&buf,
3394  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
3395  " t.typdefault as \"%s\",\n"
3396  " pg_catalog.array_to_string(ARRAY(\n"
3397  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
3398  " ), ' ') as \"%s\"",
3399  gettext_noop("Nullable"),
3400  gettext_noop("Default"),
3401  gettext_noop("Check"));
3402 
3403  if (verbose)
3404  {
3405  if (pset.sversion >= 90200)
3406  {
3407  appendPQExpBufferStr(&buf, ",\n ");
3408  printACLColumn(&buf, "t.typacl");
3409  }
3410  appendPQExpBuffer(&buf,
3411  ",\n d.description as \"%s\"",
3412  gettext_noop("Description"));
3413  }
3414 
3415  appendPQExpBufferStr(&buf,
3416  "\nFROM pg_catalog.pg_type t\n"
3417  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
3418 
3419  if (verbose)
3420  appendPQExpBufferStr(&buf,
3421  " LEFT JOIN pg_catalog.pg_description d "
3422  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
3423  "AND d.objsubid = 0\n");
3424 
3425  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
3426 
3427  if (!showSystem && !pattern)
3428  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3429  " AND n.nspname <> 'information_schema'\n");
3430 
3431  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3432  "n.nspname", "t.typname", NULL,
3433  "pg_catalog.pg_type_is_visible(t.oid)");
3434 
3435  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3436 
3437  res = PSQLexec(buf.data);
3438  termPQExpBuffer(&buf);
3439  if (!res)
3440  return false;
3441 
3442  myopt.nullPrint = NULL;
3443  myopt.title = _("List of domains");
3444  myopt.translate_header = true;
3445 
3446  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3447 
3448  PQclear(res);
3449  return true;
3450 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5149
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:599
bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

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

3535 {
3537  PGresult *res;
3538  printQueryOpt myopt = pset.popt;
3539  static const bool translate_columns[] =
3540  {false, false, false, true, false, false, false};
3541 
3542  initPQExpBuffer(&buf);
3543 
3544  printfPQExpBuffer(&buf,
3545  "SELECT evtname as \"%s\", "
3546  "evtevent as \"%s\", "
3547  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
3548  " case evtenabled when 'O' then '%s'"
3549  " when 'R' then '%s'"
3550  " when 'A' then '%s'"
3551  " when 'D' then '%s' end as \"%s\",\n"
3552  " e.evtfoid::pg_catalog.regproc as \"%s\", "
3553  "pg_catalog.array_to_string(array(select x"
3554  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
3555  gettext_noop("Name"),
3556  gettext_noop("Event"),
3557  gettext_noop("Owner"),
3558  gettext_noop("enabled"),
3559  gettext_noop("replica"),
3560  gettext_noop("always"),
3561  gettext_noop("disabled"),
3562  gettext_noop("Enabled"),
3563  gettext_noop("Procedure"),
3564  gettext_noop("Tags"));
3565  if (verbose)
3566  appendPQExpBuffer(&buf,
3567  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
3568  gettext_noop("Description"));
3569  appendPQExpBufferStr(&buf,
3570  "\nFROM pg_catalog.pg_event_trigger e ");
3571 
3572  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3573  NULL, "evtname", NULL, NULL);
3574 
3575  appendPQExpBufferStr(&buf, "ORDER BY 1");
3576 
3577  res = PSQLexec(buf.data);
3578  termPQExpBuffer(&buf);
3579  if (!res)
3580  return false;
3581 
3582  myopt.nullPrint = NULL;
3583  myopt.title = _("List of event triggers");
3584  myopt.translate_header = true;
3585  myopt.translate_columns = translate_columns;
3586  myopt.n_translate_columns = lengthof(translate_columns);
3587 
3588  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3589 
3590  PQclear(res);
3591  return true;
3592 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
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:3286
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:599
bool listExtensionContents ( const char *  pattern)

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

4778 {
4780  PGresult *res;
4781  int i;
4782 
4783  if (pset.sversion < 90100)
4784  {
4785  char sverbuf[32];
4786 
4787  psql_error("The server (version %s) does not support extensions.\n",
4789  sverbuf, sizeof(sverbuf)));
4790  return true;
4791  }
4792 
4793  initPQExpBuffer(&buf);
4794  printfPQExpBuffer(&buf,
4795  "SELECT e.extname, e.oid\n"
4796  "FROM pg_catalog.pg_extension e\n");
4797 
4798  processSQLNamePattern(pset.db, &buf, pattern,
4799  false, false,
4800  NULL, "e.extname", NULL,
4801  NULL);
4802 
4803  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4804 
4805  res = PSQLexec(buf.data);
4806  termPQExpBuffer(&buf);
4807  if (!res)
4808  return false;
4809 
4810  if (PQntuples(res) == 0)
4811  {
4812  if (!pset.quiet)
4813  {
4814  if (pattern)
4815  psql_error("Did not find any extension named \"%s\".\n",
4816  pattern);
4817  else
4818  psql_error("Did not find any extensions.\n");
4819  }
4820  PQclear(res);
4821  return false;
4822  }
4823 
4824  for (i = 0; i < PQntuples(res); i++)
4825  {
4826  const char *extname;
4827  const char *oid;
4828 
4829  extname = PQgetvalue(res, i, 0);
4830  oid = PQgetvalue(res, i, 1);
4831 
4832  if (!listOneExtensionContents(extname, oid))
4833  {
4834  PQclear(res);
4835  return false;
4836  }
4837  if (cancel_pressed)
4838  {
4839  PQclear(res);
4840  return false;
4841  }
4842  }
4843 
4844  PQclear(res);
4845  return true;
4846 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:37
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:817
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
volatile bool cancel_pressed
Definition: print.c:47
static char * buf
Definition: pg_test_fsync.c:65
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:4849
void psql_error(const char *fmt,...)
Definition: common.c:177
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:226
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:599
bool listExtensions ( const char *  pattern)

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

4721 {
4723  PGresult *res;
4724  printQueryOpt myopt = pset.popt;
4725 
4726  if (pset.sversion < 90100)
4727  {
4728  char sverbuf[32];
4729 
4730  psql_error("The server (version %s) does not support extensions.\n",
4732  sverbuf, sizeof(sverbuf)));
4733  return true;
4734  }
4735 
4736  initPQExpBuffer(&buf);
4737  printfPQExpBuffer(&buf,
4738  "SELECT e.extname AS \"%s\", "
4739  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4740  "FROM pg_catalog.pg_extension e "
4741  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4742  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4743  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4744  gettext_noop("Name"),
4745  gettext_noop("Version"),
4746  gettext_noop("Schema"),
4747  gettext_noop("Description"));
4748 
4749  processSQLNamePattern(pset.db, &buf, pattern,
4750  false, false,
4751  NULL, "e.extname", NULL,
4752  NULL);
4753 
4754  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4755 
4756  res = PSQLexec(buf.data);
4757  termPQExpBuffer(&buf);
4758  if (!res)
4759  return false;
4760 
4761  myopt.nullPrint = NULL;
4762  myopt.title = _("List of installed extensions");
4763  myopt.translate_header = true;
4764 
4765  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4766 
4767  PQclear(res);
4768  return true;
4769 }
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:37
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:817
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
#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:599
bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

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

4417 {
4419  PGresult *res;
4420  printQueryOpt myopt = pset.popt;
4421 
4422  if (pset.sversion < 80400)
4423  {
4424  char sverbuf[32];
4425 
4426  psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4428  sverbuf, sizeof(sverbuf)));
4429  return true;
4430  }
4431 
4432  initPQExpBuffer(&buf);
4433  printfPQExpBuffer(&buf,
4434  "SELECT fdw.fdwname AS \"%s\",\n"
4435  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4436  gettext_noop("Name"),
4437  gettext_noop("Owner"));
4438  if (pset.sversion >= 90100)
4439  appendPQExpBuffer(&buf,
4440  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4441  gettext_noop("Handler"));
4442  appendPQExpBuffer(&buf,
4443  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4444  gettext_noop("Validator"));
4445 
4446  if (verbose)
4447  {
4448  appendPQExpBufferStr(&buf, ",\n ");
4449  printACLColumn(&buf, "fdwacl");
4450  appendPQExpBuffer(&buf,
4451  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4452  " '(' || array_to_string(ARRAY(SELECT "
4453  " quote_ident(option_name) || ' ' || "
4454  " quote_literal(option_value) FROM "
4455  " pg_options_to_table(fdwoptions)), ', ') || ')' "
4456  " END AS \"%s\"",
4457  gettext_noop("FDW Options"));
4458 
4459  if (pset.sversion >= 90100)
4460  appendPQExpBuffer(&buf,
4461  ",\n d.description AS \"%s\" ",
4462  gettext_noop("Description"));
4463  }
4464 
4465  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4466 
4467  if (verbose && pset.sversion >= 90100)
4468  appendPQExpBufferStr(&buf,
4469  "LEFT JOIN pg_catalog.pg_description d\n"
4470  " ON d.classoid = fdw.tableoid "
4471  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4472 
4473  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4474  NULL, "fdwname", NULL, NULL);
4475 
4476  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4477 
4478  res = PSQLexec(buf.data);
4479  termPQExpBuffer(&buf);
4480  if (!res)
4481  return false;
4482 
4483  myopt.nullPrint = NULL;
4484  myopt.title = _("List of foreign-data wrappers");
4485  myopt.translate_header = true;
4486 
4487  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4488 
4489  PQclear(res);
4490  return true;
4491 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5149
#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:599
bool listForeignServers ( const char *  pattern,
bool  verbose 
)

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

4500 {
4502  PGresult *res;
4503  printQueryOpt myopt = pset.popt;
4504 
4505  if (pset.sversion < 80400)
4506  {
4507  char sverbuf[32];
4508 
4509  psql_error("The server (version %s) does not support foreign servers.\n",
4511  sverbuf, sizeof(sverbuf)));
4512  return true;
4513  }
4514 
4515  initPQExpBuffer(&buf);
4516  printfPQExpBuffer(&buf,
4517  "SELECT s.srvname AS \"%s\",\n"
4518  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4519  " f.fdwname AS \"%s\"",
4520  gettext_noop("Name"),
4521  gettext_noop("Owner"),
4522  gettext_noop("Foreign-data wrapper"));
4523 
4524  if (verbose)
4525  {
4526  appendPQExpBufferStr(&buf, ",\n ");
4527  printACLColumn(&buf, "s.srvacl");
4528  appendPQExpBuffer(&buf,
4529  ",\n"
4530  " s.srvtype AS \"%s\",\n"
4531  " s.srvversion AS \"%s\",\n"
4532  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4533  " '(' || array_to_string(ARRAY(SELECT "
4534  " quote_ident(option_name) || ' ' || "
4535  " quote_literal(option_value) FROM "
4536  " pg_options_to_table(srvoptions)), ', ') || ')' "
4537  " END AS \"%s\",\n"
4538  " d.description AS \"%s\"",
4539  gettext_noop("Type"),
4540  gettext_noop("Version"),
4541  gettext_noop("FDW Options"),
4542  gettext_noop("Description"));
4543  }
4544 
4545  appendPQExpBufferStr(&buf,
4546  "\nFROM pg_catalog.pg_foreign_server s\n"
4547  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4548 
4549  if (verbose)
4550  appendPQExpBufferStr(&buf,
4551  "LEFT JOIN pg_description d\n "
4552  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4553  "AND d.objsubid = 0\n");
4554 
4555  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4556  NULL, "s.srvname", NULL, NULL);
4557 
4558  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4559 
4560  res = PSQLexec(buf.data);
4561  termPQExpBuffer(&buf);
4562  if (!res)
4563  return false;
4564 
4565  myopt.nullPrint = NULL;
4566  myopt.title = _("List of foreign servers");
4567  myopt.translate_header = true;
4568 
4569  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4570 
4571  PQclear(res);
4572  return true;
4573 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5149
#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:599
bool listForeignTables ( const char *  pattern,
bool  verbose 
)

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

4643 {
4645  PGresult *res;
4646  printQueryOpt myopt = pset.popt;
4647 
4648  if (pset.sversion < 90100)
4649  {
4650  char sverbuf[32];
4651 
4652  psql_error("The server (version %s) does not support foreign tables.\n",
4654  sverbuf, sizeof(sverbuf)));
4655  return true;
4656  }
4657 
4658  initPQExpBuffer(&buf);
4659  printfPQExpBuffer(&buf,
4660  "SELECT n.nspname AS \"%s\",\n"
4661  " c.relname AS \"%s\",\n"
4662  " s.srvname AS \"%s\"",
4663  gettext_noop("Schema"),
4664  gettext_noop("Table"),
4665  gettext_noop("Server"));
4666 
4667  if (verbose)
4668  appendPQExpBuffer(&buf,
4669  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4670  " '(' || array_to_string(ARRAY(SELECT "
4671  " quote_ident(option_name) || ' ' || "
4672  " quote_literal(option_value) FROM "
4673  " pg_options_to_table(ftoptions)), ', ') || ')' "
4674  " END AS \"%s\",\n"
4675  " d.description AS \"%s\"",
4676  gettext_noop("FDW Options"),
4677  gettext_noop("Description"));
4678 
4679  appendPQExpBufferStr(&buf,
4680  "\nFROM pg_catalog.pg_foreign_table ft\n"
4681  " INNER JOIN pg_catalog.pg_class c"
4682  " ON c.oid = ft.ftrelid\n"
4683  " INNER JOIN pg_catalog.pg_namespace n"
4684  " ON n.oid = c.relnamespace\n"
4685  " INNER JOIN pg_catalog.pg_foreign_server s"
4686  " ON s.oid = ft.ftserver\n");
4687  if (verbose)
4688  appendPQExpBufferStr(&buf,
4689  " LEFT JOIN pg_catalog.pg_description d\n"
4690  " ON d.classoid = c.tableoid AND "
4691  "d.objoid = c.oid AND d.objsubid = 0\n");
4692 
4693  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4694  "n.nspname", "c.relname", NULL,
4695  "pg_catalog.pg_table_is_visible(c.oid)");
4696 
4697  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4698 
4699  res = PSQLexec(buf.data);
4700  termPQExpBuffer(&buf);
4701  if (!res)
4702  return false;
4703 
4704  myopt.nullPrint = NULL;
4705  myopt.title = _("List of foreign tables");
4706  myopt.translate_header = true;
4707 
4708  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4709 
4710  PQclear(res);
4711  return true;
4712 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
#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:599
bool listLanguages ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3298 {
3300  PGresult *res;
3301  printQueryOpt myopt = pset.popt;
3302 
3303  initPQExpBuffer(&buf);
3304 
3305  printfPQExpBuffer(&buf,
3306  "SELECT l.lanname AS \"%s\",\n",
3307  gettext_noop("Name"));
3308  if (pset.sversion >= 80300)
3309  appendPQExpBuffer(&buf,
3310  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
3311  gettext_noop("Owner"));
3312 
3313  appendPQExpBuffer(&buf,
3314  " l.lanpltrusted AS \"%s\"",
3315  gettext_noop("Trusted"));
3316 
3317  if (verbose)
3318  {
3319  appendPQExpBuffer(&buf,
3320  ",\n NOT l.lanispl AS \"%s\",\n"
3321  " l.lanplcallfoid::regprocedure AS \"%s\",\n"
3322  " l.lanvalidator::regprocedure AS \"%s\",\n ",
3323  gettext_noop("Internal Language"),
3324  gettext_noop("Call Handler"),
3325  gettext_noop("Validator"));
3326  if (pset.sversion >= 90000)
3327  appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n ",
3328  gettext_noop("Inline Handler"));
3329  printACLColumn(&buf, "l.lanacl");
3330  }
3331 
3332  appendPQExpBuffer(&buf,
3333  ",\n d.description AS \"%s\""
3334  "\nFROM pg_catalog.pg_language l\n"
3335  "LEFT JOIN pg_catalog.pg_description d\n"
3336  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
3337  " AND d.objsubid = 0\n",
3338  gettext_noop("Description"));
3339 
3340  if (pattern)
3341  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3342  NULL, "l.lanname", NULL, NULL);
3343 
3344  if (!showSystem && !pattern)
3345  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
3346 
3347 
3348  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3349 
3350  res = PSQLexec(buf.data);
3351  termPQExpBuffer(&buf);
3352  if (!res)
3353  return false;
3354 
3355  myopt.nullPrint = NULL;
3356  myopt.title = _("List of languages");
3357  myopt.translate_header = true;
3358 
3359  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3360 
3361  PQclear(res);
3362  return true;
3363 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5149
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:599
bool listPublications ( const char *  pattern)

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

4888 {
4890  PGresult *res;
4891  printQueryOpt myopt = pset.popt;
4892  static const bool translate_columns[] = {false, false, false, false, false};
4893 
4894  if (pset.sversion < 100000)
4895  {
4896  char sverbuf[32];
4897  psql_error("The server (version %s) does not support publications.\n",
4899  sverbuf, sizeof(sverbuf)));
4900  return true;
4901  }
4902 
4903  initPQExpBuffer(&buf);
4904 
4905  printfPQExpBuffer(&buf,
4906  "SELECT pubname AS \"%s\",\n"
4907  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
4908  " pubinsert AS \"%s\",\n"
4909  " pubupdate AS \"%s\",\n"
4910  " pubdelete AS \"%s\"\n",
4911  gettext_noop("Name"),
4912  gettext_noop("Owner"),
4913  gettext_noop("Inserts"),
4914  gettext_noop("Updates"),
4915  gettext_noop("Deletes"));
4916 
4917  appendPQExpBufferStr(&buf,
4918  "\nFROM pg_catalog.pg_publication\n");
4919 
4920  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4921  NULL, "pubname", NULL,
4922  NULL);
4923 
4924  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4925 
4926  res = PSQLexec(buf.data);
4927  termPQExpBuffer(&buf);
4928  if (!res)
4929  return false;
4930 
4931  myopt.nullPrint = NULL;
4932  myopt.title = _("List of publications");
4933  myopt.translate_header = true;
4934  myopt.translate_columns = translate_columns;
4935  myopt.n_translate_columns = lengthof(translate_columns);
4936 
4937  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4938 
4939  PQclear(res);
4940 
4941  return true;
4942 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
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:3286
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:599
bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3779 {
3781  PGresult *res;
3782  printQueryOpt myopt = pset.popt;
3783 
3784  initPQExpBuffer(&buf);
3785  printfPQExpBuffer(&buf,
3786  "SELECT n.nspname AS \"%s\",\n"
3787  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
3788  gettext_noop("Name"),
3789  gettext_noop("Owner"));
3790 
3791  if (verbose)
3792  {
3793  appendPQExpBufferStr(&buf, ",\n ");
3794  printACLColumn(&buf, "n.nspacl");
3795  appendPQExpBuffer(&buf,
3796  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
3797  gettext_noop("Description"));
3798  }
3799 
3800  appendPQExpBuffer(&buf,
3801  "\nFROM pg_catalog.pg_namespace n\n");
3802 
3803  if (!showSystem && !pattern)
3804  appendPQExpBufferStr(&buf,
3805  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
3806 
3807  processSQLNamePattern(pset.db, &buf, pattern,
3808  !showSystem && !pattern, false,
3809  NULL, "n.nspname", NULL,
3810  NULL);
3811 
3812  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3813 
3814  res = PSQLexec(buf.data);
3815  termPQExpBuffer(&buf);
3816  if (!res)
3817  return false;
3818 
3819  myopt.nullPrint = NULL;
3820  myopt.title = _("List of schemas");
3821  myopt.translate_header = true;
3822 
3823  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3824 
3825  PQclear(res);
3826  return true;
3827 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5149
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:599
bool listTables ( const char *  tabtypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3142 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(), PQntuples(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::quiet, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command().

3143 {
3144  bool showTables = strchr(tabtypes, 't') != NULL;
3145  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3146  bool showViews = strchr(tabtypes, 'v') != NULL;
3147  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3148  bool showSeq = strchr(tabtypes, 's') != NULL;
3149  bool showForeign = strchr(tabtypes, 'E') != NULL;
3150 
3152  PGresult *res;
3153  printQueryOpt myopt = pset.popt;
3154  static const bool translate_columns[] = {false, false, true, false, false, false, false};
3155 
3156  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3157  showTables = showViews = showMatViews = showSeq = showForeign = true;
3158 
3159  initPQExpBuffer(&buf);
3160 
3161  /*
3162  * Note: as of Pg 8.2, we no longer use relkind 's', but we keep it here
3163  * for backwards compatibility.
3164  */
3165  printfPQExpBuffer(&buf,
3166  "SELECT n.nspname as \"%s\",\n"
3167  " c.relname as \"%s\",\n"
3168  " CASE c.relkind"
3169  " WHEN 'r' THEN '%s'"
3170  " WHEN 'v' THEN '%s'"
3171  " WHEN 'm' THEN '%s'"
3172  " WHEN 'i' THEN '%s'"
3173  " WHEN 'S' THEN '%s'"
3174  " WHEN 's' THEN '%s'"
3175  " WHEN 'f' THEN '%s'"
3176  " WHEN 'P' THEN '%s'"
3177  " END as \"%s\",\n"
3178  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3179  gettext_noop("Schema"),
3180  gettext_noop("Name"),
3181  gettext_noop("table"),
3182  gettext_noop("view"),
3183  gettext_noop("materialized view"),
3184  gettext_noop("index"),
3185  gettext_noop("sequence"),
3186  gettext_noop("special"),
3187  gettext_noop("foreign table"),
3188  gettext_noop("table"), /* partitioned table */
3189  gettext_noop("Type"),
3190  gettext_noop("Owner"));
3191 
3192  if (showIndexes)
3193  appendPQExpBuffer(&buf,
3194  ",\n c2.relname as \"%s\"",
3195  gettext_noop("Table"));
3196 
3197  if (verbose)
3198  {
3199  /*
3200  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3201  * size of a table, including FSM, VM and TOAST tables.
3202  */
3203  if (pset.sversion >= 90000)
3204  appendPQExpBuffer(&buf,
3205  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3206  gettext_noop("Size"));
3207  else if (pset.sversion >= 80100)
3208  appendPQExpBuffer(&buf,
3209  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3210  gettext_noop("Size"));
3211 
3212  appendPQExpBuffer(&buf,
3213  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3214  gettext_noop("Description"));
3215  }
3216 
3217  appendPQExpBufferStr(&buf,
3218  "\nFROM pg_catalog.pg_class c"
3219  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3220  if (showIndexes)
3221  appendPQExpBufferStr(&buf,
3222  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3223  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3224 
3225  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3226  if (showTables)
3227  appendPQExpBufferStr(&buf, "'r', 'P',");
3228  if (showViews)
3229  appendPQExpBufferStr(&buf, "'v',");
3230  if (showMatViews)
3231  appendPQExpBufferStr(&buf, "'m',");
3232  if (showIndexes)
3233  appendPQExpBufferStr(&buf, "'i',");
3234  if (showSeq)
3235  appendPQExpBufferStr(&buf, "'S',");
3236  if (showSystem || pattern)
3237  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL in <=
3238  * 8.1 */
3239  if (showForeign)
3240  appendPQExpBufferStr(&buf, "'f',");
3241 
3242  appendPQExpBufferStr(&buf, "''"); /* dummy */
3243  appendPQExpBufferStr(&buf, ")\n");
3244 
3245  if (!showSystem && !pattern)
3246  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3247  " AND n.nspname <> 'information_schema'\n");
3248 
3249  /*
3250  * TOAST objects are suppressed unconditionally. Since we don't provide
3251  * any way to select relkind 't' above, we would never show toast tables
3252  * in any case; it seems a bit confusing to allow their indexes to be
3253  * shown. Use plain \d if you really need to look at a TOAST table/index.
3254  */
3255  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3256 
3257  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3258  "n.nspname", "c.relname", NULL,
3259  "pg_catalog.pg_table_is_visible(c.oid)");
3260 
3261  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3262 
3263  res = PSQLexec(buf.data);
3264  termPQExpBuffer(&buf);
3265  if (!res)
3266  return false;
3267 
3268  if (PQntuples(res) == 0 && !pset.quiet)
3269  {
3270  if (pattern)
3271  fprintf(pset.queryFout, _("No matching relations found.\n"));
3272  else
3273  fprintf(pset.queryFout, _("No relations found.\n"));
3274  }
3275  else
3276  {
3277  myopt.nullPrint = NULL;
3278  myopt.title = _("List of relations");
3279  myopt.translate_header = true;
3280  myopt.translate_columns = translate_columns;
3281  myopt.n_translate_columns = lengthof(translate_columns);
3282 
3283  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3284  }
3285 
3286  PQclear(res);
3287  return true;
3288 }
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:37
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:817
#define lengthof(array)
Definition: c.h:558
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:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
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:3286
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:599
bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

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

4216 {
4218  PGresult *res;
4219  printQueryOpt myopt = pset.popt;
4220 
4221  if (pset.sversion < 80300)
4222  {
4223  char sverbuf[32];
4224 
4225  psql_error("The server (version %s) does not support full text search.\n",
4227  sverbuf, sizeof(sverbuf)));
4228  return true;
4229  }
4230 
4231  if (verbose)
4232  return listTSConfigsVerbose(pattern);
4233 
4234  initPQExpBuffer(&buf);
4235 
4236  printfPQExpBuffer(&buf,
4237  "SELECT \n"
4238  " n.nspname as \"%s\",\n"
4239  " c.cfgname as \"%s\",\n"
4240  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4241  "FROM pg_catalog.pg_ts_config c\n"
4242  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace \n",
4243  gettext_noop("Schema"),
4244  gettext_noop("Name"),
4245  gettext_noop("Description")
4246  );
4247 
4248  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4249  "n.nspname", "c.cfgname", NULL,
4250  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4251 
4252  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4253 
4254  res = PSQLexec(buf.data);
4255  termPQExpBuffer(&buf);
4256  if (!res)
4257  return false;
4258 
4259  myopt.nullPrint = NULL;
4260  myopt.title = _("List of text search configurations");
4261  myopt.translate_header = true;
4262 
4263  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4264 
4265  PQclear(res);
4266  return true;
4267 }
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:37
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:817
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:4270
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
#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:599
bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

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

4074 {
4076  PGresult *res;
4077  printQueryOpt myopt = pset.popt;
4078 
4079  if (pset.sversion < 80300)
4080  {
4081  char sverbuf[32];
4082 
4083  psql_error("The server (version %s) does not support full text search.\n",
4085  sverbuf, sizeof(sverbuf)));
4086  return true;
4087  }
4088 
4089  initPQExpBuffer(&buf);
4090 
4091  printfPQExpBuffer(&buf,
4092  "SELECT \n"
4093  " n.nspname as \"%s\",\n"
4094  " d.dictname as \"%s\",\n",
4095  gettext_noop("Schema"),
4096  gettext_noop("Name"));
4097 
4098  if (verbose)
4099  {
4100  appendPQExpBuffer(&buf,
4101  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM \n"
4102  " pg_catalog.pg_ts_template t \n"
4103  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace \n"
4104  " WHERE d.dicttemplate = t.oid ) AS \"%s\", \n"
4105  " d.dictinitoption as \"%s\", \n",
4106  gettext_noop("Template"),
4107  gettext_noop("Init options"));
4108  }
4109 
4110  appendPQExpBuffer(&buf,
4111  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
4112  gettext_noop("Description"));
4113 
4114  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
4115  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
4116 
4117  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4118  "n.nspname", "d.dictname", NULL,
4119  "pg_catalog.pg_ts_dict_is_visible(d.oid)");
4120 
4121  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4122 
4123  res = PSQLexec(buf.data);
4124  termPQExpBuffer(&buf);
4125  if (!res)
4126  return false;
4127 
4128  myopt.nullPrint = NULL;
4129  myopt.title = _("List of text search dictionaries");
4130  myopt.translate_header = true;
4131 
4132  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4133 
4134  PQclear(res);
4135  return true;
4136 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
#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:599
bool listTSParsers ( const char *  pattern,
bool  verbose 
)

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

3836 {
3838  PGresult *res;
3839  printQueryOpt myopt = pset.popt;
3840 
3841  if (pset.sversion < 80300)
3842  {
3843  char sverbuf[32];
3844 
3845  psql_error("The server (version %s) does not support full text search.\n",
3847  sverbuf, sizeof(sverbuf)));
3848  return true;
3849  }
3850 
3851  if (verbose)
3852  return listTSParsersVerbose(pattern);
3853 
3854  initPQExpBuffer(&buf);
3855 
3856  printfPQExpBuffer(&buf,
3857  "SELECT \n"
3858  " n.nspname as \"%s\",\n"
3859  " p.prsname as \"%s\",\n"
3860  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
3861  "FROM pg_catalog.pg_ts_parser p \n"
3862  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
3863  gettext_noop("Schema"),
3864  gettext_noop("Name"),
3865  gettext_noop("Description")
3866  );
3867 
3868  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3869  "n.nspname", "p.prsname", NULL,
3870  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
3871 
3872  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3873 
3874  res = PSQLexec(buf.data);
3875  termPQExpBuffer(&buf);
3876  if (!res)
3877  return false;
3878 
3879  myopt.nullPrint = NULL;
3880  myopt.title = _("List of text search parsers");
3881  myopt.translate_header = true;
3882 
3883  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3884 
3885  PQclear(res);
3886  return true;
3887 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:3893
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:37
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:817
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
#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:599
bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

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

4145 {
4147  PGresult *res;
4148  printQueryOpt myopt = pset.popt;
4149 
4150  if (pset.sversion < 80300)
4151  {
4152  char sverbuf[32];
4153 
4154  psql_error("The server (version %s) does not support full text search.\n",
4156  sverbuf, sizeof(sverbuf)));
4157  return true;
4158  }
4159 
4160  initPQExpBuffer(&buf);
4161 
4162  if (verbose)
4163  printfPQExpBuffer(&buf,
4164  "SELECT \n"
4165  " n.nspname AS \"%s\",\n"
4166  " t.tmplname AS \"%s\",\n"
4167  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4168  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4169  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4170  gettext_noop("Schema"),
4171  gettext_noop("Name"),
4172  gettext_noop("Init"),
4173  gettext_noop("Lexize"),
4174  gettext_noop("Description"));
4175  else
4176  printfPQExpBuffer(&buf,
4177  "SELECT \n"
4178  " n.nspname AS \"%s\",\n"
4179  " t.tmplname AS \"%s\",\n"
4180  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4181  gettext_noop("Schema"),
4182  gettext_noop("Name"),
4183  gettext_noop("Description"));
4184 
4185  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4186  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4187 
4188  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4189  "n.nspname", "t.tmplname", NULL,
4190  "pg_catalog.pg_ts_template_is_visible(t.oid)");
4191 
4192  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4193 
4194  res = PSQLexec(buf.data);
4195  termPQExpBuffer(&buf);
4196  if (!res)
4197  return false;
4198 
4199  myopt.nullPrint = NULL;
4200  myopt.title = _("List of text search templates");
4201  myopt.translate_header = true;
4202 
4203  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4204 
4205  PQclear(res);
4206  return true;
4207 }
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:37
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:817
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
#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:599
bool listUserMappings ( const char *  pattern,
bool  verbose 
)

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

4582 {
4584  PGresult *res;
4585  printQueryOpt myopt = pset.popt;
4586 
4587  if (pset.sversion < 80400)
4588  {
4589  char sverbuf[32];
4590 
4591  psql_error("The server (version %s) does not support user mappings.\n",
4593  sverbuf, sizeof(sverbuf)));
4594  return true;
4595  }
4596 
4597  initPQExpBuffer(&buf);
4598  printfPQExpBuffer(&buf,
4599  "SELECT um.srvname AS \"%s\",\n"
4600  " um.usename AS \"%s\"",
4601  gettext_noop("Server"),
4602  gettext_noop("User name"));
4603 
4604  if (verbose)
4605  appendPQExpBuffer(&buf,
4606  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4607  " '(' || array_to_string(ARRAY(SELECT "
4608  " quote_ident(option_name) || ' ' || "
4609  " quote_literal(option_value) FROM "
4610  " pg_options_to_table(umoptions)), ', ') || ')' "
4611  " END AS \"%s\"",
4612  gettext_noop("FDW Options"));
4613 
4614  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4615 
4616  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4617  NULL, "um.srvname", "um.usename", NULL);
4618 
4619  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4620 
4621  res = PSQLexec(buf.data);
4622  termPQExpBuffer(&buf);
4623  if (!res)
4624  return false;
4625 
4626  myopt.nullPrint = NULL;
4627  myopt.title = _("List of user mappings");
4628  myopt.translate_header = true;
4629 
4630  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4631 
4632  PQclear(res);
4633  return true;
4634 }
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:37
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:87
void psql_error(const char *fmt,...)
Definition: common.c:177
FILE * logfile
Definition: settings.h:113
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:226
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3286
#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:599
bool objectDescription ( const char *  pattern,
bool  showSystem 
)

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

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

Definition at line 847 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(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, and printQueryOpt::translate_header.

Referenced by exec_command().

848 {
850  PGresult *res;
851  printQueryOpt myopt = pset.popt;
852  static const bool translate_columns[] = {false, false, true, false, false, false};
853 
854  initPQExpBuffer(&buf);
855 
856  /*
857  * we ignore indexes and toast tables since they have no meaningful rights
858  */
859  printfPQExpBuffer(&buf,
860  "SELECT n.nspname as \"%s\",\n"
861  " c.relname as \"%s\",\n"
862  " CASE c.relkind"
863  " WHEN 'r' THEN '%s'"
864  " WHEN 'v' THEN '%s'"
865  " WHEN 'm' THEN '%s'"
866  " WHEN 'S' THEN '%s'"
867  " WHEN 'f' THEN '%s'"
868  " WHEN 'P' THEN '%s'"
869  " END as \"%s\",\n"
870  " ",
871  gettext_noop("Schema"),
872  gettext_noop("Name"),
873  gettext_noop("table"),
874  gettext_noop("view"),
875  gettext_noop("materialized view"),
876  gettext_noop("sequence"),
877  gettext_noop("foreign table"),
878  gettext_noop("table"), /* partitioned table */
879  gettext_noop("Type"));
880 
881  printACLColumn(&buf, "c.relacl");
882 
883  if (pset.sversion >= 80400)
884  appendPQExpBuffer(&buf,
885  ",\n pg_catalog.array_to_string(ARRAY(\n"
886  " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
887  " FROM pg_catalog.pg_attribute a\n"
888  " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
889  " ), E'\\n') AS \"%s\"",
890  gettext_noop("Column privileges"));
891 
892  if (pset.sversion >= 90500 && pset.sversion < 100000)
893  appendPQExpBuffer(&buf,
894  ",\n pg_catalog.array_to_string(ARRAY(\n"
895  " SELECT polname\n"
896  " || CASE WHEN polcmd != '*' THEN\n"
897  " E' (' || polcmd || E'):'\n"
898  " ELSE E':' \n"
899  " END\n"
900  " || CASE WHEN polqual IS NOT NULL THEN\n"
901  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
902  " ELSE E''\n"
903  " END\n"
904  " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
905  " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
906  " ELSE E''\n"
907  " END"
908  " || CASE WHEN polroles <> '{0}' THEN\n"
909  " E'\\n to: ' || pg_catalog.array_to_string(\n"
910  " ARRAY(\n"
911  " SELECT rolname\n"
912  " FROM pg_catalog.pg_roles\n"
913  " WHERE oid = ANY (polroles)\n"
914  " ORDER BY 1\n"
915  " ), E', ')\n"
916  " ELSE E''\n"
917  " END\n"
918  " FROM pg_catalog.pg_policy pol\n"
919  " WHERE polrelid = c.oid), E'\\n')\n"
920  " AS \"%s\"",
921  gettext_noop("Policies"));
922 
923  if (pset.sversion >= 100000)
924  appendPQExpBuffer(&buf,
925  ",\n pg_catalog.array_to_string(ARRAY(\n"
926  " SELECT polname\n"
927  " || CASE WHEN NOT polpermissive THEN\n"
928  " E' (RESTRICTIVE)'\n"
929  " ELSE '' END\n"
930  " || CASE WHEN polcmd != '*' THEN\n"
931  " E' (' || polcmd || E'):'\n"
932  " ELSE E':' \n"
933  " END\n"
934  " || CASE WHEN polqual IS NOT NULL THEN\n"
935  " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
936  " ELSE E''\n"
937  " END\n"
938  " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
939  " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
940  " ELSE E''\n"
941  " END"
942  " || CASE WHEN polroles <> '{0}' THEN\n"
943  " E'\\n to: ' || pg_catalog.array_to_string(\n"
944  " ARRAY(\n"
945  " SELECT rolname\n"
946  " FROM pg_catalog.pg_roles\n"
947  " WHERE oid = ANY (polroles)\n"
948  " ORDER BY 1\n"
949  " ), E', ')\n"
950  " ELSE E''\n"
951  " END\n"
952  " FROM pg_catalog.pg_policy pol\n"
953  " WHERE polrelid = c.oid), E'\\n')\n"
954  " AS \"%s\"",
955  gettext_noop("Policies"));
956 
957  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
958  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
959  "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f', 'P')\n");
960 
961  /*
962  * Unless a schema pattern is specified, we suppress system and temp
963  * tables, since they normally aren't very interesting from a permissions
964  * point of view. You can see 'em by explicit request though, eg with \z
965  * pg_catalog.*
966  */
967  processSQLNamePattern(pset.db, &buf, pattern, true, false,
968  "n.nspname", "c.relname", NULL,
969