PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
describe.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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

Function Documentation

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 138 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 61 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 299 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 703 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 5110 of file describe.c.

References _, appendPQExpBufferStr(), buf, CppAsString2, 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, RELKIND_RELATION, _psqlSettings::sversion, termPQExpBuffer(), and printQueryOpt::topt.

Referenced by exec_command_d().

5111 {
5113  int i;
5114  PGresult *res;
5115 
5116  if (pset.sversion < 100000)
5117  {
5118  char sverbuf[32];
5119 
5120  psql_error("The server (version %s) does not support publications.\n",
5122  sverbuf, sizeof(sverbuf)));
5123  return true;
5124  }
5125 
5126  initPQExpBuffer(&buf);
5127 
5128  printfPQExpBuffer(&buf,
5129  "SELECT oid, pubname, puballtables, pubinsert,\n"
5130  " pubupdate, pubdelete\n"
5131  "FROM pg_catalog.pg_publication\n");
5132 
5133  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5134  NULL, "pubname", NULL,
5135  NULL);
5136 
5137  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5138 
5139  res = PSQLexec(buf.data);
5140  if (!res)
5141  {
5142  termPQExpBuffer(&buf);
5143  return false;
5144  }
5145 
5146  for (i = 0; i < PQntuples(res); i++)
5147  {
5148  const char align = 'l';
5149  int ncols = 3;
5150  int nrows = 1;
5151  int tables = 0;
5152  PGresult *tabres;
5153  char *pubid = PQgetvalue(res, i, 0);
5154  char *pubname = PQgetvalue(res, i, 1);
5155  bool puballtables = strcmp(PQgetvalue(res, i, 2), "t") == 0;
5156  int j;
5157  PQExpBufferData title;
5158  printTableOpt myopt = pset.popt.topt;
5159  printTableContent cont;
5160 
5161  initPQExpBuffer(&title);
5162  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5163  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5164 
5165  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5166  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5167  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5168 
5169  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5170  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5171  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5172 
5173  if (puballtables)
5174  printfPQExpBuffer(&buf,
5175  "SELECT n.nspname, c.relname\n"
5176  "FROM pg_catalog.pg_class c,\n"
5177  " pg_catalog.pg_namespace n\n"
5178  "WHERE c.relnamespace = n.oid\n"
5179  " AND c.relkind = " CppAsString2(RELKIND_RELATION) "\n"
5180  " AND n.nspname <> 'pg_catalog'\n"
5181  " AND n.nspname <> 'information_schema'\n"
5182  "ORDER BY 1,2");
5183  else
5184  printfPQExpBuffer(&buf,
5185  "SELECT n.nspname, c.relname\n"
5186  "FROM pg_catalog.pg_class c,\n"
5187  " pg_catalog.pg_namespace n,\n"
5188  " pg_catalog.pg_publication_rel pr\n"
5189  "WHERE c.relnamespace = n.oid\n"
5190  " AND c.oid = pr.prrelid\n"
5191  " AND pr.prpubid = '%s'\n"
5192  "ORDER BY 1,2", pubid);
5193 
5194  tabres = PSQLexec(buf.data);
5195  if (!tabres)
5196  {
5197  printTableCleanup(&cont);
5198  PQclear(res);
5199  termPQExpBuffer(&buf);
5200  termPQExpBuffer(&title);
5201  return false;
5202  }
5203  else
5204  tables = PQntuples(tabres);
5205 
5206  if (tables > 0)
5207  printTableAddFooter(&cont, _("Tables:"));
5208 
5209  for (j = 0; j < tables; j++)
5210  {
5211  printfPQExpBuffer(&buf, " \"%s.%s\"",
5212  PQgetvalue(tabres, j, 0),
5213  PQgetvalue(tabres, j, 1));
5214 
5215  printTableAddFooter(&cont, buf.data);
5216  }
5217  PQclear(tabres);
5218 
5219  printTable(&cont, pset.queryFout, false, pset.logfile);
5220  printTableCleanup(&cont);
5221 
5222  termPQExpBuffer(&title);
5223  }
5224 
5225  termPQExpBuffer(&buf);
5226  PQclear(res);
5227 
5228  return true;
5229 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
void printTableCleanup(printTableContent *const content)
Definition: print.c:3099
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
printTableOpt topt
Definition: print.h:165
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2968
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3008
static char * buf
Definition: pg_test_fsync.c:66
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3188
#define CppAsString2(x)
Definition: c.h:162
void psql_error(const char *fmt,...)
Definition: common.c:220
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3056
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2931
int i
#define RELKIND_RELATION
Definition: pg_class.h:160
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3049 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 5237 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 1287 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 205 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 588 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 780 of file describe.c.

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

Referenced by exec_command_list(), and main().

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

Definition at line 3754 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3853 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3612 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3220 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 1010 of file describe.c.

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

Referenced by exec_command_d().

1011 {
1013  PGresult *res;
1014  printQueryOpt myopt = pset.popt;
1015  static const bool translate_columns[] = {false, false, true, false};
1016 
1017  if (pset.sversion < 90000)
1018  {
1019  char sverbuf[32];
1020 
1021  psql_error("The server (version %s) does not support altering default privileges.\n",
1023  sverbuf, sizeof(sverbuf)));
1024  return true;
1025  }
1026 
1027  initPQExpBuffer(&buf);
1028 
1029  printfPQExpBuffer(&buf,
1030  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1031  " n.nspname AS \"%s\",\n"
1032  " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1033  " ",
1034  gettext_noop("Owner"),
1035  gettext_noop("Schema"),
1037  gettext_noop("table"),
1039  gettext_noop("sequence"),
1041  gettext_noop("function"),
1043  gettext_noop("type"),
1045  gettext_noop("schema"),
1046  gettext_noop("Type"));
1047 
1048  printACLColumn(&buf, "d.defaclacl");
1049 
1050  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1051  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1052 
1053  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1054  NULL,
1055  "n.nspname",
1056  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1057  NULL);
1058 
1059  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1060 
1061  res = PSQLexec(buf.data);
1062  if (!res)
1063  {
1064  termPQExpBuffer(&buf);
1065  return false;
1066  }
1067 
1068  myopt.nullPrint = NULL;
1069  printfPQExpBuffer(&buf, _("Default access privileges"));
1070  myopt.title = buf.data;
1071  myopt.translate_header = true;
1072  myopt.translate_columns = translate_columns;
1073  myopt.n_translate_columns = lengthof(translate_columns);
1074 
1075  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1076 
1077  termPQExpBuffer(&buf);
1078  PQclear(res);
1079  return true;
1080 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
#define lengthof(array)
Definition: c.h:562
#define DEFACLOBJ_SEQUENCE
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
#define DEFACLOBJ_TYPE
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
#define DEFACLOBJ_NAMESPACE
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DEFACLOBJ_RELATION
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
#define DEFACLOBJ_FUNCTION
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
const bool * translate_columns
Definition: print.h:170
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5314
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listDomains ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3526 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3688 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4936 of file describe.c.

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

Referenced by exec_command_d().

4937 {
4939  PGresult *res;
4940  int i;
4941 
4942  if (pset.sversion < 90100)
4943  {
4944  char sverbuf[32];
4945 
4946  psql_error("The server (version %s) does not support extensions.\n",
4948  sverbuf, sizeof(sverbuf)));
4949  return true;
4950  }
4951 
4952  initPQExpBuffer(&buf);
4953  printfPQExpBuffer(&buf,
4954  "SELECT e.extname, e.oid\n"
4955  "FROM pg_catalog.pg_extension e\n");
4956 
4957  processSQLNamePattern(pset.db, &buf, pattern,
4958  false, false,
4959  NULL, "e.extname", NULL,
4960  NULL);
4961 
4962  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4963 
4964  res = PSQLexec(buf.data);
4965  termPQExpBuffer(&buf);
4966  if (!res)
4967  return false;
4968 
4969  if (PQntuples(res) == 0)
4970  {
4971  if (!pset.quiet)
4972  {
4973  if (pattern)
4974  psql_error("Did not find any extension named \"%s\".\n",
4975  pattern);
4976  else
4977  psql_error("Did not find any extensions.\n");
4978  }
4979  PQclear(res);
4980  return false;
4981  }
4982 
4983  for (i = 0; i < PQntuples(res); i++)
4984  {
4985  const char *extname;
4986  const char *oid;
4987 
4988  extname = PQgetvalue(res, i, 0);
4989  oid = PQgetvalue(res, i, 1);
4990 
4991  if (!listOneExtensionContents(extname, oid))
4992  {
4993  PQclear(res);
4994  return false;
4995  }
4996  if (cancel_pressed)
4997  {
4998  PQclear(res);
4999  return false;
5000  }
5001  }
5002 
5003  PQclear(res);
5004  return true;
5005 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:66
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5008
void psql_error(const char *fmt,...)
Definition: common.c:220
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listExtensions ( const char *  pattern)

Definition at line 4879 of file describe.c.

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

Referenced by exec_command_d().

4880 {
4882  PGresult *res;
4883  printQueryOpt myopt = pset.popt;
4884 
4885  if (pset.sversion < 90100)
4886  {
4887  char sverbuf[32];
4888 
4889  psql_error("The server (version %s) does not support extensions.\n",
4891  sverbuf, sizeof(sverbuf)));
4892  return true;
4893  }
4894 
4895  initPQExpBuffer(&buf);
4896  printfPQExpBuffer(&buf,
4897  "SELECT e.extname AS \"%s\", "
4898  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4899  "FROM pg_catalog.pg_extension e "
4900  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4901  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4902  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4903  gettext_noop("Name"),
4904  gettext_noop("Version"),
4905  gettext_noop("Schema"),
4906  gettext_noop("Description"));
4907 
4908  processSQLNamePattern(pset.db, &buf, pattern,
4909  false, false,
4910  NULL, "e.extname", NULL,
4911  NULL);
4912 
4913  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4914 
4915  res = PSQLexec(buf.data);
4916  termPQExpBuffer(&buf);
4917  if (!res)
4918  return false;
4919 
4920  myopt.nullPrint = NULL;
4921  myopt.title = _("List of installed extensions");
4922  myopt.translate_header = true;
4923 
4924  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4925 
4926  PQclear(res);
4927  return true;
4928 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 4575 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4658 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4801 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3451 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 5046 of file describe.c.

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

Referenced by exec_command_d().

5047 {
5049  PGresult *res;
5050  printQueryOpt myopt = pset.popt;
5051  static const bool translate_columns[] = {false, false, false, false, false};
5052 
5053  if (pset.sversion < 100000)
5054  {
5055  char sverbuf[32];
5056 
5057  psql_error("The server (version %s) does not support publications.\n",
5059  sverbuf, sizeof(sverbuf)));
5060  return true;
5061  }
5062 
5063  initPQExpBuffer(&buf);
5064 
5065  printfPQExpBuffer(&buf,
5066  "SELECT pubname AS \"%s\",\n"
5067  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5068  " pubinsert AS \"%s\",\n"
5069  " pubupdate AS \"%s\",\n"
5070  " pubdelete AS \"%s\"\n",
5071  gettext_noop("Name"),
5072  gettext_noop("Owner"),
5073  gettext_noop("Inserts"),
5074  gettext_noop("Updates"),
5075  gettext_noop("Deletes"));
5076 
5077  appendPQExpBufferStr(&buf,
5078  "\nFROM pg_catalog.pg_publication\n");
5079 
5080  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5081  NULL, "pubname", NULL,
5082  NULL);
5083 
5084  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5085 
5086  res = PSQLexec(buf.data);
5087  termPQExpBuffer(&buf);
5088  if (!res)
5089  return false;
5090 
5091  myopt.nullPrint = NULL;
5092  myopt.title = _("List of publications");
5093  myopt.translate_header = true;
5094  myopt.translate_columns = translate_columns;
5095  myopt.n_translate_columns = lengthof(translate_columns);
5096 
5097  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5098 
5099  PQclear(res);
5100 
5101  return true;
5102 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
#define lengthof(array)
Definition: c.h:562
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3937 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3295 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4374 of file describe.c.

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

Referenced by exec_command_d().

4375 {
4377  PGresult *res;
4378  printQueryOpt myopt = pset.popt;
4379 
4380  if (pset.sversion < 80300)
4381  {
4382  char sverbuf[32];
4383 
4384  psql_error("The server (version %s) does not support full text search.\n",
4386  sverbuf, sizeof(sverbuf)));
4387  return true;
4388  }
4389 
4390  if (verbose)
4391  return listTSConfigsVerbose(pattern);
4392 
4393  initPQExpBuffer(&buf);
4394 
4395  printfPQExpBuffer(&buf,
4396  "SELECT\n"
4397  " n.nspname as \"%s\",\n"
4398  " c.cfgname as \"%s\",\n"
4399  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4400  "FROM pg_catalog.pg_ts_config c\n"
4401  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
4402  gettext_noop("Schema"),
4403  gettext_noop("Name"),
4404  gettext_noop("Description")
4405  );
4406 
4407  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4408  "n.nspname", "c.cfgname", NULL,
4409  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4410 
4411  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4412 
4413  res = PSQLexec(buf.data);
4414  termPQExpBuffer(&buf);
4415  if (!res)
4416  return false;
4417 
4418  myopt.nullPrint = NULL;
4419  myopt.title = _("List of text search configurations");
4420  myopt.translate_header = true;
4421 
4422  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4423 
4424  PQclear(res);
4425  return true;
4426 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:4429
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 4232 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3994 of file describe.c.

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

Referenced by exec_command_d().

3995 {
3997  PGresult *res;
3998  printQueryOpt myopt = pset.popt;
3999 
4000  if (pset.sversion < 80300)
4001  {
4002  char sverbuf[32];
4003 
4004  psql_error("The server (version %s) does not support full text search.\n",
4006  sverbuf, sizeof(sverbuf)));
4007  return true;
4008  }
4009 
4010  if (verbose)
4011  return listTSParsersVerbose(pattern);
4012 
4013  initPQExpBuffer(&buf);
4014 
4015  printfPQExpBuffer(&buf,
4016  "SELECT\n"
4017  " n.nspname as \"%s\",\n"
4018  " p.prsname as \"%s\",\n"
4019  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
4020  "FROM pg_catalog.pg_ts_parser p\n"
4021  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
4022  gettext_noop("Schema"),
4023  gettext_noop("Name"),
4024  gettext_noop("Description")
4025  );
4026 
4027  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4028  "n.nspname", "p.prsname", NULL,
4029  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
4030 
4031  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4032 
4033  res = PSQLexec(buf.data);
4034  termPQExpBuffer(&buf);
4035  if (!res)
4036  return false;
4037 
4038  myopt.nullPrint = NULL;
4039  myopt.title = _("List of text search parsers");
4040  myopt.translate_header = true;
4041 
4042  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4043 
4044  PQclear(res);
4045  return true;
4046 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:4052
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

Definition at line 4303 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4740 of file describe.c.

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

Referenced by exec_command_d().

4741 {
4743  PGresult *res;
4744  printQueryOpt myopt = pset.popt;
4745 
4746  if (pset.sversion < 80400)
4747  {
4748  char sverbuf[32];
4749 
4750  psql_error("The server (version %s) does not support user mappings.\n",
4752  sverbuf, sizeof(sverbuf)));
4753  return true;
4754  }
4755 
4756  initPQExpBuffer(&buf);
4757  printfPQExpBuffer(&buf,
4758  "SELECT um.srvname AS \"%s\",\n"
4759  " um.usename AS \"%s\"",
4760  gettext_noop("Server"),
4761  gettext_noop("User name"));
4762 
4763  if (verbose)
4764  appendPQExpBuffer(&buf,
4765  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4766  " '(' || array_to_string(ARRAY(SELECT "
4767  " quote_ident(option_name) || ' ' || "
4768  " quote_literal(option_value) FROM "
4769  " pg_options_to_table(umoptions)), ', ') || ')' "
4770  " END AS \"%s\"",
4771  gettext_noop("FDW Options"));
4772 
4773  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4774 
4775  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4776  NULL, "um.srvname", "um.usename", NULL);
4777 
4778  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4779 
4780  res = PSQLexec(buf.data);
4781  termPQExpBuffer(&buf);
4782  if (!res)
4783  return false;
4784 
4785  myopt.nullPrint = NULL;
4786  myopt.title = _("List of user mappings");
4787  myopt.translate_header = true;
4788 
4789  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4790 
4791  PQclear(res);
4792  return true;
4793 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:832
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool objectDescription ( const char *  pattern,
bool  showSystem 
)

Definition at line 1095 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 850 of file describe.c.

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

Referenced by exec_command_d(), and exec_command_z().

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