PostgreSQL Source Code  git master
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

◆ describeAccessMethods()

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 148 of file describe.c.

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

Referenced by exec_command_d().

149 {
151  PGresult *res;
152  printQueryOpt myopt = pset.popt;
153  static const bool translate_columns[] = {false, true, false, false};
154 
155  if (pset.sversion < 90600)
156  {
157  char sverbuf[32];
158 
159  psql_error("The server (version %s) does not support access methods.\n",
161  sverbuf, sizeof(sverbuf)));
162  return true;
163  }
164 
165  initPQExpBuffer(&buf);
166 
167  printfPQExpBuffer(&buf,
168  "SELECT amname AS \"%s\",\n"
169  " CASE amtype"
170  " WHEN 'i' THEN '%s'"
171  " END AS \"%s\"",
172  gettext_noop("Name"),
173  gettext_noop("Index"),
174  gettext_noop("Type"));
175 
176  if (verbose)
177  {
178  appendPQExpBuffer(&buf,
179  ",\n amhandler AS \"%s\",\n"
180  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
181  gettext_noop("Handler"),
182  gettext_noop("Description"));
183  }
184 
186  "\nFROM pg_catalog.pg_am\n");
187 
188  processSQLNamePattern(pset.db, &buf, pattern, false, false,
189  NULL, "amname", NULL,
190  NULL);
191 
192  appendPQExpBufferStr(&buf, "ORDER BY 1;");
193 
194  res = PSQLexec(buf.data);
195  termPQExpBuffer(&buf);
196  if (!res)
197  return false;
198 
199  myopt.nullPrint = NULL;
200  myopt.title = _("List of access methods");
201  myopt.translate_header = true;
202  myopt.translate_columns = translate_columns;
203  myopt.n_translate_columns = lengthof(translate_columns);
204 
205  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
206 
207  PQclear(res);
208  return true;
209 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeAggregates()

bool describeAggregates ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 62 of file describe.c.

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

Referenced by exec_command_d().

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

◆ describeFunctions()

bool describeFunctions ( const char *  functypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 311 of file describe.c.

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

Referenced by exec_command_d().

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

◆ describeOperators()

bool describeOperators ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 746 of file describe.c.

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

Referenced by exec_command_d().

747 {
749  PGresult *res;
750  printQueryOpt myopt = pset.popt;
751 
752  initPQExpBuffer(&buf);
753 
754  /*
755  * Note: before Postgres 9.1, we did not assign comments to any built-in
756  * operators, preferring to let the comment on the underlying function
757  * suffice. The coalesce() on the obj_description() calls below supports
758  * this convention by providing a fallback lookup of a comment on the
759  * operator's function. As of 9.1 there is a policy that every built-in
760  * operator should have a comment; so the coalesce() is no longer
761  * necessary so far as built-in operators are concerned. We keep it
762  * anyway, for now, because (1) third-party modules may still be following
763  * the old convention, and (2) we'd need to do it anyway when talking to a
764  * pre-9.1 server.
765  */
766 
767  printfPQExpBuffer(&buf,
768  "SELECT n.nspname as \"%s\",\n"
769  " o.oprname AS \"%s\",\n"
770  " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
771  " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
772  " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
773  gettext_noop("Schema"),
774  gettext_noop("Name"),
775  gettext_noop("Left arg type"),
776  gettext_noop("Right arg type"),
777  gettext_noop("Result type"));
778 
779  if (verbose)
780  appendPQExpBuffer(&buf,
781  " o.oprcode AS \"%s\",\n",
782  gettext_noop("Function"));
783 
784  appendPQExpBuffer(&buf,
785  " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
786  " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
787  "FROM pg_catalog.pg_operator o\n"
788  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
789  gettext_noop("Description"));
790 
791  if (!showSystem && !pattern)
792  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
793  " AND n.nspname <> 'information_schema'\n");
794 
795  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
796  "n.nspname", "o.oprname", NULL,
797  "pg_catalog.pg_operator_is_visible(o.oid)");
798 
799  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
800 
801  res = PSQLexec(buf.data);
802  termPQExpBuffer(&buf);
803  if (!res)
804  return false;
805 
806  myopt.nullPrint = NULL;
807  myopt.title = _("List of operators");
808  myopt.translate_header = true;
809 
810  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
811 
812  PQclear(res);
813  return true;
814 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describePublications()

bool describePublications ( const char *  pattern)

Definition at line 5261 of file describe.c.

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

Referenced by exec_command_d().

5262 {
5264  int i;
5265  PGresult *res;
5266  bool has_pubtruncate;
5267 
5268  if (pset.sversion < 100000)
5269  {
5270  char sverbuf[32];
5271 
5272  psql_error("The server (version %s) does not support publications.\n",
5274  sverbuf, sizeof(sverbuf)));
5275  return true;
5276  }
5277 
5278  has_pubtruncate = (pset.sversion >= 110000);
5279 
5280  initPQExpBuffer(&buf);
5281 
5282  printfPQExpBuffer(&buf,
5283  "SELECT oid, pubname,\n"
5284  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
5285  " puballtables, pubinsert, pubupdate, pubdelete");
5286  if (has_pubtruncate)
5287  appendPQExpBuffer(&buf,
5288  ", pubtruncate");
5289  appendPQExpBuffer(&buf,
5290  "\nFROM pg_catalog.pg_publication\n");
5291 
5292  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5293  NULL, "pubname", NULL,
5294  NULL);
5295 
5296  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5297 
5298  res = PSQLexec(buf.data);
5299  if (!res)
5300  {
5301  termPQExpBuffer(&buf);
5302  return false;
5303  }
5304 
5305  if (PQntuples(res) == 0)
5306  {
5307  if (!pset.quiet)
5308  {
5309  if (pattern)
5310  psql_error("Did not find any publication named \"%s\".\n",
5311  pattern);
5312  else
5313  psql_error("Did not find any publications.\n");
5314  }
5315 
5316  termPQExpBuffer(&buf);
5317  PQclear(res);
5318  return false;
5319  }
5320 
5321  for (i = 0; i < PQntuples(res); i++)
5322  {
5323  const char align = 'l';
5324  int ncols = 5;
5325  int nrows = 1;
5326  int tables = 0;
5327  PGresult *tabres;
5328  char *pubid = PQgetvalue(res, i, 0);
5329  char *pubname = PQgetvalue(res, i, 1);
5330  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
5331  int j;
5332  PQExpBufferData title;
5333  printTableOpt myopt = pset.popt.topt;
5334  printTableContent cont;
5335 
5336  if (has_pubtruncate)
5337  ncols++;
5338 
5339  initPQExpBuffer(&title);
5340  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5341  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5342 
5343  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
5344  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
5345  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5346  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5347  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5348  if (has_pubtruncate)
5349  printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
5350 
5351  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
5352  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5353  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5354  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5355  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
5356  if (has_pubtruncate)
5357  printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
5358 
5359  if (!puballtables)
5360  {
5361  printfPQExpBuffer(&buf,
5362  "SELECT n.nspname, c.relname\n"
5363  "FROM pg_catalog.pg_class c,\n"
5364  " pg_catalog.pg_namespace n,\n"
5365  " pg_catalog.pg_publication_rel pr\n"
5366  "WHERE c.relnamespace = n.oid\n"
5367  " AND c.oid = pr.prrelid\n"
5368  " AND pr.prpubid = '%s'\n"
5369  "ORDER BY 1,2", pubid);
5370 
5371  tabres = PSQLexec(buf.data);
5372  if (!tabres)
5373  {
5374  printTableCleanup(&cont);
5375  PQclear(res);
5376  termPQExpBuffer(&buf);
5377  termPQExpBuffer(&title);
5378  return false;
5379  }
5380  else
5381  tables = PQntuples(tabres);
5382 
5383  if (tables > 0)
5384  printTableAddFooter(&cont, _("Tables:"));
5385 
5386  for (j = 0; j < tables; j++)
5387  {
5388  printfPQExpBuffer(&buf, " \"%s.%s\"",
5389  PQgetvalue(tabres, j, 0),
5390  PQgetvalue(tabres, j, 1));
5391 
5392  printTableAddFooter(&cont, buf.data);
5393  }
5394  PQclear(tabres);
5395  }
5396 
5397  printTable(&cont, pset.queryFout, false, pset.logfile);
5398  printTableCleanup(&cont);
5399 
5400  termPQExpBuffer(&title);
5401  }
5402 
5403  termPQExpBuffer(&buf);
5404  PQclear(res);
5405 
5406  return true;
5407 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
void printTableCleanup(printTableContent *const content)
Definition: print.c:3101
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
printTableOpt topt
Definition: print.h:165
#define gettext_noop(x)
Definition: c.h:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2970
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3010
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3190
void psql_error(const char *fmt,...)
Definition: common.c:221
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3058
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2933
int i
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeRoles()

bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3157 of file describe.c.

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

Referenced by exec_command_d().

3158 {
3160  PGresult *res;
3161  printTableContent cont;
3162  printTableOpt myopt = pset.popt.topt;
3163  int ncols = 3;
3164  int nrows = 0;
3165  int i;
3166  int conns;
3167  const char align = 'l';
3168  char **attr;
3169 
3170  myopt.default_footer = false;
3171 
3172  initPQExpBuffer(&buf);
3173 
3174  if (pset.sversion >= 80100)
3175  {
3176  printfPQExpBuffer(&buf,
3177  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3178  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3179  " r.rolconnlimit, r.rolvaliduntil,\n"
3180  " ARRAY(SELECT b.rolname\n"
3181  " FROM pg_catalog.pg_auth_members m\n"
3182  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3183  " WHERE m.member = r.oid) as memberof");
3184 
3185  if (verbose && pset.sversion >= 80200)
3186  {
3187  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3188  ncols++;
3189  }
3190  if (pset.sversion >= 90100)
3191  {
3192  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3193  }
3194 
3195  if (pset.sversion >= 90500)
3196  {
3197  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3198  }
3199 
3200  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3201 
3202  if (!showSystem && !pattern)
3203  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3204 
3205  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3206  NULL, "r.rolname", NULL, NULL);
3207  }
3208  else
3209  {
3210  printfPQExpBuffer(&buf,
3211  "SELECT u.usename AS rolname,\n"
3212  " u.usesuper AS rolsuper,\n"
3213  " true AS rolinherit, false AS rolcreaterole,\n"
3214  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3215  " -1 AS rolconnlimit,"
3216  " u.valuntil as rolvaliduntil,\n"
3217  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3218  "\nFROM pg_catalog.pg_user u\n");
3219 
3220  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3221  NULL, "u.usename", NULL, NULL);
3222  }
3223 
3224  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3225 
3226  res = PSQLexec(buf.data);
3227  if (!res)
3228  return false;
3229 
3230  nrows = PQntuples(res);
3231  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3232 
3233  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3234 
3235  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3236  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3237  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3238 
3239  if (verbose && pset.sversion >= 80200)
3240  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3241 
3242  for (i = 0; i < nrows; i++)
3243  {
3244  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3245 
3246  resetPQExpBuffer(&buf);
3247  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3248  add_role_attribute(&buf, _("Superuser"));
3249 
3250  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3251  add_role_attribute(&buf, _("No inheritance"));
3252 
3253  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3254  add_role_attribute(&buf, _("Create role"));
3255 
3256  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3257  add_role_attribute(&buf, _("Create DB"));
3258 
3259  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3260  add_role_attribute(&buf, _("Cannot login"));
3261 
3262  if (pset.sversion >= 90100)
3263  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3264  add_role_attribute(&buf, _("Replication"));
3265 
3266  if (pset.sversion >= 90500)
3267  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3268  add_role_attribute(&buf, _("Bypass RLS"));
3269 
3270  conns = atoi(PQgetvalue(res, i, 6));
3271  if (conns >= 0)
3272  {
3273  if (buf.len > 0)
3274  appendPQExpBufferChar(&buf, '\n');
3275 
3276  if (conns == 0)
3277  appendPQExpBufferStr(&buf, _("No connections"));
3278  else
3279  appendPQExpBuffer(&buf, ngettext("%d connection",
3280  "%d connections",
3281  conns),
3282  conns);
3283  }
3284 
3285  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3286  {
3287  if (buf.len > 0)
3288  appendPQExpBufferChar(&buf, '\n');
3289  appendPQExpBufferStr(&buf, _("Password valid until "));
3290  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3291  }
3292 
3293  attr[i] = pg_strdup(buf.data);
3294 
3295  printTableAddCell(&cont, attr[i], false, false);
3296 
3297  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3298 
3299  if (verbose && pset.sversion >= 80200)
3300  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3301  }
3302  termPQExpBuffer(&buf);
3303 
3304  printTable(&cont, pset.queryFout, false, pset.logfile);
3305  printTableCleanup(&cont);
3306 
3307  for (i = 0; i < nrows; i++)
3308  free(attr[i]);
3309  free(attr);
3310 
3311  PQclear(res);
3312  return true;
3313 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
void printTableCleanup(printTableContent *const content)
Definition: print.c:3101
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
printTableOpt topt
Definition: print.h:165
#define gettext_noop(x)
Definition: c.h:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3316
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2970
static PGconn ** conns
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3010
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3190
static int verbose
Definition: pg_basebackup.c:88
#define ngettext(s, p, n)
Definition: c.h:1022
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define free(a)
Definition: header.h:65
bool default_footer
Definition: print.h:110
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2933
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeSubscriptions()

bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 5416 of file describe.c.

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

Referenced by exec_command_d().

5417 {
5419  PGresult *res;
5420  printQueryOpt myopt = pset.popt;
5421  static const bool translate_columns[] = {false, false, false, false,
5422  false, false};
5423 
5424  if (pset.sversion < 100000)
5425  {
5426  char sverbuf[32];
5427 
5428  psql_error("The server (version %s) does not support subscriptions.\n",
5430  sverbuf, sizeof(sverbuf)));
5431  return true;
5432  }
5433 
5434  initPQExpBuffer(&buf);
5435 
5436  printfPQExpBuffer(&buf,
5437  "SELECT subname AS \"%s\"\n"
5438  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5439  ", subenabled AS \"%s\"\n"
5440  ", subpublications AS \"%s\"\n",
5441  gettext_noop("Name"),
5442  gettext_noop("Owner"),
5443  gettext_noop("Enabled"),
5444  gettext_noop("Publication"));
5445 
5446  if (verbose)
5447  {
5448  appendPQExpBuffer(&buf,
5449  ", subsynccommit AS \"%s\"\n"
5450  ", subconninfo AS \"%s\"\n",
5451  gettext_noop("Synchronous commit"),
5452  gettext_noop("Conninfo"));
5453  }
5454 
5455  /* Only display subscriptions in current database. */
5456  appendPQExpBufferStr(&buf,
5457  "FROM pg_catalog.pg_subscription\n"
5458  "WHERE subdbid = (SELECT oid\n"
5459  " FROM pg_catalog.pg_database\n"
5460  " WHERE datname = pg_catalog.current_database())");
5461 
5462  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5463  NULL, "subname", NULL,
5464  NULL);
5465 
5466  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5467 
5468  res = PSQLexec(buf.data);
5469  termPQExpBuffer(&buf);
5470  if (!res)
5471  return false;
5472 
5473  myopt.nullPrint = NULL;
5474  myopt.title = _("List of subscriptions");
5475  myopt.translate_header = true;
5476  myopt.translate_columns = translate_columns;
5477  myopt.n_translate_columns = lengthof(translate_columns);
5478 
5479  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5480 
5481  PQclear(res);
5482  return true;
5483 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeTableDetails()

bool describeTableDetails ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 1330 of file describe.c.

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

Referenced by exec_command_d().

1331 {
1333  PGresult *res;
1334  int i;
1335 
1336  initPQExpBuffer(&buf);
1337 
1338  printfPQExpBuffer(&buf,
1339  "SELECT c.oid,\n"
1340  " n.nspname,\n"
1341  " c.relname\n"
1342  "FROM pg_catalog.pg_class c\n"
1343  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1344 
1345  if (!showSystem && !pattern)
1346  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1347  " AND n.nspname <> 'information_schema'\n");
1348 
1349  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1350  "n.nspname", "c.relname", NULL,
1351  "pg_catalog.pg_table_is_visible(c.oid)");
1352 
1353  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1354 
1355  res = PSQLexec(buf.data);
1356  termPQExpBuffer(&buf);
1357  if (!res)
1358  return false;
1359 
1360  if (PQntuples(res) == 0)
1361  {
1362  if (!pset.quiet)
1363  {
1364  if (pattern)
1365  psql_error("Did not find any relation named \"%s\".\n",
1366  pattern);
1367  else
1368  psql_error("Did not find any relations.\n");
1369  }
1370  PQclear(res);
1371  return false;
1372  }
1373 
1374  for (i = 0; i < PQntuples(res); i++)
1375  {
1376  const char *oid;
1377  const char *nspname;
1378  const char *relname;
1379 
1380  oid = PQgetvalue(res, i, 0);
1381  nspname = PQgetvalue(res, i, 1);
1382  relname = PQgetvalue(res, i, 2);
1383 
1384  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1385  {
1386  PQclear(res);
1387  return false;
1388  }
1389  if (cancel_pressed)
1390  {
1391  PQclear(res);
1392  return false;
1393  }
1394  }
1395 
1396  PQclear(res);
1397  return true;
1398 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:67
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1408
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
void PQclear(PGresult *res)
Definition: fe-exec.c:671
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeTablespaces()

bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 216 of file describe.c.

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

Referenced by exec_command_d().

217 {
219  PGresult *res;
220  printQueryOpt myopt = pset.popt;
221 
222  if (pset.sversion < 80000)
223  {
224  char sverbuf[32];
225 
226  psql_error("The server (version %s) does not support tablespaces.\n",
228  sverbuf, sizeof(sverbuf)));
229  return true;
230  }
231 
232  initPQExpBuffer(&buf);
233 
234  if (pset.sversion >= 90200)
235  printfPQExpBuffer(&buf,
236  "SELECT spcname AS \"%s\",\n"
237  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
238  " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
239  gettext_noop("Name"),
240  gettext_noop("Owner"),
241  gettext_noop("Location"));
242  else
243  printfPQExpBuffer(&buf,
244  "SELECT spcname AS \"%s\",\n"
245  " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
246  " spclocation AS \"%s\"",
247  gettext_noop("Name"),
248  gettext_noop("Owner"),
249  gettext_noop("Location"));
250 
251  if (verbose)
252  {
253  appendPQExpBufferStr(&buf, ",\n ");
254  printACLColumn(&buf, "spcacl");
255  }
256 
257  if (verbose && pset.sversion >= 90000)
258  appendPQExpBuffer(&buf,
259  ",\n spcoptions AS \"%s\"",
260  gettext_noop("Options"));
261 
262  if (verbose && pset.sversion >= 90200)
263  appendPQExpBuffer(&buf,
264  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"",
265  gettext_noop("Size"));
266 
267  if (verbose && pset.sversion >= 80200)
268  appendPQExpBuffer(&buf,
269  ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
270  gettext_noop("Description"));
271 
273  "\nFROM pg_catalog.pg_tablespace\n");
274 
275  processSQLNamePattern(pset.db, &buf, pattern, false, false,
276  NULL, "spcname", NULL,
277  NULL);
278 
279  appendPQExpBufferStr(&buf, "ORDER BY 1;");
280 
281  res = PSQLexec(buf.data);
282  termPQExpBuffer(&buf);
283  if (!res)
284  return false;
285 
286  myopt.nullPrint = NULL;
287  myopt.title = _("List of tablespaces");
288  myopt.translate_header = true;
289 
290  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
291 
292  PQclear(res);
293  return true;
294 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ describeTypes()

bool describeTypes ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 630 of file describe.c.

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

Referenced by exec_command_d().

631 {
633  PGresult *res;
634  printQueryOpt myopt = pset.popt;
635 
636  initPQExpBuffer(&buf);
637 
638  printfPQExpBuffer(&buf,
639  "SELECT n.nspname as \"%s\",\n"
640  " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
641  gettext_noop("Schema"),
642  gettext_noop("Name"));
643  if (verbose)
644  appendPQExpBuffer(&buf,
645  " t.typname AS \"%s\",\n"
646  " CASE WHEN t.typrelid != 0\n"
647  " THEN CAST('tuple' AS pg_catalog.text)\n"
648  " WHEN t.typlen < 0\n"
649  " THEN CAST('var' AS pg_catalog.text)\n"
650  " ELSE CAST(t.typlen AS pg_catalog.text)\n"
651  " END AS \"%s\",\n",
652  gettext_noop("Internal name"),
653  gettext_noop("Size"));
654  if (verbose && pset.sversion >= 80300)
655  {
657  " pg_catalog.array_to_string(\n"
658  " ARRAY(\n"
659  " SELECT e.enumlabel\n"
660  " FROM pg_catalog.pg_enum e\n"
661  " WHERE e.enumtypid = t.oid\n");
662 
663  if (pset.sversion >= 90100)
665  " ORDER BY e.enumsortorder\n");
666  else
668  " ORDER BY e.oid\n");
669 
670  appendPQExpBuffer(&buf,
671  " ),\n"
672  " E'\\n'\n"
673  " ) AS \"%s\",\n",
674  gettext_noop("Elements"));
675  }
676  if (verbose)
677  {
678  appendPQExpBuffer(&buf,
679  " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
680  gettext_noop("Owner"));
681  }
682  if (verbose && pset.sversion >= 90200)
683  {
684  printACLColumn(&buf, "t.typacl");
685  appendPQExpBufferStr(&buf, ",\n ");
686  }
687 
688  appendPQExpBuffer(&buf,
689  " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
690  gettext_noop("Description"));
691 
692  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
693  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
694 
695  /*
696  * do not include complex types (typrelid!=0) unless they are standalone
697  * composite types
698  */
699  appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
700  appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
701  " FROM pg_catalog.pg_class c "
702  "WHERE c.oid = t.typrelid))\n");
703 
704  /*
705  * do not include array types (before 8.3 we have to use the assumption
706  * that their names start with underscore)
707  */
708  if (pset.sversion >= 80300)
709  appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
710  else
711  appendPQExpBufferStr(&buf, " AND t.typname !~ '^_'\n");
712 
713  if (!showSystem && !pattern)
714  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
715  " AND n.nspname <> 'information_schema'\n");
716 
717  /* Match name pattern against either internal or external name */
718  processSQLNamePattern(pset.db, &buf, pattern, true, false,
719  "n.nspname", "t.typname",
720  "pg_catalog.format_type(t.oid, NULL)",
721  "pg_catalog.pg_type_is_visible(t.oid)");
722 
723  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
724 
725  res = PSQLexec(buf.data);
726  termPQExpBuffer(&buf);
727  if (!res)
728  return false;
729 
730  myopt.nullPrint = NULL;
731  myopt.title = _("List of data types");
732  myopt.translate_header = true;
733 
734  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
735 
736  PQclear(res);
737  return true;
738 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
#define CppAsString2(x)
Definition: c.h:224
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listAllDbs()

bool listAllDbs ( const char *  pattern,
bool  verbose 
)

Definition at line 823 of file describe.c.

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

Referenced by exec_command_list(), and main().

824 {
825  PGresult *res;
827  printQueryOpt myopt = pset.popt;
828 
829  initPQExpBuffer(&buf);
830 
831  printfPQExpBuffer(&buf,
832  "SELECT d.datname as \"%s\",\n"
833  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
834  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
835  gettext_noop("Name"),
836  gettext_noop("Owner"),
837  gettext_noop("Encoding"));
838  if (pset.sversion >= 80400)
839  appendPQExpBuffer(&buf,
840  " d.datcollate as \"%s\",\n"
841  " d.datctype as \"%s\",\n",
842  gettext_noop("Collate"),
843  gettext_noop("Ctype"));
844  appendPQExpBufferStr(&buf, " ");
845  printACLColumn(&buf, "d.datacl");
846  if (verbose && pset.sversion >= 80200)
847  appendPQExpBuffer(&buf,
848  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
849  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
850  " ELSE 'No Access'\n"
851  " END as \"%s\"",
852  gettext_noop("Size"));
853  if (verbose && pset.sversion >= 80000)
854  appendPQExpBuffer(&buf,
855  ",\n t.spcname as \"%s\"",
856  gettext_noop("Tablespace"));
857  if (verbose && pset.sversion >= 80200)
858  appendPQExpBuffer(&buf,
859  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
860  gettext_noop("Description"));
862  "\nFROM pg_catalog.pg_database d\n");
863  if (verbose && pset.sversion >= 80000)
865  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
866 
867  if (pattern)
868  processSQLNamePattern(pset.db, &buf, pattern, false, false,
869  NULL, "d.datname", NULL, NULL);
870 
871  appendPQExpBufferStr(&buf, "ORDER BY 1;");
872  res = PSQLexec(buf.data);
873  termPQExpBuffer(&buf);
874  if (!res)
875  return false;
876 
877  myopt.nullPrint = NULL;
878  myopt.title = _("List of databases");
879  myopt.translate_header = true;
880 
881  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
882 
883  PQclear(res);
884  return true;
885 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listCasts()

bool listCasts ( const char *  pattern,
bool  verbose 
)

Definition at line 3881 of file describe.c.

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

Referenced by exec_command_d().

3882 {
3884  PGresult *res;
3885  printQueryOpt myopt = pset.popt;
3886  static const bool translate_columns[] = {false, false, false, true, false};
3887 
3888  initPQExpBuffer(&buf);
3889 
3890  /*
3891  * We need a left join to pg_proc for binary casts; the others are just
3892  * paranoia. Also note that we don't attempt to localize '(binary
3893  * coercible)', because there's too much risk of gettext translating a
3894  * function name that happens to match some string in the PO database.
3895  */
3896  printfPQExpBuffer(&buf,
3897  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3898  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3899  " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3900  " ELSE p.proname\n"
3901  " END as \"%s\",\n"
3902  " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3903  " WHEN c.castcontext = 'a' THEN '%s'\n"
3904  " ELSE '%s'\n"
3905  " END as \"%s\"",
3906  gettext_noop("Source type"),
3907  gettext_noop("Target type"),
3908  gettext_noop("Function"),
3909  gettext_noop("no"),
3910  gettext_noop("in assignment"),
3911  gettext_noop("yes"),
3912  gettext_noop("Implicit?"));
3913 
3914  if (verbose)
3915  appendPQExpBuffer(&buf,
3916  ",\n d.description AS \"%s\"\n",
3917  gettext_noop("Description"));
3918 
3919  appendPQExpBufferStr(&buf,
3920  "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
3921  " ON c.castfunc = p.oid\n"
3922  " LEFT JOIN pg_catalog.pg_type ts\n"
3923  " ON c.castsource = ts.oid\n"
3924  " LEFT JOIN pg_catalog.pg_namespace ns\n"
3925  " ON ns.oid = ts.typnamespace\n"
3926  " LEFT JOIN pg_catalog.pg_type tt\n"
3927  " ON c.casttarget = tt.oid\n"
3928  " LEFT JOIN pg_catalog.pg_namespace nt\n"
3929  " ON nt.oid = tt.typnamespace\n");
3930 
3931  if (verbose)
3932  appendPQExpBufferStr(&buf,
3933  " LEFT JOIN pg_catalog.pg_description d\n"
3934  " ON d.classoid = c.tableoid AND d.objoid = "
3935  "c.oid AND d.objsubid = 0\n");
3936 
3937  appendPQExpBufferStr(&buf, "WHERE ( (true");
3938 
3939  /*
3940  * Match name pattern against either internal or external name of either
3941  * castsource or casttarget
3942  */
3943  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3944  "ns.nspname", "ts.typname",
3945  "pg_catalog.format_type(ts.oid, NULL)",
3946  "pg_catalog.pg_type_is_visible(ts.oid)");
3947 
3948  appendPQExpBufferStr(&buf, ") OR (true");
3949 
3950  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3951  "nt.nspname", "tt.typname",
3952  "pg_catalog.format_type(tt.oid, NULL)",
3953  "pg_catalog.pg_type_is_visible(tt.oid)");
3954 
3955  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
3956 
3957  res = PSQLexec(buf.data);
3958  termPQExpBuffer(&buf);
3959  if (!res)
3960  return false;
3961 
3962  myopt.nullPrint = NULL;
3963  myopt.title = _("List of casts");
3964  myopt.translate_header = true;
3965  myopt.translate_columns = translate_columns;
3966  myopt.n_translate_columns = lengthof(translate_columns);
3967 
3968  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3969 
3970  PQclear(res);
3971  return true;
3972 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listCollations()

bool listCollations ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3980 of file describe.c.

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

Referenced by exec_command_d().

3981 {
3983  PGresult *res;
3984  printQueryOpt myopt = pset.popt;
3985  static const bool translate_columns[] = {false, false, false, false, false, false};
3986 
3987  if (pset.sversion < 90100)
3988  {
3989  char sverbuf[32];
3990 
3991  psql_error("The server (version %s) does not support collations.\n",
3993  sverbuf, sizeof(sverbuf)));
3994  return true;
3995  }
3996 
3997  initPQExpBuffer(&buf);
3998 
3999  printfPQExpBuffer(&buf,
4000  "SELECT n.nspname AS \"%s\",\n"
4001  " c.collname AS \"%s\",\n"
4002  " c.collcollate AS \"%s\",\n"
4003  " c.collctype AS \"%s\"",
4004  gettext_noop("Schema"),
4005  gettext_noop("Name"),
4006  gettext_noop("Collate"),
4007  gettext_noop("Ctype"));
4008 
4009  if (pset.sversion >= 100000)
4010  appendPQExpBuffer(&buf,
4011  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
4012  gettext_noop("Provider"));
4013 
4014  if (verbose)
4015  appendPQExpBuffer(&buf,
4016  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4017  gettext_noop("Description"));
4018 
4019  appendPQExpBufferStr(&buf,
4020  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4021  "WHERE n.oid = c.collnamespace\n");
4022 
4023  if (!showSystem && !pattern)
4024  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4025  " AND n.nspname <> 'information_schema'\n");
4026 
4027  /*
4028  * Hide collations that aren't usable in the current database's encoding.
4029  * If you think to change this, note that pg_collation_is_visible rejects
4030  * unusable collations, so you will need to hack name pattern processing
4031  * somehow to avoid inconsistent behavior.
4032  */
4033  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4034 
4035  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4036  "n.nspname", "c.collname", NULL,
4037  "pg_catalog.pg_collation_is_visible(c.oid)");
4038 
4039  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4040 
4041  res = PSQLexec(buf.data);
4042  termPQExpBuffer(&buf);
4043  if (!res)
4044  return false;
4045 
4046  myopt.nullPrint = NULL;
4047  myopt.title = _("List of collations");
4048  myopt.translate_header = true;
4049  myopt.translate_columns = translate_columns;
4050  myopt.n_translate_columns = lengthof(translate_columns);
4051 
4052  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4053 
4054  PQclear(res);
4055  return true;
4056 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listConversions()

bool listConversions ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3739 of file describe.c.

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

Referenced by exec_command_d().

3740 {
3742  PGresult *res;
3743  printQueryOpt myopt = pset.popt;
3744  static const bool translate_columns[] =
3745  {false, false, false, false, true, false};
3746 
3747  initPQExpBuffer(&buf);
3748 
3749  printfPQExpBuffer(&buf,
3750  "SELECT n.nspname AS \"%s\",\n"
3751  " c.conname AS \"%s\",\n"
3752  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
3753  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
3754  " CASE WHEN c.condefault THEN '%s'\n"
3755  " ELSE '%s' END AS \"%s\"",
3756  gettext_noop("Schema"),
3757  gettext_noop("Name"),
3758  gettext_noop("Source"),
3759  gettext_noop("Destination"),
3760  gettext_noop("yes"), gettext_noop("no"),
3761  gettext_noop("Default?"));
3762 
3763  if (verbose)
3764  appendPQExpBuffer(&buf,
3765  ",\n d.description AS \"%s\"",
3766  gettext_noop("Description"));
3767 
3768  appendPQExpBufferStr(&buf,
3769  "\nFROM pg_catalog.pg_conversion c\n"
3770  " JOIN pg_catalog.pg_namespace n "
3771  "ON n.oid = c.connamespace\n");
3772 
3773  if (verbose)
3774  appendPQExpBufferStr(&buf,
3775  "LEFT JOIN pg_catalog.pg_description d "
3776  "ON d.classoid = c.tableoid\n"
3777  " AND d.objoid = c.oid "
3778  "AND d.objsubid = 0\n");
3779 
3780  appendPQExpBufferStr(&buf, "WHERE true\n");
3781 
3782  if (!showSystem && !pattern)
3783  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3784  " AND n.nspname <> 'information_schema'\n");
3785 
3786  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3787  "n.nspname", "c.conname", NULL,
3788  "pg_catalog.pg_conversion_is_visible(c.oid)");
3789 
3790  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3791 
3792  res = PSQLexec(buf.data);
3793  termPQExpBuffer(&buf);
3794  if (!res)
3795  return false;
3796 
3797  myopt.nullPrint = NULL;
3798  myopt.title = _("List of conversions");
3799  myopt.translate_header = true;
3800  myopt.translate_columns = translate_columns;
3801  myopt.n_translate_columns = lengthof(translate_columns);
3802 
3803  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3804 
3805  PQclear(res);
3806  return true;
3807 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listDbRoleSettings()

bool listDbRoleSettings ( const char *  pattern1,
const char *  pattern2 
)

Definition at line 3328 of file describe.c.

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

Referenced by exec_command_d().

3329 {
3331  PGresult *res;
3332  printQueryOpt myopt = pset.popt;
3333  bool havewhere;
3334 
3335  if (pset.sversion < 90000)
3336  {
3337  char sverbuf[32];
3338 
3339  psql_error("The server (version %s) does not support per-database role settings.\n",
3341  sverbuf, sizeof(sverbuf)));
3342  return true;
3343  }
3344 
3345  initPQExpBuffer(&buf);
3346 
3347  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3348  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3349  "FROM pg_catalog.pg_db_role_setting s\n"
3350  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3351  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3352  gettext_noop("Role"),
3353  gettext_noop("Database"),
3354  gettext_noop("Settings"));
3355  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3356  NULL, "r.rolname", NULL, NULL);
3357  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3358  NULL, "d.datname", NULL, NULL);
3359  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3360 
3361  res = PSQLexec(buf.data);
3362  termPQExpBuffer(&buf);
3363  if (!res)
3364  return false;
3365 
3366  /*
3367  * Most functions in this file are content to print an empty table when
3368  * there are no matching objects. We intentionally deviate from that
3369  * here, but only in !quiet mode, because of the possibility that the user
3370  * is confused about what the two pattern arguments mean.
3371  */
3372  if (PQntuples(res) == 0 && !pset.quiet)
3373  {
3374  if (pattern && pattern2)
3375  psql_error("Did not find any settings for role \"%s\" and database \"%s\".\n",
3376  pattern, pattern2);
3377  else if (pattern)
3378  psql_error("Did not find any settings for role \"%s\".\n",
3379  pattern);
3380  else
3381  psql_error("Did not find any settings.\n");
3382  }
3383  else
3384  {
3385  myopt.nullPrint = NULL;
3386  myopt.title = _("List of settings");
3387  myopt.translate_header = true;
3388 
3389  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3390  }
3391 
3392  PQclear(res);
3393  return true;
3394 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1053 of file describe.c.

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

Referenced by exec_command_d().

1054 {
1056  PGresult *res;
1057  printQueryOpt myopt = pset.popt;
1058  static const bool translate_columns[] = {false, false, true, false};
1059 
1060  if (pset.sversion < 90000)
1061  {
1062  char sverbuf[32];
1063 
1064  psql_error("The server (version %s) does not support altering default privileges.\n",
1066  sverbuf, sizeof(sverbuf)));
1067  return true;
1068  }
1069 
1070  initPQExpBuffer(&buf);
1071 
1072  printfPQExpBuffer(&buf,
1073  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1074  " n.nspname AS \"%s\",\n"
1075  " 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"
1076  " ",
1077  gettext_noop("Owner"),
1078  gettext_noop("Schema"),
1079  DEFACLOBJ_RELATION,
1080  gettext_noop("table"),
1081  DEFACLOBJ_SEQUENCE,
1082  gettext_noop("sequence"),
1083  DEFACLOBJ_FUNCTION,
1084  gettext_noop("function"),
1085  DEFACLOBJ_TYPE,
1086  gettext_noop("type"),
1087  DEFACLOBJ_NAMESPACE,
1088  gettext_noop("schema"),
1089  gettext_noop("Type"));
1090 
1091  printACLColumn(&buf, "d.defaclacl");
1092 
1093  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1094  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1095 
1096  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1097  NULL,
1098  "n.nspname",
1099  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1100  NULL);
1101 
1102  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1103 
1104  res = PSQLexec(buf.data);
1105  if (!res)
1106  {
1107  termPQExpBuffer(&buf);
1108  return false;
1109  }
1110 
1111  myopt.nullPrint = NULL;
1112  printfPQExpBuffer(&buf, _("Default access privileges"));
1113  myopt.title = buf.data;
1114  myopt.translate_header = true;
1115  myopt.translate_columns = translate_columns;
1116  myopt.n_translate_columns = lengthof(translate_columns);
1117 
1118  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1119 
1120  termPQExpBuffer(&buf);
1121  PQclear(res);
1122  return true;
1123 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listDomains()

bool listDomains ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3653 of file describe.c.

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

Referenced by exec_command_d().

3654 {
3656  PGresult *res;
3657  printQueryOpt myopt = pset.popt;
3658 
3659  initPQExpBuffer(&buf);
3660 
3661  printfPQExpBuffer(&buf,
3662  "SELECT n.nspname as \"%s\",\n"
3663  " t.typname as \"%s\",\n"
3664  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
3665  gettext_noop("Schema"),
3666  gettext_noop("Name"),
3667  gettext_noop("Type"));
3668 
3669  if (pset.sversion >= 90100)
3670  appendPQExpBuffer(&buf,
3671  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
3672  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
3673  gettext_noop("Collation"));
3674  appendPQExpBuffer(&buf,
3675  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
3676  " t.typdefault as \"%s\",\n"
3677  " pg_catalog.array_to_string(ARRAY(\n"
3678  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
3679  " ), ' ') as \"%s\"",
3680  gettext_noop("Nullable"),
3681  gettext_noop("Default"),
3682  gettext_noop("Check"));
3683 
3684  if (verbose)
3685  {
3686  if (pset.sversion >= 90200)
3687  {
3688  appendPQExpBufferStr(&buf, ",\n ");
3689  printACLColumn(&buf, "t.typacl");
3690  }
3691  appendPQExpBuffer(&buf,
3692  ",\n d.description as \"%s\"",
3693  gettext_noop("Description"));
3694  }
3695 
3696  appendPQExpBufferStr(&buf,
3697  "\nFROM pg_catalog.pg_type t\n"
3698  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
3699 
3700  if (verbose)
3701  appendPQExpBufferStr(&buf,
3702  " LEFT JOIN pg_catalog.pg_description d "
3703  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
3704  "AND d.objsubid = 0\n");
3705 
3706  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
3707 
3708  if (!showSystem && !pattern)
3709  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3710  " AND n.nspname <> 'information_schema'\n");
3711 
3712  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3713  "n.nspname", "t.typname", NULL,
3714  "pg_catalog.pg_type_is_visible(t.oid)");
3715 
3716  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3717 
3718  res = PSQLexec(buf.data);
3719  termPQExpBuffer(&buf);
3720  if (!res)
3721  return false;
3722 
3723  myopt.nullPrint = NULL;
3724  myopt.title = _("List of domains");
3725  myopt.translate_header = true;
3726 
3727  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3728 
3729  PQclear(res);
3730  return true;
3731 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listEventTriggers()

bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 3815 of file describe.c.

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

Referenced by exec_command_d().

3816 {
3818  PGresult *res;
3819  printQueryOpt myopt = pset.popt;
3820  static const bool translate_columns[] =
3821  {false, false, false, true, false, false, false};
3822 
3823  initPQExpBuffer(&buf);
3824 
3825  printfPQExpBuffer(&buf,
3826  "SELECT evtname as \"%s\", "
3827  "evtevent as \"%s\", "
3828  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
3829  " case evtenabled when 'O' then '%s'"
3830  " when 'R' then '%s'"
3831  " when 'A' then '%s'"
3832  " when 'D' then '%s' end as \"%s\",\n"
3833  " e.evtfoid::pg_catalog.regproc as \"%s\", "
3834  "pg_catalog.array_to_string(array(select x"
3835  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
3836  gettext_noop("Name"),
3837  gettext_noop("Event"),
3838  gettext_noop("Owner"),
3839  gettext_noop("enabled"),
3840  gettext_noop("replica"),
3841  gettext_noop("always"),
3842  gettext_noop("disabled"),
3843  gettext_noop("Enabled"),
3844  gettext_noop("Procedure"),
3845  gettext_noop("Tags"));
3846  if (verbose)
3847  appendPQExpBuffer(&buf,
3848  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
3849  gettext_noop("Description"));
3850  appendPQExpBufferStr(&buf,
3851  "\nFROM pg_catalog.pg_event_trigger e ");
3852 
3853  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3854  NULL, "evtname", NULL, NULL);
3855 
3856  appendPQExpBufferStr(&buf, "ORDER BY 1");
3857 
3858  res = PSQLexec(buf.data);
3859  termPQExpBuffer(&buf);
3860  if (!res)
3861  return false;
3862 
3863  myopt.nullPrint = NULL;
3864  myopt.title = _("List of event triggers");
3865  myopt.translate_header = true;
3866  myopt.translate_columns = translate_columns;
3867  myopt.n_translate_columns = lengthof(translate_columns);
3868 
3869  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3870 
3871  PQclear(res);
3872  return true;
3873 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listExtensionContents()

bool listExtensionContents ( const char *  pattern)

Definition at line 5077 of file describe.c.

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

Referenced by exec_command_d().

5078 {
5080  PGresult *res;
5081  int i;
5082 
5083  if (pset.sversion < 90100)
5084  {
5085  char sverbuf[32];
5086 
5087  psql_error("The server (version %s) does not support extensions.\n",
5089  sverbuf, sizeof(sverbuf)));
5090  return true;
5091  }
5092 
5093  initPQExpBuffer(&buf);
5094  printfPQExpBuffer(&buf,
5095  "SELECT e.extname, e.oid\n"
5096  "FROM pg_catalog.pg_extension e\n");
5097 
5098  processSQLNamePattern(pset.db, &buf, pattern,
5099  false, false,
5100  NULL, "e.extname", NULL,
5101  NULL);
5102 
5103  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5104 
5105  res = PSQLexec(buf.data);
5106  termPQExpBuffer(&buf);
5107  if (!res)
5108  return false;
5109 
5110  if (PQntuples(res) == 0)
5111  {
5112  if (!pset.quiet)
5113  {
5114  if (pattern)
5115  psql_error("Did not find any extension named \"%s\".\n",
5116  pattern);
5117  else
5118  psql_error("Did not find any extensions.\n");
5119  }
5120  PQclear(res);
5121  return false;
5122  }
5123 
5124  for (i = 0; i < PQntuples(res); i++)
5125  {
5126  const char *extname;
5127  const char *oid;
5128 
5129  extname = PQgetvalue(res, i, 0);
5130  oid = PQgetvalue(res, i, 1);
5131 
5132  if (!listOneExtensionContents(extname, oid))
5133  {
5134  PQclear(res);
5135  return false;
5136  }
5137  if (cancel_pressed)
5138  {
5139  PQclear(res);
5140  return false;
5141  }
5142  }
5143 
5144  PQclear(res);
5145  return true;
5146 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:67
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5149
void psql_error(const char *fmt,...)
Definition: common.c:221
void PQclear(PGresult *res)
Definition: fe-exec.c:671
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listExtensions()

bool listExtensions ( const char *  pattern)

Definition at line 5020 of file describe.c.

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

Referenced by exec_command_d().

5021 {
5023  PGresult *res;
5024  printQueryOpt myopt = pset.popt;
5025 
5026  if (pset.sversion < 90100)
5027  {
5028  char sverbuf[32];
5029 
5030  psql_error("The server (version %s) does not support extensions.\n",
5032  sverbuf, sizeof(sverbuf)));
5033  return true;
5034  }
5035 
5036  initPQExpBuffer(&buf);
5037  printfPQExpBuffer(&buf,
5038  "SELECT e.extname AS \"%s\", "
5039  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
5040  "FROM pg_catalog.pg_extension e "
5041  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
5042  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
5043  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
5044  gettext_noop("Name"),
5045  gettext_noop("Version"),
5046  gettext_noop("Schema"),
5047  gettext_noop("Description"));
5048 
5049  processSQLNamePattern(pset.db, &buf, pattern,
5050  false, false,
5051  NULL, "e.extname", NULL,
5052  NULL);
5053 
5054  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5055 
5056  res = PSQLexec(buf.data);
5057  termPQExpBuffer(&buf);
5058  if (!res)
5059  return false;
5060 
5061  myopt.nullPrint = NULL;
5062  myopt.title = _("List of installed extensions");
5063  myopt.translate_header = true;
5064 
5065  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5066 
5067  PQclear(res);
5068  return true;
5069 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 4716 of file describe.c.

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

Referenced by exec_command_d().

4717 {
4719  PGresult *res;
4720  printQueryOpt myopt = pset.popt;
4721 
4722  if (pset.sversion < 80400)
4723  {
4724  char sverbuf[32];
4725 
4726  psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4728  sverbuf, sizeof(sverbuf)));
4729  return true;
4730  }
4731 
4732  initPQExpBuffer(&buf);
4733  printfPQExpBuffer(&buf,
4734  "SELECT fdw.fdwname AS \"%s\",\n"
4735  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4736  gettext_noop("Name"),
4737  gettext_noop("Owner"));
4738  if (pset.sversion >= 90100)
4739  appendPQExpBuffer(&buf,
4740  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4741  gettext_noop("Handler"));
4742  appendPQExpBuffer(&buf,
4743  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4744  gettext_noop("Validator"));
4745 
4746  if (verbose)
4747  {
4748  appendPQExpBufferStr(&buf, ",\n ");
4749  printACLColumn(&buf, "fdwacl");
4750  appendPQExpBuffer(&buf,
4751  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4752  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4753  " pg_catalog.quote_ident(option_name) || ' ' || "
4754  " pg_catalog.quote_literal(option_value) FROM "
4755  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
4756  " END AS \"%s\"",
4757  gettext_noop("FDW options"));
4758 
4759  if (pset.sversion >= 90100)
4760  appendPQExpBuffer(&buf,
4761  ",\n d.description AS \"%s\" ",
4762  gettext_noop("Description"));
4763  }
4764 
4765  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4766 
4767  if (verbose && pset.sversion >= 90100)
4768  appendPQExpBufferStr(&buf,
4769  "LEFT JOIN pg_catalog.pg_description d\n"
4770  " ON d.classoid = fdw.tableoid "
4771  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4772 
4773  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4774  NULL, "fdwname", NULL, NULL);
4775 
4776  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4777 
4778  res = PSQLexec(buf.data);
4779  termPQExpBuffer(&buf);
4780  if (!res)
4781  return false;
4782 
4783  myopt.nullPrint = NULL;
4784  myopt.title = _("List of foreign-data wrappers");
4785  myopt.translate_header = true;
4786 
4787  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4788 
4789  PQclear(res);
4790  return true;
4791 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listForeignServers()

bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 4799 of file describe.c.

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

Referenced by exec_command_d().

4800 {
4802  PGresult *res;
4803  printQueryOpt myopt = pset.popt;
4804 
4805  if (pset.sversion < 80400)
4806  {
4807  char sverbuf[32];
4808 
4809  psql_error("The server (version %s) does not support foreign servers.\n",
4811  sverbuf, sizeof(sverbuf)));
4812  return true;
4813  }
4814 
4815  initPQExpBuffer(&buf);
4816  printfPQExpBuffer(&buf,
4817  "SELECT s.srvname AS \"%s\",\n"
4818  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4819  " f.fdwname AS \"%s\"",
4820  gettext_noop("Name"),
4821  gettext_noop("Owner"),
4822  gettext_noop("Foreign-data wrapper"));
4823 
4824  if (verbose)
4825  {
4826  appendPQExpBufferStr(&buf, ",\n ");
4827  printACLColumn(&buf, "s.srvacl");
4828  appendPQExpBuffer(&buf,
4829  ",\n"
4830  " s.srvtype AS \"%s\",\n"
4831  " s.srvversion AS \"%s\",\n"
4832  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4833  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4834  " pg_catalog.quote_ident(option_name) || ' ' || "
4835  " pg_catalog.quote_literal(option_value) FROM "
4836  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
4837  " END AS \"%s\",\n"
4838  " d.description AS \"%s\"",
4839  gettext_noop("Type"),
4840  gettext_noop("Version"),
4841  gettext_noop("FDW options"),
4842  gettext_noop("Description"));
4843  }
4844 
4845  appendPQExpBufferStr(&buf,
4846  "\nFROM pg_catalog.pg_foreign_server s\n"
4847  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4848 
4849  if (verbose)
4850  appendPQExpBufferStr(&buf,
4851  "LEFT JOIN pg_catalog.pg_description d\n "
4852  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4853  "AND d.objsubid = 0\n");
4854 
4855  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4856  NULL, "s.srvname", NULL, NULL);
4857 
4858  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4859 
4860  res = PSQLexec(buf.data);
4861  termPQExpBuffer(&buf);
4862  if (!res)
4863  return false;
4864 
4865  myopt.nullPrint = NULL;
4866  myopt.title = _("List of foreign servers");
4867  myopt.translate_header = true;
4868 
4869  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4870 
4871  PQclear(res);
4872  return true;
4873 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listForeignTables()

bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 4942 of file describe.c.

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

Referenced by exec_command_d().

4943 {
4945  PGresult *res;
4946  printQueryOpt myopt = pset.popt;
4947 
4948  if (pset.sversion < 90100)
4949  {
4950  char sverbuf[32];
4951 
4952  psql_error("The server (version %s) does not support foreign tables.\n",
4954  sverbuf, sizeof(sverbuf)));
4955  return true;
4956  }
4957 
4958  initPQExpBuffer(&buf);
4959  printfPQExpBuffer(&buf,
4960  "SELECT n.nspname AS \"%s\",\n"
4961  " c.relname AS \"%s\",\n"
4962  " s.srvname AS \"%s\"",
4963  gettext_noop("Schema"),
4964  gettext_noop("Table"),
4965  gettext_noop("Server"));
4966 
4967  if (verbose)
4968  appendPQExpBuffer(&buf,
4969  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4970  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4971  " pg_catalog.quote_ident(option_name) || ' ' || "
4972  " pg_catalog.quote_literal(option_value) FROM "
4973  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
4974  " END AS \"%s\",\n"
4975  " d.description AS \"%s\"",
4976  gettext_noop("FDW options"),
4977  gettext_noop("Description"));
4978 
4979  appendPQExpBufferStr(&buf,
4980  "\nFROM pg_catalog.pg_foreign_table ft\n"
4981  " INNER JOIN pg_catalog.pg_class c"
4982  " ON c.oid = ft.ftrelid\n"
4983  " INNER JOIN pg_catalog.pg_namespace n"
4984  " ON n.oid = c.relnamespace\n"
4985  " INNER JOIN pg_catalog.pg_foreign_server s"
4986  " ON s.oid = ft.ftserver\n");
4987  if (verbose)
4988  appendPQExpBufferStr(&buf,
4989  " LEFT JOIN pg_catalog.pg_description d\n"
4990  " ON d.classoid = c.tableoid AND "
4991  "d.objoid = c.oid AND d.objsubid = 0\n");
4992 
4993  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4994  "n.nspname", "c.relname", NULL,
4995  "pg_catalog.pg_table_is_visible(c.oid)");
4996 
4997  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4998 
4999  res = PSQLexec(buf.data);
5000  termPQExpBuffer(&buf);
5001  if (!res)
5002  return false;
5003 
5004  myopt.nullPrint = NULL;
5005  myopt.title = _("List of foreign tables");
5006  myopt.translate_header = true;
5007 
5008  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5009 
5010  PQclear(res);
5011  return true;
5012 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listLanguages()

bool listLanguages ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3578 of file describe.c.

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

Referenced by exec_command_d().

3579 {
3581  PGresult *res;
3582  printQueryOpt myopt = pset.popt;
3583 
3584  initPQExpBuffer(&buf);
3585 
3586  printfPQExpBuffer(&buf,
3587  "SELECT l.lanname AS \"%s\",\n",
3588  gettext_noop("Name"));
3589  if (pset.sversion >= 80300)
3590  appendPQExpBuffer(&buf,
3591  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
3592  gettext_noop("Owner"));
3593 
3594  appendPQExpBuffer(&buf,
3595  " l.lanpltrusted AS \"%s\"",
3596  gettext_noop("Trusted"));
3597 
3598  if (verbose)
3599  {
3600  appendPQExpBuffer(&buf,
3601  ",\n NOT l.lanispl AS \"%s\",\n"
3602  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
3603  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n ",
3604  gettext_noop("Internal language"),
3605  gettext_noop("Call handler"),
3606  gettext_noop("Validator"));
3607  if (pset.sversion >= 90000)
3608  appendPQExpBuffer(&buf, "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
3609  gettext_noop("Inline handler"));
3610  printACLColumn(&buf, "l.lanacl");
3611  }
3612 
3613  appendPQExpBuffer(&buf,
3614  ",\n d.description AS \"%s\""
3615  "\nFROM pg_catalog.pg_language l\n"
3616  "LEFT JOIN pg_catalog.pg_description d\n"
3617  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
3618  " AND d.objsubid = 0\n",
3619  gettext_noop("Description"));
3620 
3621  if (pattern)
3622  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3623  NULL, "l.lanname", NULL, NULL);
3624 
3625  if (!showSystem && !pattern)
3626  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
3627 
3628 
3629  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3630 
3631  res = PSQLexec(buf.data);
3632  termPQExpBuffer(&buf);
3633  if (!res)
3634  return false;
3635 
3636  myopt.nullPrint = NULL;
3637  myopt.title = _("List of languages");
3638  myopt.translate_header = true;
3639 
3640  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3641 
3642  PQclear(res);
3643  return true;
3644 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listPublications()

bool listPublications ( const char *  pattern)

Definition at line 5190 of file describe.c.

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

Referenced by exec_command_d().

5191 {
5193  PGresult *res;
5194  printQueryOpt myopt = pset.popt;
5195  static const bool translate_columns[] = {false, false, false, false, false, false, false};
5196 
5197  if (pset.sversion < 100000)
5198  {
5199  char sverbuf[32];
5200 
5201  psql_error("The server (version %s) does not support publications.\n",
5203  sverbuf, sizeof(sverbuf)));
5204  return true;
5205  }
5206 
5207  initPQExpBuffer(&buf);
5208 
5209  printfPQExpBuffer(&buf,
5210  "SELECT pubname AS \"%s\",\n"
5211  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5212  " puballtables AS \"%s\",\n"
5213  " pubinsert AS \"%s\",\n"
5214  " pubupdate AS \"%s\",\n"
5215  " pubdelete AS \"%s\"",
5216  gettext_noop("Name"),
5217  gettext_noop("Owner"),
5218  gettext_noop("All tables"),
5219  gettext_noop("Inserts"),
5220  gettext_noop("Updates"),
5221  gettext_noop("Deletes"));
5222  if (pset.sversion >= 110000)
5223  appendPQExpBuffer(&buf,
5224  ",\n pubtruncate AS \"%s\"",
5225  gettext_noop("Truncates"));
5226 
5227  appendPQExpBufferStr(&buf,
5228  "\nFROM pg_catalog.pg_publication\n");
5229 
5230  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5231  NULL, "pubname", NULL,
5232  NULL);
5233 
5234  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5235 
5236  res = PSQLexec(buf.data);
5237  termPQExpBuffer(&buf);
5238  if (!res)
5239  return false;
5240 
5241  myopt.nullPrint = NULL;
5242  myopt.title = _("List of publications");
5243  myopt.translate_header = true;
5244  myopt.translate_columns = translate_columns;
5245  myopt.n_translate_columns = lengthof(translate_columns);
5246 
5247  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5248 
5249  PQclear(res);
5250 
5251  return true;
5252 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listSchemas()

bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 4064 of file describe.c.

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

Referenced by exec_command_d().

4065 {
4067  PGresult *res;
4068  printQueryOpt myopt = pset.popt;
4069 
4070  initPQExpBuffer(&buf);
4071  printfPQExpBuffer(&buf,
4072  "SELECT n.nspname AS \"%s\",\n"
4073  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4074  gettext_noop("Name"),
4075  gettext_noop("Owner"));
4076 
4077  if (verbose)
4078  {
4079  appendPQExpBufferStr(&buf, ",\n ");
4080  printACLColumn(&buf, "n.nspacl");
4081  appendPQExpBuffer(&buf,
4082  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4083  gettext_noop("Description"));
4084  }
4085 
4086  appendPQExpBuffer(&buf,
4087  "\nFROM pg_catalog.pg_namespace n\n");
4088 
4089  if (!showSystem && !pattern)
4090  appendPQExpBufferStr(&buf,
4091  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
4092 
4093  processSQLNamePattern(pset.db, &buf, pattern,
4094  !showSystem && !pattern, false,
4095  NULL, "n.nspname", NULL,
4096  NULL);
4097 
4098  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4099 
4100  res = PSQLexec(buf.data);
4101  termPQExpBuffer(&buf);
4102  if (!res)
4103  return false;
4104 
4105  myopt.nullPrint = NULL;
4106  myopt.title = _("List of schemas");
4107  myopt.translate_header = true;
4108 
4109  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4110 
4111  PQclear(res);
4112  return true;
4113 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5493
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTables()

bool listTables ( const char *  tabtypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3412 of file describe.c.

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

Referenced by exec_command_d().

3413 {
3414  bool showTables = strchr(tabtypes, 't') != NULL;
3415  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3416  bool showViews = strchr(tabtypes, 'v') != NULL;
3417  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3418  bool showSeq = strchr(tabtypes, 's') != NULL;
3419  bool showForeign = strchr(tabtypes, 'E') != NULL;
3420 
3422  PGresult *res;
3423  printQueryOpt myopt = pset.popt;
3424  static const bool translate_columns[] = {false, false, true, false, false, false, false};
3425 
3426  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3427  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3428  showTables = showViews = showMatViews = showSeq = showForeign = true;
3429 
3430  initPQExpBuffer(&buf);
3431 
3432  /*
3433  * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
3434  * it here for backwards compatibility.
3435  */
3436  printfPQExpBuffer(&buf,
3437  "SELECT n.nspname as \"%s\",\n"
3438  " c.relname as \"%s\",\n"
3439  " CASE c.relkind"
3440  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3441  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3442  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3443  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3444  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3445  " WHEN 's' THEN '%s'"
3446  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3447  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3448  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
3449  " END as \"%s\",\n"
3450  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3451  gettext_noop("Schema"),
3452  gettext_noop("Name"),
3453  gettext_noop("table"),
3454  gettext_noop("view"),
3455  gettext_noop("materialized view"),
3456  gettext_noop("index"),
3457  gettext_noop("sequence"),
3458  gettext_noop("special"),
3459  gettext_noop("foreign table"),
3460  gettext_noop("table"), /* partitioned table */
3461  gettext_noop("index"), /* partitioned index */
3462  gettext_noop("Type"),
3463  gettext_noop("Owner"));
3464 
3465  if (showIndexes)
3466  appendPQExpBuffer(&buf,
3467  ",\n c2.relname as \"%s\"",
3468  gettext_noop("Table"));
3469 
3470  if (verbose)
3471  {
3472  /*
3473  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3474  * size of a table, including FSM, VM and TOAST tables.
3475  */
3476  if (pset.sversion >= 90000)
3477  appendPQExpBuffer(&buf,
3478  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3479  gettext_noop("Size"));
3480  else if (pset.sversion >= 80100)
3481  appendPQExpBuffer(&buf,
3482  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3483  gettext_noop("Size"));
3484 
3485  appendPQExpBuffer(&buf,
3486  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3487  gettext_noop("Description"));
3488  }
3489 
3490  appendPQExpBufferStr(&buf,
3491  "\nFROM pg_catalog.pg_class c"
3492  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3493  if (showIndexes)
3494  appendPQExpBufferStr(&buf,
3495  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3496  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3497 
3498  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3499  if (showTables)
3500  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
3501  CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
3502  if (showViews)
3503  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
3504  if (showMatViews)
3505  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_MATVIEW) ",");
3506  if (showIndexes)
3507  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_INDEX) ","
3508  CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
3509  if (showSeq)
3510  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ",");
3511  if (showSystem || pattern)
3512  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3513  if (showForeign)
3514  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ",");
3515 
3516  appendPQExpBufferStr(&buf, "''"); /* dummy */
3517  appendPQExpBufferStr(&buf, ")\n");
3518 
3519  if (!showSystem && !pattern)
3520  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3521  " AND n.nspname <> 'information_schema'\n");
3522 
3523  /*
3524  * TOAST objects are suppressed unconditionally. Since we don't provide
3525  * any way to select RELKIND_TOASTVALUE above, we would never show toast
3526  * tables in any case; it seems a bit confusing to allow their indexes to
3527  * be shown. Use plain \d if you really need to look at a TOAST
3528  * table/index.
3529  */
3530  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3531 
3532  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3533  "n.nspname", "c.relname", NULL,
3534  "pg_catalog.pg_table_is_visible(c.oid)");
3535 
3536  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3537 
3538  res = PSQLexec(buf.data);
3539  termPQExpBuffer(&buf);
3540  if (!res)
3541  return false;
3542 
3543  /*
3544  * Most functions in this file are content to print an empty table when
3545  * there are no matching objects. We intentionally deviate from that
3546  * here, but only in !quiet mode, for historical reasons.
3547  */
3548  if (PQntuples(res) == 0 && !pset.quiet)
3549  {
3550  if (pattern)
3551  psql_error("Did not find any relation named \"%s\".\n",
3552  pattern);
3553  else
3554  psql_error("Did not find any relations.\n");
3555  }
3556  else
3557  {
3558  myopt.nullPrint = NULL;
3559  myopt.title = _("List of relations");
3560  myopt.translate_header = true;
3561  myopt.translate_columns = translate_columns;
3562  myopt.n_translate_columns = lengthof(translate_columns);
3563 
3564  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3565  }
3566 
3567  PQclear(res);
3568  return true;
3569 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
#define CppAsString2(x)
Definition: c.h:224
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSConfigs()

bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

Definition at line 4510 of file describe.c.

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

Referenced by exec_command_d().

4511 {
4513  PGresult *res;
4514  printQueryOpt myopt = pset.popt;
4515 
4516  if (pset.sversion < 80300)
4517  {
4518  char sverbuf[32];
4519 
4520  psql_error("The server (version %s) does not support full text search.\n",
4522  sverbuf, sizeof(sverbuf)));
4523  return true;
4524  }
4525 
4526  if (verbose)
4527  return listTSConfigsVerbose(pattern);
4528 
4529  initPQExpBuffer(&buf);
4530 
4531  printfPQExpBuffer(&buf,
4532  "SELECT\n"
4533  " n.nspname as \"%s\",\n"
4534  " c.cfgname as \"%s\",\n"
4535  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4536  "FROM pg_catalog.pg_ts_config c\n"
4537  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
4538  gettext_noop("Schema"),
4539  gettext_noop("Name"),
4540  gettext_noop("Description")
4541  );
4542 
4543  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4544  "n.nspname", "c.cfgname", NULL,
4545  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4546 
4547  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4548 
4549  res = PSQLexec(buf.data);
4550  termPQExpBuffer(&buf);
4551  if (!res)
4552  return false;
4553 
4554  myopt.nullPrint = NULL;
4555  myopt.title = _("List of text search configurations");
4556  myopt.translate_header = true;
4557 
4558  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4559 
4560  PQclear(res);
4561  return true;
4562 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:4565
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSDictionaries()

bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 4368 of file describe.c.

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

Referenced by exec_command_d().

4369 {
4371  PGresult *res;
4372  printQueryOpt myopt = pset.popt;
4373 
4374  if (pset.sversion < 80300)
4375  {
4376  char sverbuf[32];
4377 
4378  psql_error("The server (version %s) does not support full text search.\n",
4380  sverbuf, sizeof(sverbuf)));
4381  return true;
4382  }
4383 
4384  initPQExpBuffer(&buf);
4385 
4386  printfPQExpBuffer(&buf,
4387  "SELECT\n"
4388  " n.nspname as \"%s\",\n"
4389  " d.dictname as \"%s\",\n",
4390  gettext_noop("Schema"),
4391  gettext_noop("Name"));
4392 
4393  if (verbose)
4394  {
4395  appendPQExpBuffer(&buf,
4396  " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
4397  " pg_catalog.pg_ts_template t\n"
4398  " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
4399  " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
4400  " d.dictinitoption as \"%s\",\n",
4401  gettext_noop("Template"),
4402  gettext_noop("Init options"));
4403  }
4404 
4405  appendPQExpBuffer(&buf,
4406  " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
4407  gettext_noop("Description"));
4408 
4409  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
4410  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
4411 
4412  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4413  "n.nspname", "d.dictname", NULL,
4414  "pg_catalog.pg_ts_dict_is_visible(d.oid)");
4415 
4416  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4417 
4418  res = PSQLexec(buf.data);
4419  termPQExpBuffer(&buf);
4420  if (!res)
4421  return false;
4422 
4423  myopt.nullPrint = NULL;
4424  myopt.title = _("List of text search dictionaries");
4425  myopt.translate_header = true;
4426 
4427  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4428 
4429  PQclear(res);
4430  return true;
4431 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSParsers()

bool listTSParsers ( const char *  pattern,
bool  verbose 
)

Definition at line 4121 of file describe.c.

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

Referenced by exec_command_d().

4122 {
4124  PGresult *res;
4125  printQueryOpt myopt = pset.popt;
4126 
4127  if (pset.sversion < 80300)
4128  {
4129  char sverbuf[32];
4130 
4131  psql_error("The server (version %s) does not support full text search.\n",
4133  sverbuf, sizeof(sverbuf)));
4134  return true;
4135  }
4136 
4137  if (verbose)
4138  return listTSParsersVerbose(pattern);
4139 
4140  initPQExpBuffer(&buf);
4141 
4142  printfPQExpBuffer(&buf,
4143  "SELECT\n"
4144  " n.nspname as \"%s\",\n"
4145  " p.prsname as \"%s\",\n"
4146  " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
4147  "FROM pg_catalog.pg_ts_parser p\n"
4148  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
4149  gettext_noop("Schema"),
4150  gettext_noop("Name"),
4151  gettext_noop("Description")
4152  );
4153 
4154  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4155  "n.nspname", "p.prsname", NULL,
4156  "pg_catalog.pg_ts_parser_is_visible(p.oid)");
4157 
4158  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4159 
4160  res = PSQLexec(buf.data);
4161  termPQExpBuffer(&buf);
4162  if (!res)
4163  return false;
4164 
4165  myopt.nullPrint = NULL;
4166  myopt.title = _("List of text search parsers");
4167  myopt.translate_header = true;
4168 
4169  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4170 
4171  PQclear(res);
4172  return true;
4173 }
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:4179
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listTSTemplates()

bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

Definition at line 4439 of file describe.c.

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

Referenced by exec_command_d().

4440 {
4442  PGresult *res;
4443  printQueryOpt myopt = pset.popt;
4444 
4445  if (pset.sversion < 80300)
4446  {
4447  char sverbuf[32];
4448 
4449  psql_error("The server (version %s) does not support full text search.\n",
4451  sverbuf, sizeof(sverbuf)));
4452  return true;
4453  }
4454 
4455  initPQExpBuffer(&buf);
4456 
4457  if (verbose)
4458  printfPQExpBuffer(&buf,
4459  "SELECT\n"
4460  " n.nspname AS \"%s\",\n"
4461  " t.tmplname AS \"%s\",\n"
4462  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4463  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4464  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4465  gettext_noop("Schema"),
4466  gettext_noop("Name"),
4467  gettext_noop("Init"),
4468  gettext_noop("Lexize"),
4469  gettext_noop("Description"));
4470  else
4471  printfPQExpBuffer(&buf,
4472  "SELECT\n"
4473  " n.nspname AS \"%s\",\n"
4474  " t.tmplname AS \"%s\",\n"
4475  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4476  gettext_noop("Schema"),
4477  gettext_noop("Name"),
4478  gettext_noop("Description"));
4479 
4480  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4481  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4482 
4483  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4484  "n.nspname", "t.tmplname", NULL,
4485  "pg_catalog.pg_ts_template_is_visible(t.oid)");
4486 
4487  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4488 
4489  res = PSQLexec(buf.data);
4490  termPQExpBuffer(&buf);
4491  if (!res)
4492  return false;
4493 
4494  myopt.nullPrint = NULL;
4495  myopt.title = _("List of text search templates");
4496  myopt.translate_header = true;
4497 
4498  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4499 
4500  PQclear(res);
4501  return true;
4502 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ listUserMappings()

bool listUserMappings ( const char *  pattern,
bool  verbose 
)

Definition at line 4881 of file describe.c.

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

Referenced by exec_command_d().

4882 {
4884  PGresult *res;
4885  printQueryOpt myopt = pset.popt;
4886 
4887  if (pset.sversion < 80400)
4888  {
4889  char sverbuf[32];
4890 
4891  psql_error("The server (version %s) does not support user mappings.\n",
4893  sverbuf, sizeof(sverbuf)));
4894  return true;
4895  }
4896 
4897  initPQExpBuffer(&buf);
4898  printfPQExpBuffer(&buf,
4899  "SELECT um.srvname AS \"%s\",\n"
4900  " um.usename AS \"%s\"",
4901  gettext_noop("Server"),
4902  gettext_noop("User name"));
4903 
4904  if (verbose)
4905  appendPQExpBuffer(&buf,
4906  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4907  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4908  " pg_catalog.quote_ident(option_name) || ' ' || "
4909  " pg_catalog.quote_literal(option_value) FROM "
4910  " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
4911  " END AS \"%s\"",
4912  gettext_noop("FDW options"));
4913 
4914  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4915 
4916  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4917  NULL, "um.srvname", "um.usename", NULL);
4918 
4919  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4920 
4921  res = PSQLexec(buf.data);
4922  termPQExpBuffer(&buf);
4923  if (!res)
4924  return false;
4925 
4926  myopt.nullPrint = NULL;
4927  myopt.title = _("List of user mappings");
4928  myopt.translate_header = true;
4929 
4930  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4931 
4932  PQclear(res);
4933  return true;
4934 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:88
void psql_error(const char *fmt,...)
Definition: common.c:221
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ objectDescription()

bool objectDescription ( const char *  pattern,
bool  showSystem 
)

Definition at line 1138 of file describe.c.

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

Referenced by exec_command_d().

1139 {
1141  PGresult *res;
1142  printQueryOpt myopt = pset.popt;
1143  static const bool translate_columns[] = {false, false, true, false};
1144 
1145  initPQExpBuffer(&buf);
1146 
1147  appendPQExpBuffer(&buf,
1148  "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1149  "FROM (\n",
1150  gettext_noop("Schema"),
1151  gettext_noop("Name"),
1152  gettext_noop("Object"),
1153  gettext_noop("Description"));
1154 
1155  /* Table constraint descriptions */
1156  appendPQExpBuffer(&buf,
1157  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1158  " n.nspname as nspname,\n"
1159  " CAST(pgc.conname AS pg_catalog.text) as name,"
1160  " CAST('%s' AS pg_catalog.text) as object\n"
1161  " FROM pg_catalog.pg_constraint pgc\n"
1162  " JOIN pg_catalog.pg_class c "
1163  "ON c.oid = pgc.conrelid\n"
1164  " LEFT JOIN pg_catalog.pg_namespace n "
1165  " ON n.oid = c.relnamespace\n",
1166  gettext_noop("table constraint"));
1167 
1168  if (!showSystem && !pattern)
1169  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1170  " AND n.nspname <> 'information_schema'\n");
1171 
1172  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
1173  false, "n.nspname", "pgc.conname", NULL,
1174  "pg_catalog.pg_table_is_visible(c.oid)");
1175 
1176  /* Domain constraint descriptions */
1177  appendPQExpBuffer(&buf,
1178  "UNION ALL\n"
1179  " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1180  " n.nspname as nspname,\n"
1181  " CAST(pgc.conname AS pg_catalog.text) as name,"
1182  " CAST('%s' AS pg_catalog.text) as object\n"
1183  " FROM pg_catalog.pg_constraint pgc\n"
1184  " JOIN pg_catalog.pg_type t "
1185  "ON t.oid = pgc.contypid\n"
1186  " LEFT JOIN pg_catalog.pg_namespace n "
1187  " ON n.oid = t.typnamespace\n",
1188  gettext_noop("domain constraint"));
1189 
1190  if (!showSystem && !pattern)
1191  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1192  " AND n.nspname <> 'information_schema'\n");
1193 
1194  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
1195  false, "n.nspname", "pgc.conname", NULL,
1196  "pg_catalog.pg_type_is_visible(t.oid)");
1197 
1198 
1199  /*
1200  * pg_opclass.opcmethod only available in 8.3+
1201  */
1202  if (pset.sversion >= 80300)
1203  {
1204  /* Operator class descriptions */
1205  appendPQExpBuffer(&buf,
1206  "UNION ALL\n"
1207  " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1208  " n.nspname as nspname,\n"
1209  " CAST(o.opcname AS pg_catalog.text) as name,\n"
1210  " CAST('%s' AS pg_catalog.text) as object\n"
1211  " FROM pg_catalog.pg_opclass o\n"
1212  " JOIN pg_catalog.pg_am am ON "
1213  "o.opcmethod = am.oid\n"
1214  " JOIN pg_catalog.pg_namespace n ON "
1215  "n.oid = o.opcnamespace\n",
1216  gettext_noop("operator class"));
1217 
1218  if (!showSystem && !pattern)
1219  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1220  " AND n.nspname <> 'information_schema'\n");
1221 
1222  processSQLNamePattern(pset.db, &buf, pattern, true, false,
1223  "n.nspname", "o.opcname", NULL,
1224  "pg_catalog.pg_opclass_is_visible(o.oid)");
1225  }
1226 
1227  /*
1228  * although operator family comments have been around since 8.3,
1229  * pg_opfamily_is_visible is only available in 9.2+
1230  */
1231  if (pset.sversion >= 90200)
1232  {
1233  /* Operator family descriptions */
1234  appendPQExpBuffer(&buf,
1235  "UNION ALL\n"
1236  " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1237  " n.nspname as nspname,\n"
1238  " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1239  " CAST('%s' AS pg_catalog.text) as object\n"
1240  " FROM pg_catalog.pg_opfamily opf\n"
1241  " JOIN pg_catalog.pg_am am "
1242  "ON opf.opfmethod = am.oid\n"
1243  " JOIN pg_catalog.pg_namespace n "
1244  "ON opf.opfnamespace = n.oid\n",
1245  gettext_noop("operator family"));
1246 
1247  if (!showSystem && !pattern)
1248  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1249  " AND n.nspname <> 'information_schema'\n");
1250 
1251  processSQLNamePattern(pset.db, &buf, pattern, true, false,
1252  "n.nspname", "opf.opfname", NULL,
1253  "pg_catalog.pg_opfamily_is_visible(opf.oid)");
1254  }
1255 
1256  /* Rule descriptions (ignore rules for views) */
1257  appendPQExpBuffer(&buf,
1258  "UNION ALL\n"
1259  " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1260  " n.nspname as nspname,\n"
1261  " CAST(r.rulename AS pg_catalog.text) as name,"
1262  " CAST('%s' AS pg_catalog.text) as object\n"
1263  " FROM pg_catalog.pg_rewrite r\n"
1264  " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1265  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1266  " WHERE r.rulename != '_RETURN'\n",
1267  gettext_noop("rule"));
1268 
1269  if (!showSystem && !pattern)
1270  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1271  " AND n.nspname <> 'information_schema'\n");
1272 
1273  processSQLNamePattern(pset.db, &buf, pattern, true, false,
1274  "n.nspname", "r.rulename", NULL,
1275  "pg_catalog.pg_table_is_visible(c.oid)");
1276 
1277  /* Trigger descriptions */
1278  appendPQExpBuffer(&buf,
1279  "UNION ALL\n"
1280  " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1281  " n.nspname as nspname,\n"
1282  " CAST(t.tgname AS pg_catalog.text) as name,"
1283  " CAST('%s' AS pg_catalog.text) as object\n"
1284  " FROM pg_catalog.pg_trigger t\n"
1285  " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1286  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1287  gettext_noop("trigger"));
1288 
1289  if (!showSystem && !pattern)
1290  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1291  " AND n.nspname <> 'information_schema'\n");
1292 
1293  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1294  "n.nspname", "t.tgname", NULL,
1295  "pg_catalog.pg_table_is_visible(c.oid)");
1296 
1297  appendPQExpBufferStr(&buf,
1298  ") AS tt\n"
1299  " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1300 
1301  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1302 
1303  res = PSQLexec(buf.data);
1304  termPQExpBuffer(&buf);
1305  if (!res)
1306  return false;
1307 
1308  myopt.nullPrint = NULL;
1309  myopt.title = _("Object descriptions");
1310  myopt.translate_header = true;
1311  myopt.translate_columns = translate_columns;
1312  myopt.n_translate_columns = lengthof(translate_columns);
1313 
1314  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1315 
1316  PQclear(res);
1317  return true;
1318 }
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:1036
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:629
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:169
FILE * logfile
Definition: settings.h:115
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * title
Definition: print.h:167
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3287
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:690

◆ permissionsList()

bool permissionsList ( const char *  pattern)

Definition at line 893 of file describe.c.

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

Referenced by exec_command_d(), and exec_command_z().

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