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

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

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

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

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

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

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

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

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

5046 {
5048  int i;
5049  PGresult *res;
5050 
5051  if (pset.sversion < 100000)
5052  {
5053  char sverbuf[32];
5054  psql_error("The server (version %s) does not support publications.\n",
5056  sverbuf, sizeof(sverbuf)));
5057  return true;
5058  }
5059 
5060  initPQExpBuffer(&buf);
5061 
5062  printfPQExpBuffer(&buf,
5063  "SELECT oid, pubname, puballtables, pubinsert,\n"
5064  " pubupdate, pubdelete\n"
5065  "FROM pg_catalog.pg_publication\n");
5066 
5067  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5068  NULL, "pubname", NULL,
5069  NULL);
5070 
5071  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5072 
5073  res = PSQLexec(buf.data);
5074  if (!res)
5075  {
5076  termPQExpBuffer(&buf);
5077  return false;
5078  }
5079 
5080  for (i = 0; i < PQntuples(res); i++)
5081  {
5082  const char align = 'l';
5083  int ncols = 3;
5084  int nrows = 1;
5085  int tables = 0;
5086  PGresult *tabres;
5087  char *pubid = PQgetvalue(res, i, 0);
5088  char *pubname = PQgetvalue(res, i, 1);
5089  bool puballtables = strcmp(PQgetvalue(res, i, 2), "t") == 0;
5090  int j;
5091  PQExpBufferData title;
5092  printTableOpt myopt = pset.popt.topt;
5093  printTableContent cont;
5094 
5095  initPQExpBuffer(&title);
5096  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5097  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5098 
5099  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5100  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5101  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5102 
5103  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5104  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5105  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5106 
5107  if (puballtables)
5108  printfPQExpBuffer(&buf,
5109  "SELECT n.nspname, c.relname\n"
5110  "FROM pg_catalog.pg_class c,\n"
5111  " pg_catalog.pg_namespace n\n"
5112  "WHERE c.relnamespace = n.oid\n"
5113  " AND c.relkind = " CppAsString2(RELKIND_RELATION) "\n"
5114  " AND n.nspname <> 'pg_catalog'\n"
5115  " AND n.nspname <> 'information_schema'\n"
5116  "ORDER BY 1,2");
5117  else
5118  printfPQExpBuffer(&buf,
5119  "SELECT n.nspname, c.relname\n"
5120  "FROM pg_catalog.pg_class c,\n"
5121  " pg_catalog.pg_namespace n,\n"
5122  " pg_catalog.pg_publication_rel pr\n"
5123  "WHERE c.relnamespace = n.oid\n"
5124  " AND c.oid = pr.prrelid\n"
5125  " AND pr.prpubid = '%s'\n"
5126  "ORDER BY 1,2", pubid);
5127 
5128  tabres = PSQLexec(buf.data);
5129  if (!tabres)
5130  {
5131  printTableCleanup(&cont);
5132  PQclear(res);
5133  termPQExpBuffer(&buf);
5134  termPQExpBuffer(&title);
5135  return false;
5136  }
5137  else
5138  tables = PQntuples(tabres);
5139 
5140  if (tables > 0)
5141  printTableAddFooter(&cont, _("Tables:"));
5142 
5143  for (j = 0; j < tables; j++)
5144  {
5145  printfPQExpBuffer(&buf, " \"%s.%s\"",
5146  PQgetvalue(tabres, j, 0),
5147  PQgetvalue(tabres, j, 1));
5148 
5149  printTableAddFooter(&cont, buf.data);
5150  }
5151  PQclear(tabres);
5152 
5153  printTable(&cont, pset.queryFout, false, pset.logfile);
5154  printTableCleanup(&cont);
5155 
5156  termPQExpBuffer(&title);
5157  }
5158 
5159  termPQExpBuffer(&buf);
5160  PQclear(res);
5161 
5162  return true;
5163 }
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:817
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c: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:65
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:181
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:603
bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

2986 {
2988  PGresult *res;
2989  printTableContent cont;
2990  printTableOpt myopt = pset.popt.topt;
2991  int ncols = 3;
2992  int nrows = 0;
2993  int i;
2994  int conns;
2995  const char align = 'l';
2996  char **attr;
2997 
2998  myopt.default_footer = false;
2999 
3000  initPQExpBuffer(&buf);
3001 
3002  if (pset.sversion >= 80100)
3003  {
3004  printfPQExpBuffer(&buf,
3005  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3006  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3007  " r.rolconnlimit, r.rolvaliduntil,\n"
3008  " ARRAY(SELECT b.rolname\n"
3009  " FROM pg_catalog.pg_auth_members m\n"
3010  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3011  " WHERE m.member = r.oid) as memberof");
3012 
3013  if (verbose && pset.sversion >= 80200)
3014  {
3015  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3016  ncols++;
3017  }
3018  if (pset.sversion >= 90100)
3019  {
3020  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3021  }
3022 
3023  if (pset.sversion >= 90500)
3024  {
3025  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3026  }
3027 
3028  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3029 
3030  if (!showSystem && !pattern)
3031  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3032 
3033  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3034  NULL, "r.rolname", NULL, NULL);
3035  }
3036  else
3037  {
3038  printfPQExpBuffer(&buf,
3039  "SELECT u.usename AS rolname,\n"
3040  " u.usesuper AS rolsuper,\n"
3041  " true AS rolinherit, false AS rolcreaterole,\n"
3042  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3043  " -1 AS rolconnlimit,"
3044  " u.valuntil as rolvaliduntil,\n"
3045  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3046  "\nFROM pg_catalog.pg_user u\n");
3047 
3048  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3049  NULL, "u.usename", NULL, NULL);
3050  }
3051 
3052  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3053 
3054  res = PSQLexec(buf.data);
3055  if (!res)
3056  return false;
3057 
3058  nrows = PQntuples(res);
3059  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3060 
3061  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3062 
3063  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3064  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3065  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3066 
3067  if (verbose && pset.sversion >= 80200)
3068  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3069 
3070  for (i = 0; i < nrows; i++)
3071  {
3072  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3073 
3074  resetPQExpBuffer(&buf);
3075  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3076  add_role_attribute(&buf, _("Superuser"));
3077 
3078  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3079  add_role_attribute(&buf, _("No inheritance"));
3080 
3081  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3082  add_role_attribute(&buf, _("Create role"));
3083 
3084  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3085  add_role_attribute(&buf, _("Create DB"));
3086 
3087  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3088  add_role_attribute(&buf, _("Cannot login"));
3089 
3090  if (pset.sversion >= 90100)
3091  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3092  add_role_attribute(&buf, _("Replication"));
3093 
3094  if (pset.sversion >= 90500)
3095  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3096  add_role_attribute(&buf, _("Bypass RLS"));
3097 
3098  conns = atoi(PQgetvalue(res, i, 6));
3099  if (conns >= 0)
3100  {
3101  if (buf.len > 0)
3102  appendPQExpBufferChar(&buf, '\n');
3103 
3104  if (conns == 0)
3105  appendPQExpBufferStr(&buf, _("No connections"));
3106  else
3107  appendPQExpBuffer(&buf, ngettext("%d connection",
3108  "%d connections",
3109  conns),
3110  conns);
3111  }
3112 
3113  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3114  {
3115  if (buf.len > 0)
3116  appendPQExpBufferStr(&buf, "\n");
3117  appendPQExpBufferStr(&buf, _("Password valid until "));
3118  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3119  }
3120 
3121  attr[i] = pg_strdup(buf.data);
3122 
3123  printTableAddCell(&cont, attr[i], false, false);
3124 
3125  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3126 
3127  if (verbose && pset.sversion >= 80200)
3128  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3129  }
3130  termPQExpBuffer(&buf);
3131 
3132  printTable(&cont, pset.queryFout, false, pset.logfile);
3133  printTableCleanup(&cont);
3134 
3135  for (i = 0; i < nrows; i++)
3136  free(attr[i]);
3137  free(attr);
3138 
3139  PQclear(res);
3140  return true;
3141 }
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:817
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3144
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:65
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c: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:603
bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

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

5172 {
5174  PGresult *res;
5175  printQueryOpt myopt = pset.popt;
5176  static const bool translate_columns[] = {false, false, false, false, false};
5177 
5178  if (pset.sversion < 100000)
5179  {
5180  char sverbuf[32];
5181  psql_error("The server (version %s) does not support subscriptions.\n",
5183  sverbuf, sizeof(sverbuf)));
5184  return true;
5185  }
5186 
5187  initPQExpBuffer(&buf);
5188 
5189  printfPQExpBuffer(&buf,
5190  "SELECT subname AS \"%s\"\n"
5191  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5192  ", subenabled AS \"%s\"\n"
5193  ", subpublications AS \"%s\"\n",
5194  gettext_noop("Name"),
5195  gettext_noop("Owner"),
5196  gettext_noop("Enabled"),
5197  gettext_noop("Publication"));
5198 
5199  if (verbose)
5200  {
5201  appendPQExpBuffer(&buf,
5202  ", subconninfo AS \"%s\"\n",
5203  gettext_noop("Conninfo"));
5204  }
5205 
5206  /* Only display subscriptions in current database. */
5207  appendPQExpBufferStr(&buf,
5208  "FROM pg_catalog.pg_subscription\n"
5209  "WHERE subdbid = (SELECT oid\n"
5210  " FROM pg_catalog.pg_database\n"
5211  " WHERE datname = current_database())");
5212 
5213  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5214  NULL, "subname", NULL,
5215  NULL);
5216 
5217  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5218 
5219  res = PSQLexec(buf.data);
5220  termPQExpBuffer(&buf);
5221  if (!res)
5222  return false;
5223 
5224  myopt.nullPrint = NULL;
5225  myopt.title = _("List of subscriptions");
5226  myopt.translate_header = true;
5227  myopt.translate_columns = translate_columns;
5228  myopt.n_translate_columns = lengthof(translate_columns);
5229 
5230  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5231 
5232  PQclear(res);
5233  return true;
5234 }
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:817
#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:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool describeTableDetails ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

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

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

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

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

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

Definition at line 779 of file describe.c.

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

Referenced by exec_command(), and main().

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

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

3691 {
3693  PGresult *res;
3694  printQueryOpt myopt = pset.popt;
3695  static const bool translate_columns[] = {false, false, false, true, false};
3696 
3697  initPQExpBuffer(&buf);
3698 
3699  /*
3700  * We need a left join to pg_proc for binary casts; the others are just
3701  * paranoia. Also note that we don't attempt to localize '(binary
3702  * coercible)', because there's too much risk of gettext translating a
3703  * function name that happens to match some string in the PO database.
3704  */
3705  printfPQExpBuffer(&buf,
3706  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3707  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3708  " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3709  " ELSE p.proname\n"
3710  " END as \"%s\",\n"
3711  " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3712  " WHEN c.castcontext = 'a' THEN '%s'\n"
3713  " ELSE '%s'\n"
3714  " END as \"%s\"",
3715  gettext_noop("Source type"),
3716  gettext_noop("Target type"),
3717  gettext_noop("Function"),
3718  gettext_noop("no"),
3719  gettext_noop("in assignment"),
3720  gettext_noop("yes"),
3721  gettext_noop("Implicit?"));
3722 
3723  if (verbose)
3724  appendPQExpBuffer(&buf,
3725  ",\n d.description AS \"%s\"\n",
3726  gettext_noop("Description"));
3727 
3728  appendPQExpBufferStr(&buf,
3729  "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
3730  " ON c.castfunc = p.oid\n"
3731  " LEFT JOIN pg_catalog.pg_type ts\n"
3732  " ON c.castsource = ts.oid\n"
3733  " LEFT JOIN pg_catalog.pg_namespace ns\n"
3734  " ON ns.oid = ts.typnamespace\n"
3735  " LEFT JOIN pg_catalog.pg_type tt\n"
3736  " ON c.casttarget = tt.oid\n"
3737  " LEFT JOIN pg_catalog.pg_namespace nt\n"
3738  " ON nt.oid = tt.typnamespace\n");
3739 
3740  if (verbose)
3741  appendPQExpBufferStr(&buf,
3742  " LEFT JOIN pg_catalog.pg_description d\n"
3743  " ON d.classoid = c.tableoid AND d.objoid = "
3744  "c.oid AND d.objsubid = 0\n");
3745 
3746  appendPQExpBufferStr(&buf, "WHERE ( (true");
3747 
3748  /*
3749  * Match name pattern against either internal or external name of either
3750  * castsource or casttarget
3751  */
3752  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3753  "ns.nspname", "ts.typname",
3754  "pg_catalog.format_type(ts.oid, NULL)",
3755  "pg_catalog.pg_type_is_visible(ts.oid)");
3756 
3757  appendPQExpBufferStr(&buf, ") OR (true");
3758 
3759  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3760  "nt.nspname", "tt.typname",
3761  "pg_catalog.format_type(tt.oid, NULL)",
3762  "pg_catalog.pg_type_is_visible(tt.oid)");
3763 
3764  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
3765 
3766  res = PSQLexec(buf.data);
3767  termPQExpBuffer(&buf);
3768  if (!res)
3769  return false;
3770 
3771  myopt.nullPrint = NULL;
3772  myopt.title = _("List of casts");
3773  myopt.translate_header = true;
3774  myopt.translate_columns = translate_columns;
3775  myopt.n_translate_columns = lengthof(translate_columns);
3776 
3777  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3778 
3779  PQclear(res);
3780  return true;
3781 }
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:817
#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:65
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:603
bool listCollations ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3790 {
3792  PGresult *res;
3793  printQueryOpt myopt = pset.popt;
3794  static const bool translate_columns[] = {false, false, false, false, false, false};
3795 
3796  if (pset.sversion < 90100)
3797  {
3798  char sverbuf[32];
3799 
3800  psql_error("The server (version %s) does not support collations.\n",
3802  sverbuf, sizeof(sverbuf)));
3803  return true;
3804  }
3805 
3806  initPQExpBuffer(&buf);
3807 
3808  printfPQExpBuffer(&buf,
3809  "SELECT n.nspname AS \"%s\",\n"
3810  " c.collname AS \"%s\",\n"
3811  " c.collcollate AS \"%s\",\n"
3812  " c.collctype AS \"%s\"",
3813  gettext_noop("Schema"),
3814  gettext_noop("Name"),
3815  gettext_noop("Collate"),
3816  gettext_noop("Ctype"));
3817 
3818  if (pset.sversion >= 100000)
3819  appendPQExpBuffer(&buf,
3820  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
3821  gettext_noop("Provider"));
3822 
3823  if (verbose)
3824  appendPQExpBuffer(&buf,
3825  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
3826  gettext_noop("Description"));
3827 
3828  appendPQExpBufferStr(&buf,
3829  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
3830  "WHERE n.oid = c.collnamespace\n");
3831 
3832  if (!showSystem && !pattern)
3833  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3834  " AND n.nspname <> 'information_schema'\n");
3835 
3836  /*
3837  * Hide collations that aren't usable in the current database's encoding.
3838  * If you think to change this, note that pg_collation_is_visible rejects
3839  * unusable collations, so you will need to hack name pattern processing
3840  * somehow to avoid inconsistent behavior.
3841  */
3842  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
3843 
3844  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3845  "n.nspname", "c.collname", NULL,
3846  "pg_catalog.pg_collation_is_visible(c.oid)");
3847 
3848  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3849 
3850  res = PSQLexec(buf.data);
3851  termPQExpBuffer(&buf);
3852  if (!res)
3853  return false;
3854 
3855  myopt.nullPrint = NULL;
3856  myopt.title = _("List of collations");
3857  myopt.translate_header = true;
3858  myopt.translate_columns = translate_columns;
3859  myopt.n_translate_columns = lengthof(translate_columns);
3860 
3861  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3862 
3863  PQclear(res);
3864  return true;
3865 }
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:817
#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:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listConversions ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3549 {
3551  PGresult *res;
3552  printQueryOpt myopt = pset.popt;
3553  static const bool translate_columns[] =
3554  {false, false, false, false, true, false};
3555 
3556  initPQExpBuffer(&buf);
3557 
3558  printfPQExpBuffer(&buf,
3559  "SELECT n.nspname AS \"%s\",\n"
3560  " c.conname AS \"%s\",\n"
3561  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
3562  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
3563  " CASE WHEN c.condefault THEN '%s'\n"
3564  " ELSE '%s' END AS \"%s\"",
3565  gettext_noop("Schema"),
3566  gettext_noop("Name"),
3567  gettext_noop("Source"),
3568  gettext_noop("Destination"),
3569  gettext_noop("yes"), gettext_noop("no"),
3570  gettext_noop("Default?"));
3571 
3572  if (verbose)
3573  appendPQExpBuffer(&buf,
3574  ",\n d.description AS \"%s\"",
3575  gettext_noop("Description"));
3576 
3577  appendPQExpBufferStr(&buf,
3578  "\nFROM pg_catalog.pg_conversion c\n"
3579  " JOIN pg_catalog.pg_namespace n "
3580  "ON n.oid = c.connamespace\n");
3581 
3582  if (verbose)
3583  appendPQExpBufferStr(&buf,
3584  "LEFT JOIN pg_catalog.pg_description d "
3585  "ON d.classoid = c.tableoid\n"
3586  " AND d.objoid = c.oid "
3587  "AND d.objsubid = 0\n");
3588 
3589  appendPQExpBufferStr(&buf, "WHERE true\n");
3590 
3591  if (!showSystem && !pattern)
3592  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3593  " AND n.nspname <> 'information_schema'\n");
3594 
3595  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3596  "n.nspname", "c.conname", NULL,
3597  "pg_catalog.pg_conversion_is_visible(c.oid)");
3598 
3599  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3600 
3601  res = PSQLexec(buf.data);
3602  termPQExpBuffer(&buf);
3603  if (!res)
3604  return false;
3605 
3606  myopt.nullPrint = NULL;
3607  myopt.title = _("List of conversions");
3608  myopt.translate_header = true;
3609  myopt.translate_columns = translate_columns;
3610  myopt.n_translate_columns = lengthof(translate_columns);
3611 
3612  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3613 
3614  PQclear(res);
3615  return true;
3616 }
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:817
#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:65
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:603
bool listDbRoleSettings ( const char *  pattern1,
const char *  pattern2 
)

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

3157 {
3159  PGresult *res;
3160  printQueryOpt myopt = pset.popt;
3161 
3162  initPQExpBuffer(&buf);
3163 
3164  if (pset.sversion >= 90000)
3165  {
3166  bool havewhere;
3167 
3168  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3169  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3170  "FROM pg_db_role_setting AS s\n"
3171  "LEFT JOIN pg_database ON pg_database.oid = setdatabase\n"
3172  "LEFT JOIN pg_roles ON pg_roles.oid = setrole\n",
3173  gettext_noop("Role"),
3174  gettext_noop("Database"),
3175  gettext_noop("Settings"));
3176  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3177  NULL, "pg_roles.rolname", NULL, NULL);
3178  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3179  NULL, "pg_database.datname", NULL, NULL);
3180  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3181  }
3182  else
3183  {
3184  fprintf(pset.queryFout,
3185  _("No per-database role settings support in this server version.\n"));
3186  return false;
3187  }
3188 
3189  res = PSQLexec(buf.data);
3190  if (!res)
3191  return false;
3192 
3193  if (PQntuples(res) == 0 && !pset.quiet)
3194  {
3195  if (pattern)
3196  fprintf(pset.queryFout, _("No matching settings found.\n"));
3197  else
3198  fprintf(pset.queryFout, _("No settings found.\n"));
3199  }
3200  else
3201  {
3202  myopt.nullPrint = NULL;
3203  myopt.title = _("List of settings");
3204  myopt.translate_header = true;
3205 
3206  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3207  }
3208 
3209  PQclear(res);
3210  resetPQExpBuffer(&buf);
3211  return true;
3212 }
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:817
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
FILE * logfile
Definition: settings.h: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:603
bool listDefaultACLs ( const char *  pattern)

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

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

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

3463 {
3465  PGresult *res;
3466  printQueryOpt myopt = pset.popt;
3467 
3468  initPQExpBuffer(&buf);
3469 
3470  printfPQExpBuffer(&buf,
3471  "SELECT n.nspname as \"%s\",\n"
3472  " t.typname as \"%s\",\n"
3473  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
3474  gettext_noop("Schema"),
3475  gettext_noop("Name"),
3476  gettext_noop("Type"));
3477 
3478  if (pset.sversion >= 90100)
3479  appendPQExpBuffer(&buf,
3480  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
3481  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
3482  gettext_noop("Collation"));
3483  appendPQExpBuffer(&buf,
3484  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
3485  " t.typdefault as \"%s\",\n"
3486  " pg_catalog.array_to_string(ARRAY(\n"
3487  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
3488  " ), ' ') as \"%s\"",
3489  gettext_noop("Nullable"),
3490  gettext_noop("Default"),
3491  gettext_noop("Check"));
3492 
3493  if (verbose)
3494  {
3495  if (pset.sversion >= 90200)
3496  {
3497  appendPQExpBufferStr(&buf, ",\n ");
3498  printACLColumn(&buf, "t.typacl");
3499  }
3500  appendPQExpBuffer(&buf,
3501  ",\n d.description as \"%s\"",
3502  gettext_noop("Description"));
3503  }
3504 
3505  appendPQExpBufferStr(&buf,
3506  "\nFROM pg_catalog.pg_type t\n"
3507  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
3508 
3509  if (verbose)
3510  appendPQExpBufferStr(&buf,
3511  " LEFT JOIN pg_catalog.pg_description d "
3512  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
3513  "AND d.objsubid = 0\n");
3514 
3515  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
3516 
3517  if (!showSystem && !pattern)
3518  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3519  " AND n.nspname <> 'information_schema'\n");
3520 
3521  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3522  "n.nspname", "t.typname", NULL,
3523  "pg_catalog.pg_type_is_visible(t.oid)");
3524 
3525  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3526 
3527  res = PSQLexec(buf.data);
3528  termPQExpBuffer(&buf);
3529  if (!res)
3530  return false;
3531 
3532  myopt.nullPrint = NULL;
3533  myopt.title = _("List of domains");
3534  myopt.translate_header = true;
3535 
3536  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3537 
3538  PQclear(res);
3539  return true;
3540 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c: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:5244
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:603
bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

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

3625 {
3627  PGresult *res;
3628  printQueryOpt myopt = pset.popt;
3629  static const bool translate_columns[] =
3630  {false, false, false, true, false, false, false};
3631 
3632  initPQExpBuffer(&buf);
3633 
3634  printfPQExpBuffer(&buf,
3635  "SELECT evtname as \"%s\", "
3636  "evtevent as \"%s\", "
3637  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
3638  " case evtenabled when 'O' then '%s'"
3639  " when 'R' then '%s'"
3640  " when 'A' then '%s'"
3641  " when 'D' then '%s' end as \"%s\",\n"
3642  " e.evtfoid::pg_catalog.regproc as \"%s\", "
3643  "pg_catalog.array_to_string(array(select x"
3644  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
3645  gettext_noop("Name"),
3646  gettext_noop("Event"),
3647  gettext_noop("Owner"),
3648  gettext_noop("enabled"),
3649  gettext_noop("replica"),
3650  gettext_noop("always"),
3651  gettext_noop("disabled"),
3652  gettext_noop("Enabled"),
3653  gettext_noop("Procedure"),
3654  gettext_noop("Tags"));
3655  if (verbose)
3656  appendPQExpBuffer(&buf,
3657  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
3658  gettext_noop("Description"));
3659  appendPQExpBufferStr(&buf,
3660  "\nFROM pg_catalog.pg_event_trigger e ");
3661 
3662  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3663  NULL, "evtname", NULL, NULL);
3664 
3665  appendPQExpBufferStr(&buf, "ORDER BY 1");
3666 
3667  res = PSQLexec(buf.data);
3668  termPQExpBuffer(&buf);
3669  if (!res)
3670  return false;
3671 
3672  myopt.nullPrint = NULL;
3673  myopt.title = _("List of event triggers");
3674  myopt.translate_header = true;
3675  myopt.translate_columns = translate_columns;
3676  myopt.n_translate_columns = lengthof(translate_columns);
3677 
3678  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3679 
3680  PQclear(res);
3681  return true;
3682 }
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:817
#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:65
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:603
bool listExtensionContents ( const char *  pattern)

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

4873 {
4875  PGresult *res;
4876  int i;
4877 
4878  if (pset.sversion < 90100)
4879  {
4880  char sverbuf[32];
4881 
4882  psql_error("The server (version %s) does not support extensions.\n",
4884  sverbuf, sizeof(sverbuf)));
4885  return true;
4886  }
4887 
4888  initPQExpBuffer(&buf);
4889  printfPQExpBuffer(&buf,
4890  "SELECT e.extname, e.oid\n"
4891  "FROM pg_catalog.pg_extension e\n");
4892 
4893  processSQLNamePattern(pset.db, &buf, pattern,
4894  false, false,
4895  NULL, "e.extname", NULL,
4896  NULL);
4897 
4898  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4899 
4900  res = PSQLexec(buf.data);
4901  termPQExpBuffer(&buf);
4902  if (!res)
4903  return false;
4904 
4905  if (PQntuples(res) == 0)
4906  {
4907  if (!pset.quiet)
4908  {
4909  if (pattern)
4910  psql_error("Did not find any extension named \"%s\".\n",
4911  pattern);
4912  else
4913  psql_error("Did not find any extensions.\n");
4914  }
4915  PQclear(res);
4916  return false;
4917  }
4918 
4919  for (i = 0; i < PQntuples(res); i++)
4920  {
4921  const char *extname;
4922  const char *oid;
4923 
4924  extname = PQgetvalue(res, i, 0);
4925  oid = PQgetvalue(res, i, 1);
4926 
4927  if (!listOneExtensionContents(extname, oid))
4928  {
4929  PQclear(res);
4930  return false;
4931  }
4932  if (cancel_pressed)
4933  {
4934  PQclear(res);
4935  return false;
4936  }
4937  }
4938 
4939  PQclear(res);
4940  return true;
4941 }
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:817
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:65
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:4944
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listExtensions ( const char *  pattern)

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

4816 {
4818  PGresult *res;
4819  printQueryOpt myopt = pset.popt;
4820 
4821  if (pset.sversion < 90100)
4822  {
4823  char sverbuf[32];
4824 
4825  psql_error("The server (version %s) does not support extensions.\n",
4827  sverbuf, sizeof(sverbuf)));
4828  return true;
4829  }
4830 
4831  initPQExpBuffer(&buf);
4832  printfPQExpBuffer(&buf,
4833  "SELECT e.extname AS \"%s\", "
4834  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4835  "FROM pg_catalog.pg_extension e "
4836  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4837  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4838  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4839  gettext_noop("Name"),
4840  gettext_noop("Version"),
4841  gettext_noop("Schema"),
4842  gettext_noop("Description"));
4843 
4844  processSQLNamePattern(pset.db, &buf, pattern,
4845  false, false,
4846  NULL, "e.extname", NULL,
4847  NULL);
4848 
4849  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4850 
4851  res = PSQLexec(buf.data);
4852  termPQExpBuffer(&buf);
4853  if (!res)
4854  return false;
4855 
4856  myopt.nullPrint = NULL;
4857  myopt.title = _("List of installed extensions");
4858  myopt.translate_header = true;
4859 
4860  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4861 
4862  PQclear(res);
4863  return true;
4864 }
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:817
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

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

4512 {
4514  PGresult *res;
4515  printQueryOpt myopt = pset.popt;
4516 
4517  if (pset.sversion < 80400)
4518  {
4519  char sverbuf[32];
4520 
4521  psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4523  sverbuf, sizeof(sverbuf)));
4524  return true;
4525  }
4526 
4527  initPQExpBuffer(&buf);
4528  printfPQExpBuffer(&buf,
4529  "SELECT fdw.fdwname AS \"%s\",\n"
4530  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4531  gettext_noop("Name"),
4532  gettext_noop("Owner"));
4533  if (pset.sversion >= 90100)
4534  appendPQExpBuffer(&buf,
4535  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4536  gettext_noop("Handler"));
4537  appendPQExpBuffer(&buf,
4538  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4539  gettext_noop("Validator"));
4540 
4541  if (verbose)
4542  {
4543  appendPQExpBufferStr(&buf, ",\n ");
4544  printACLColumn(&buf, "fdwacl");
4545  appendPQExpBuffer(&buf,
4546  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4547  " '(' || array_to_string(ARRAY(SELECT "
4548  " quote_ident(option_name) || ' ' || "
4549  " quote_literal(option_value) FROM "
4550  " pg_options_to_table(fdwoptions)), ', ') || ')' "
4551  " END AS \"%s\"",
4552  gettext_noop("FDW Options"));
4553 
4554  if (pset.sversion >= 90100)
4555  appendPQExpBuffer(&buf,
4556  ",\n d.description AS \"%s\" ",
4557  gettext_noop("Description"));
4558  }
4559 
4560  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4561 
4562  if (verbose && pset.sversion >= 90100)
4563  appendPQExpBufferStr(&buf,
4564  "LEFT JOIN pg_catalog.pg_description d\n"
4565  " ON d.classoid = fdw.tableoid "
4566  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4567 
4568  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4569  NULL, "fdwname", NULL, NULL);
4570 
4571  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4572 
4573  res = PSQLexec(buf.data);
4574  termPQExpBuffer(&buf);
4575  if (!res)
4576  return false;
4577 
4578  myopt.nullPrint = NULL;
4579  myopt.title = _("List of foreign-data wrappers");
4580  myopt.translate_header = true;
4581 
4582  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4583 
4584  PQclear(res);
4585  return true;
4586 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:5244
#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:603
bool listForeignServers ( const char *  pattern,
bool  verbose 
)

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

4595 {
4597  PGresult *res;
4598  printQueryOpt myopt = pset.popt;
4599 
4600  if (pset.sversion < 80400)
4601  {
4602  char sverbuf[32];
4603 
4604  psql_error("The server (version %s) does not support foreign servers.\n",
4606  sverbuf, sizeof(sverbuf)));
4607  return true;
4608  }
4609 
4610  initPQExpBuffer(&buf);
4611  printfPQExpBuffer(&buf,
4612  "SELECT s.srvname AS \"%s\",\n"
4613  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4614  " f.fdwname AS \"%s\"",
4615  gettext_noop("Name"),
4616  gettext_noop("Owner"),
4617  gettext_noop("Foreign-data wrapper"));
4618 
4619  if (verbose)
4620  {
4621  appendPQExpBufferStr(&buf, ",\n ");
4622  printACLColumn(&buf, "s.srvacl");
4623  appendPQExpBuffer(&buf,
4624  ",\n"
4625  " s.srvtype AS \"%s\",\n"
4626  " s.srvversion AS \"%s\",\n"
4627  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4628  " '(' || array_to_string(ARRAY(SELECT "
4629  " quote_ident(option_name) || ' ' || "
4630  " quote_literal(option_value) FROM "
4631  " pg_options_to_table(srvoptions)), ', ') || ')' "
4632  " END AS \"%s\",\n"
4633  " d.description AS \"%s\"",
4634  gettext_noop("Type"),
4635  gettext_noop("Version"),
4636  gettext_noop("FDW Options"),
4637  gettext_noop("Description"));
4638  }
4639 
4640  appendPQExpBufferStr(&buf,
4641  "\nFROM pg_catalog.pg_foreign_server s\n"
4642  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4643 
4644  if (verbose)
4645  appendPQExpBufferStr(&buf,
4646  "LEFT JOIN pg_description d\n "
4647  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4648  "AND d.objsubid = 0\n");
4649 
4650  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4651  NULL, "s.srvname", NULL, NULL);
4652 
4653  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4654 
4655  res = PSQLexec(buf.data);
4656  termPQExpBuffer(&buf);
4657  if (!res)
4658  return false;
4659 
4660  myopt.nullPrint = NULL;
4661  myopt.title = _("List of foreign servers");
4662  myopt.translate_header = true;
4663 
4664  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4665 
4666  PQclear(res);
4667  return true;
4668 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:5244
#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:603
bool listForeignTables ( const char *  pattern,
bool  verbose 
)

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

4738 {
4740  PGresult *res;
4741  printQueryOpt myopt = pset.popt;
4742 
4743  if (pset.sversion < 90100)
4744  {
4745  char sverbuf[32];
4746 
4747  psql_error("The server (version %s) does not support foreign tables.\n",
4749  sverbuf, sizeof(sverbuf)));
4750  return true;
4751  }
4752 
4753  initPQExpBuffer(&buf);
4754  printfPQExpBuffer(&buf,
4755  "SELECT n.nspname AS \"%s\",\n"
4756  " c.relname AS \"%s\",\n"
4757  " s.srvname AS \"%s\"",
4758  gettext_noop("Schema"),
4759  gettext_noop("Table"),
4760  gettext_noop("Server"));
4761 
4762  if (verbose)
4763  appendPQExpBuffer(&buf,
4764  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4765  " '(' || array_to_string(ARRAY(SELECT "
4766  " quote_ident(option_name) || ' ' || "
4767  " quote_literal(option_value) FROM "
4768  " pg_options_to_table(ftoptions)), ', ') || ')' "
4769  " END AS \"%s\",\n"
4770  " d.description AS \"%s\"",
4771  gettext_noop("FDW Options"),
4772  gettext_noop("Description"));
4773 
4774  appendPQExpBufferStr(&buf,
4775  "\nFROM pg_catalog.pg_foreign_table ft\n"
4776  " INNER JOIN pg_catalog.pg_class c"
4777  " ON c.oid = ft.ftrelid\n"
4778  " INNER JOIN pg_catalog.pg_namespace n"
4779  " ON n.oid = c.relnamespace\n"
4780  " INNER JOIN pg_catalog.pg_foreign_server s"
4781  " ON s.oid = ft.ftserver\n");
4782  if (verbose)
4783  appendPQExpBufferStr(&buf,
4784  " LEFT JOIN pg_catalog.pg_description d\n"
4785  " ON d.classoid = c.tableoid AND "
4786  "d.objoid = c.oid AND d.objsubid = 0\n");
4787 
4788  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4789  "n.nspname", "c.relname", NULL,
4790  "pg_catalog.pg_table_is_visible(c.oid)");
4791 
4792  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4793 
4794  res = PSQLexec(buf.data);
4795  termPQExpBuffer(&buf);
4796  if (!res)
4797  return false;
4798 
4799  myopt.nullPrint = NULL;
4800  myopt.title = _("List of foreign tables");
4801  myopt.translate_header = true;
4802 
4803  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4804 
4805  PQclear(res);
4806  return true;
4807 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listLanguages ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3388 {
3390  PGresult *res;
3391  printQueryOpt myopt = pset.popt;
3392 
3393  initPQExpBuffer(&buf);
3394 
3395  printfPQExpBuffer(&buf,
3396  "SELECT l.lanname AS \"%s\",\n",
3397  gettext_noop("Name"));
3398  if (pset.sversion >= 80300)
3399  appendPQExpBuffer(&buf,
3400  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
3401  gettext_noop("Owner"));
3402 
3403  appendPQExpBuffer(&buf,
3404  " l.lanpltrusted AS \"%s\"",
3405  gettext_noop("Trusted"));
3406 
3407  if (verbose)
3408  {
3409  appendPQExpBuffer(&buf,
3410  ",\n NOT l.lanispl AS \"%s\",\n"
3411  " l.lanplcallfoid::regprocedure AS \"%s\",\n"
3412  " l.lanvalidator::regprocedure AS \"%s\",\n ",
3413  gettext_noop("Internal Language"),
3414  gettext_noop("Call Handler"),
3415  gettext_noop("Validator"));
3416  if (pset.sversion >= 90000)
3417  appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n ",
3418  gettext_noop("Inline Handler"));
3419  printACLColumn(&buf, "l.lanacl");
3420  }
3421 
3422  appendPQExpBuffer(&buf,
3423  ",\n d.description AS \"%s\""
3424  "\nFROM pg_catalog.pg_language l\n"
3425  "LEFT JOIN pg_catalog.pg_description d\n"
3426  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
3427  " AND d.objsubid = 0\n",
3428  gettext_noop("Description"));
3429 
3430  if (pattern)
3431  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3432  NULL, "l.lanname", NULL, NULL);
3433 
3434  if (!showSystem && !pattern)
3435  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
3436 
3437 
3438  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3439 
3440  res = PSQLexec(buf.data);
3441  termPQExpBuffer(&buf);
3442  if (!res)
3443  return false;
3444 
3445  myopt.nullPrint = NULL;
3446  myopt.title = _("List of languages");
3447  myopt.translate_header = true;
3448 
3449  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3450 
3451  PQclear(res);
3452  return true;
3453 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c: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:5244
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:603
bool listPublications ( const char *  pattern)

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

4983 {
4985  PGresult *res;
4986  printQueryOpt myopt = pset.popt;
4987  static const bool translate_columns[] = {false, false, false, false, false};
4988 
4989  if (pset.sversion < 100000)
4990  {
4991  char sverbuf[32];
4992  psql_error("The server (version %s) does not support publications.\n",
4994  sverbuf, sizeof(sverbuf)));
4995  return true;
4996  }
4997 
4998  initPQExpBuffer(&buf);
4999 
5000  printfPQExpBuffer(&buf,
5001  "SELECT pubname AS \"%s\",\n"
5002  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5003  " pubinsert AS \"%s\",\n"
5004  " pubupdate AS \"%s\",\n"
5005  " pubdelete AS \"%s\"\n",
5006  gettext_noop("Name"),
5007  gettext_noop("Owner"),
5008  gettext_noop("Inserts"),
5009  gettext_noop("Updates"),
5010  gettext_noop("Deletes"));
5011 
5012  appendPQExpBufferStr(&buf,
5013  "\nFROM pg_catalog.pg_publication\n");
5014 
5015  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5016  NULL, "pubname", NULL,
5017  NULL);
5018 
5019  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5020 
5021  res = PSQLexec(buf.data);
5022  termPQExpBuffer(&buf);
5023  if (!res)
5024  return false;
5025 
5026  myopt.nullPrint = NULL;
5027  myopt.title = _("List of publications");
5028  myopt.translate_header = true;
5029  myopt.translate_columns = translate_columns;
5030  myopt.n_translate_columns = lengthof(translate_columns);
5031 
5032  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5033 
5034  PQclear(res);
5035 
5036  return true;
5037 }
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:817
#define lengthof(array)
Definition: c.h:562
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3874 {
3876  PGresult *res;
3877  printQueryOpt myopt = pset.popt;
3878 
3879  initPQExpBuffer(&buf);
3880  printfPQExpBuffer(&buf,
3881  "SELECT n.nspname AS \"%s\",\n"
3882  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
3883  gettext_noop("Name"),
3884  gettext_noop("Owner"));
3885 
3886  if (verbose)
3887  {
3888  appendPQExpBufferStr(&buf, ",\n ");
3889  printACLColumn(&buf, "n.nspacl");
3890  appendPQExpBuffer(&buf,
3891  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
3892  gettext_noop("Description"));
3893  }
3894 
3895  appendPQExpBuffer(&buf,
3896  "\nFROM pg_catalog.pg_namespace n\n");
3897 
3898  if (!showSystem && !pattern)
3899  appendPQExpBufferStr(&buf,
3900  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
3901 
3902  processSQLNamePattern(pset.db, &buf, pattern,
3903  !showSystem && !pattern, false,
3904  NULL, "n.nspname", NULL,
3905  NULL);
3906 
3907  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3908 
3909  res = PSQLexec(buf.data);
3910  termPQExpBuffer(&buf);
3911  if (!res)
3912  return false;
3913 
3914  myopt.nullPrint = NULL;
3915  myopt.title = _("List of schemas");
3916  myopt.translate_header = true;
3917 
3918  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3919 
3920  PQclear(res);
3921  return true;
3922 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c: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:5244
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:603
bool listTables ( const char *  tabtypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

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

3232 {
3233  bool showTables = strchr(tabtypes, 't') != NULL;
3234  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3235  bool showViews = strchr(tabtypes, 'v') != NULL;
3236  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3237  bool showSeq = strchr(tabtypes, 's') != NULL;
3238  bool showForeign = strchr(tabtypes, 'E') != NULL;
3239 
3241  PGresult *res;
3242  printQueryOpt myopt = pset.popt;
3243  static const bool translate_columns[] = {false, false, true, false, false, false, false};
3244 
3245  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3246  showTables = showViews = showMatViews = showSeq = showForeign = true;
3247 
3248  initPQExpBuffer(&buf);
3249 
3250  /*
3251  * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
3252  * it here for backwards compatibility.
3253  */
3254  printfPQExpBuffer(&buf,
3255  "SELECT n.nspname as \"%s\",\n"
3256  " c.relname as \"%s\",\n"
3257  " CASE c.relkind"
3258  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3259  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3260  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3261  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3262  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3263  " WHEN 's' THEN '%s'"
3264  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3265  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3266  " END as \"%s\",\n"
3267  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3268  gettext_noop("Schema"),
3269  gettext_noop("Name"),
3270  gettext_noop("table"),
3271  gettext_noop("view"),
3272  gettext_noop("materialized view"),
3273  gettext_noop("index"),
3274  gettext_noop("sequence"),
3275  gettext_noop("special"),
3276  gettext_noop("foreign table"),
3277  gettext_noop("table"), /* partitioned table */
3278  gettext_noop("Type"),
3279  gettext_noop("Owner"));
3280 
3281  if (showIndexes)
3282  appendPQExpBuffer(&buf,
3283  ",\n c2.relname as \"%s\"",
3284  gettext_noop("Table"));
3285 
3286  if (verbose)
3287  {
3288  /*
3289  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3290  * size of a table, including FSM, VM and TOAST tables.
3291  */
3292  if (pset.sversion >= 90000)
3293  appendPQExpBuffer(&buf,
3294  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3295  gettext_noop("Size"));
3296  else if (pset.sversion >= 80100)
3297  appendPQExpBuffer(&buf,
3298  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3299  gettext_noop("Size"));
3300 
3301  appendPQExpBuffer(&buf,
3302  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3303  gettext_noop("Description"));
3304  }
3305 
3306  appendPQExpBufferStr(&buf,
3307  "\nFROM pg_catalog.pg_class c"
3308  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3309  if (showIndexes)
3310  appendPQExpBufferStr(&buf,
3311  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3312  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3313 
3314  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3315  if (showTables)
3318  if (showViews)
3320  if (showMatViews)
3322  if (showIndexes)
3324  if (showSeq)
3326  if (showSystem || pattern)
3327  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3328  if (showForeign)
3330 
3331  appendPQExpBufferStr(&buf, "''"); /* dummy */
3332  appendPQExpBufferStr(&buf, ")\n");
3333 
3334  if (!showSystem && !pattern)
3335  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3336  " AND n.nspname <> 'information_schema'\n");
3337 
3338  /*
3339  * TOAST objects are suppressed unconditionally. Since we don't provide
3340  * any way to select RELKIND_TOASTVALUE above, we would never show toast
3341  * tables in any case; it seems a bit confusing to allow their indexes to
3342  * be shown. Use plain \d if you really need to look at a TOAST
3343  * table/index.
3344  */
3345  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3346 
3347  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3348  "n.nspname", "c.relname", NULL,
3349  "pg_catalog.pg_table_is_visible(c.oid)");
3350 
3351  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3352 
3353  res = PSQLexec(buf.data);
3354  termPQExpBuffer(&buf);
3355  if (!res)
3356  return false;
3357 
3358  if (PQntuples(res) == 0 && !pset.quiet)
3359  {
3360  if (pattern)
3361  fprintf(pset.queryFout, _("No matching relations found.\n"));
3362  else
3363  fprintf(pset.queryFout, _("No relations found.\n"));
3364  }
3365  else
3366  {
3367  myopt.nullPrint = NULL;
3368  myopt.title = _("List of relations");
3369  myopt.translate_header = true;
3370  myopt.translate_columns = translate_columns;
3371  myopt.n_translate_columns = lengthof(translate_columns);
3372 
3373  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3374  }
3375 
3376  PQclear(res);
3377  return true;
3378 }
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:817
#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:65
#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:603
bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

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

4311 {
4313  PGresult *res;
4314  printQueryOpt myopt = pset.popt;
4315 
4316  if (pset.sversion < 80300)
4317  {
4318  char sverbuf[32];
4319 
4320  psql_error("The server (version %s) does not support full text search.\n",
4322  sverbuf, sizeof(sverbuf)));
4323  return true;
4324  }
4325 
4326  if (verbose)
4327  return listTSConfigsVerbose(pattern);
4328 
4329  initPQExpBuffer(&buf);
4330 
4331  printfPQExpBuffer(&buf,
4332  "SELECT \n"
4333  " n.nspname as \"%s\",\n"
4334  " c.cfgname as \"%s\",\n"
4335  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4336  "FROM pg_catalog.pg_ts_config c\n"
4337  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace \n",
4338  gettext_noop("Schema"),
4339  gettext_noop("Name"),
4340  gettext_noop("Description")
4341  );
4342 
4343  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4344  "n.nspname", "c.cfgname", NULL,
4345  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4346 
4347  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4348 
4349  res = PSQLexec(buf.data);
4350  termPQExpBuffer(&buf);
4351  if (!res)
4352  return false;
4353 
4354  myopt.nullPrint = NULL;
4355  myopt.title = _("List of text search configurations");
4356  myopt.translate_header = true;
4357 
4358  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4359 
4360  PQclear(res);
4361  return true;
4362 }
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:817
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:4365
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

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

4169 {
4171  PGresult *res;
4172  printQueryOpt myopt = pset.popt;
4173 
4174  if (pset.sversion < 80300)
4175  {
4176  char sverbuf[32];
4177 
4178  psql_error("The server (version %s) does not support full text search.\n",
4180  sverbuf, sizeof(sverbuf)));
4181  return true;
4182  }
4183 
4184  initPQExpBuffer(&buf);
4185 
4186  printfPQExpBuffer(&buf,
4187  "SELECT \n"
4188  " n.nspname as \"%s\",\n"
4189  " d.dictname as \"%s\",\n",
4190  gettext_noop("Schema"),
4191  gettext_noop("Name"));
4192 
4193  if (verbose)
4194  {
4195  appendPQExpBuffer(&buf,
4196  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM \n"
4197  " pg_catalog.pg_ts_template t \n"
4198  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace \n"
4199  " WHERE d.dicttemplate = t.oid ) AS \"%s\", \n"
4200  " d.dictinitoption as \"%s\", \n",
4201  gettext_noop("Template"),
4202  gettext_noop("Init options"));
4203  }
4204 
4205  appendPQExpBuffer(&buf,
4206  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
4207  gettext_noop("Description"));
4208 
4209  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
4210  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
4211 
4212  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4213  "n.nspname", "d.dictname", NULL,
4214  "pg_catalog.pg_ts_dict_is_visible(d.oid)");
4215 
4216  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4217 
4218  res = PSQLexec(buf.data);
4219  termPQExpBuffer(&buf);
4220  if (!res)
4221  return false;
4222 
4223  myopt.nullPrint = NULL;
4224  myopt.title = _("List of text search dictionaries");
4225  myopt.translate_header = true;
4226 
4227  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4228 
4229  PQclear(res);
4230  return true;
4231 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listTSParsers ( const char *  pattern,
bool  verbose 
)

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

3931 {
3933  PGresult *res;
3934  printQueryOpt myopt = pset.popt;
3935 
3936  if (pset.sversion < 80300)
3937  {
3938  char sverbuf[32];
3939 
3940  psql_error("The server (version %s) does not support full text search.\n",
3942  sverbuf, sizeof(sverbuf)));
3943  return true;
3944  }
3945 
3946  if (verbose)
3947  return listTSParsersVerbose(pattern);
3948 
3949  initPQExpBuffer(&buf);
3950 
3951  printfPQExpBuffer(&buf,
3952  "SELECT \n"
3953  " n.nspname as \"%s\",\n"
3954  " p.prsname as \"%s\",\n"
3955  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
3956  "FROM pg_catalog.pg_ts_parser p \n"
3957  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
3958  gettext_noop("Schema"),
3959  gettext_noop("Name"),
3960  gettext_noop("Description")
3961  );
3962 
3963  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3964  "n.nspname", "p.prsname", NULL,
3965  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
3966 
3967  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3968 
3969  res = PSQLexec(buf.data);
3970  termPQExpBuffer(&buf);
3971  if (!res)
3972  return false;
3973 
3974  myopt.nullPrint = NULL;
3975  myopt.title = _("List of text search parsers");
3976  myopt.translate_header = true;
3977 
3978  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3979 
3980  PQclear(res);
3981  return true;
3982 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:3988
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:817
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

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

4240 {
4242  PGresult *res;
4243  printQueryOpt myopt = pset.popt;
4244 
4245  if (pset.sversion < 80300)
4246  {
4247  char sverbuf[32];
4248 
4249  psql_error("The server (version %s) does not support full text search.\n",
4251  sverbuf, sizeof(sverbuf)));
4252  return true;
4253  }
4254 
4255  initPQExpBuffer(&buf);
4256 
4257  if (verbose)
4258  printfPQExpBuffer(&buf,
4259  "SELECT \n"
4260  " n.nspname AS \"%s\",\n"
4261  " t.tmplname AS \"%s\",\n"
4262  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4263  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4264  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4265  gettext_noop("Schema"),
4266  gettext_noop("Name"),
4267  gettext_noop("Init"),
4268  gettext_noop("Lexize"),
4269  gettext_noop("Description"));
4270  else
4271  printfPQExpBuffer(&buf,
4272  "SELECT \n"
4273  " n.nspname AS \"%s\",\n"
4274  " t.tmplname AS \"%s\",\n"
4275  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4276  gettext_noop("Schema"),
4277  gettext_noop("Name"),
4278  gettext_noop("Description"));
4279 
4280  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4281  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4282 
4283  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4284  "n.nspname", "t.tmplname", NULL,
4285  "pg_catalog.pg_ts_template_is_visible(t.oid)");
4286 
4287  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4288 
4289  res = PSQLexec(buf.data);
4290  termPQExpBuffer(&buf);
4291  if (!res)
4292  return false;
4293 
4294  myopt.nullPrint = NULL;
4295  myopt.title = _("List of text search templates");
4296  myopt.translate_header = true;
4297 
4298  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4299 
4300  PQclear(res);
4301  return true;
4302 }
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:817
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool listUserMappings ( const char *  pattern,
bool  verbose 
)

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

4677 {
4679  PGresult *res;
4680  printQueryOpt myopt = pset.popt;
4681 
4682  if (pset.sversion < 80400)
4683  {
4684  char sverbuf[32];
4685 
4686  psql_error("The server (version %s) does not support user mappings.\n",
4688  sverbuf, sizeof(sverbuf)));
4689  return true;
4690  }
4691 
4692  initPQExpBuffer(&buf);
4693  printfPQExpBuffer(&buf,
4694  "SELECT um.srvname AS \"%s\",\n"
4695  " um.usename AS \"%s\"",
4696  gettext_noop("Server"),
4697  gettext_noop("User name"));
4698 
4699  if (verbose)
4700  appendPQExpBuffer(&buf,
4701  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4702  " '(' || array_to_string(ARRAY(SELECT "
4703  " quote_ident(option_name) || ' ' || "
4704  " quote_literal(option_value) FROM "
4705  " pg_options_to_table(umoptions)), ', ') || ')' "
4706  " END AS \"%s\"",
4707  gettext_noop("FDW Options"));
4708 
4709  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4710 
4711  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4712  NULL, "um.srvname", "um.usename", NULL);
4713 
4714  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4715 
4716  res = PSQLexec(buf.data);
4717  termPQExpBuffer(&buf);
4718  if (!res)
4719  return false;
4720 
4721  myopt.nullPrint = NULL;
4722  myopt.title = _("List of user mappings");
4723  myopt.translate_header = true;
4724 
4725  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4726 
4727  PQclear(res);
4728  return true;
4729 }
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:817
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:181
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:603
bool objectDescription ( const char *  pattern,
bool  showSystem 
)

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

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

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

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