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

Go to the source code of this file.

Functions

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

Function Documentation

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 140 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 62 of file describe.c.

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

Referenced by exec_command_d().

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  appendPQExpBuffer(&buf,
104  " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
105  "FROM pg_catalog.pg_proc p\n"
106  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
107  "WHERE p.proisagg\n",
108  gettext_noop("Description"));
109 
110  if (!showSystem && !pattern)
111  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
112  " AND n.nspname <> 'information_schema'\n");
113 
114  processSQLNamePattern(pset.db, &buf, pattern, true, false,
115  "n.nspname", "p.proname", NULL,
116  "pg_catalog.pg_function_is_visible(p.oid)");
117 
118  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
119 
120  res = PSQLexec(buf.data);
121  termPQExpBuffer(&buf);
122  if (!res)
123  return false;
124 
125  myopt.nullPrint = NULL;
126  myopt.title = _("List of aggregate functions");
127  myopt.translate_header = true;
128 
129  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
130 
131  PQclear(res);
132  return true;
133 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool describeFunctions ( const char *  functypes,
const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 303 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 708 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 5146 of file describe.c.

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

Referenced by exec_command_d().

5147 {
5149  int i;
5150  PGresult *res;
5151 
5152  if (pset.sversion < 100000)
5153  {
5154  char sverbuf[32];
5155 
5156  psql_error("The server (version %s) does not support publications.\n",
5158  sverbuf, sizeof(sverbuf)));
5159  return true;
5160  }
5161 
5162  initPQExpBuffer(&buf);
5163 
5164  printfPQExpBuffer(&buf,
5165  "SELECT oid, pubname,\n"
5166  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
5167  " puballtables, pubinsert, pubupdate, pubdelete\n"
5168  "FROM pg_catalog.pg_publication\n");
5169 
5170  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5171  NULL, "pubname", NULL,
5172  NULL);
5173 
5174  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5175 
5176  res = PSQLexec(buf.data);
5177  if (!res)
5178  {
5179  termPQExpBuffer(&buf);
5180  return false;
5181  }
5182 
5183  if (PQntuples(res) == 0)
5184  {
5185  if (!pset.quiet)
5186  {
5187  if (pattern)
5188  psql_error("Did not find any publication named \"%s\".\n",
5189  pattern);
5190  else
5191  psql_error("Did not find any publications.\n");
5192  }
5193 
5194  termPQExpBuffer(&buf);
5195  PQclear(res);
5196  return false;
5197  }
5198 
5199  for (i = 0; i < PQntuples(res); i++)
5200  {
5201  const char align = 'l';
5202  int ncols = 5;
5203  int nrows = 1;
5204  int tables = 0;
5205  PGresult *tabres;
5206  char *pubid = PQgetvalue(res, i, 0);
5207  char *pubname = PQgetvalue(res, i, 1);
5208  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
5209  int j;
5210  PQExpBufferData title;
5211  printTableOpt myopt = pset.popt.topt;
5212  printTableContent cont;
5213 
5214  initPQExpBuffer(&title);
5215  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5216  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5217 
5218  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
5219  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
5220  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5221  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5222  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5223 
5224  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
5225  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5226  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5227  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5228  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
5229 
5230  if (!puballtables)
5231  {
5232  printfPQExpBuffer(&buf,
5233  "SELECT n.nspname, c.relname\n"
5234  "FROM pg_catalog.pg_class c,\n"
5235  " pg_catalog.pg_namespace n,\n"
5236  " pg_catalog.pg_publication_rel pr\n"
5237  "WHERE c.relnamespace = n.oid\n"
5238  " AND c.oid = pr.prrelid\n"
5239  " AND pr.prpubid = '%s'\n"
5240  "ORDER BY 1,2", pubid);
5241 
5242  tabres = PSQLexec(buf.data);
5243  if (!tabres)
5244  {
5245  printTableCleanup(&cont);
5246  PQclear(res);
5247  termPQExpBuffer(&buf);
5248  termPQExpBuffer(&title);
5249  return false;
5250  }
5251  else
5252  tables = PQntuples(tabres);
5253 
5254  if (tables > 0)
5255  printTableAddFooter(&cont, _("Tables:"));
5256 
5257  for (j = 0; j < tables; j++)
5258  {
5259  printfPQExpBuffer(&buf, " \"%s.%s\"",
5260  PQgetvalue(tabres, j, 0),
5261  PQgetvalue(tabres, j, 1));
5262 
5263  printTableAddFooter(&cont, buf.data);
5264  }
5265  PQclear(tabres);
5266  }
5267 
5268  printTable(&cont, pset.queryFout, false, pset.logfile);
5269  printTableCleanup(&cont);
5270 
5271  termPQExpBuffer(&title);
5272  }
5273 
5274  termPQExpBuffer(&buf);
5275  PQclear(res);
5276 
5277  return true;
5278 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
void printTableCleanup(printTableContent *const content)
Definition: print.c:3099
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
printTableOpt topt
Definition: print.h:165
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:2968
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3008
static char * buf
Definition: pg_test_fsync.c:66
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3188
void psql_error(const char *fmt,...)
Definition: common.c:220
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3056
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:2931
int i
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool describeRoles ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3049 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 5287 of file describe.c.

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

Referenced by exec_command_d().

5288 {
5290  PGresult *res;
5291  printQueryOpt myopt = pset.popt;
5292  static const bool translate_columns[] = {false, false, false, false,
5293  false, false};
5294 
5295  if (pset.sversion < 100000)
5296  {
5297  char sverbuf[32];
5298 
5299  psql_error("The server (version %s) does not support subscriptions.\n",
5301  sverbuf, sizeof(sverbuf)));
5302  return true;
5303  }
5304 
5305  initPQExpBuffer(&buf);
5306 
5307  printfPQExpBuffer(&buf,
5308  "SELECT subname AS \"%s\"\n"
5309  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5310  ", subenabled AS \"%s\"\n"
5311  ", subpublications AS \"%s\"\n",
5312  gettext_noop("Name"),
5313  gettext_noop("Owner"),
5314  gettext_noop("Enabled"),
5315  gettext_noop("Publication"));
5316 
5317  if (verbose)
5318  {
5319  appendPQExpBuffer(&buf,
5320  ", subsynccommit AS \"%s\"\n"
5321  ", subconninfo AS \"%s\"\n",
5322  gettext_noop("Synchronous commit"),
5323  gettext_noop("Conninfo"));
5324  }
5325 
5326  /* Only display subscriptions in current database. */
5327  appendPQExpBufferStr(&buf,
5328  "FROM pg_catalog.pg_subscription\n"
5329  "WHERE subdbid = (SELECT oid\n"
5330  " FROM pg_catalog.pg_database\n"
5331  " WHERE datname = current_database())");
5332 
5333  processSQLNamePattern(pset.db, &buf, pattern, true, false,
5334  NULL, "subname", NULL,
5335  NULL);
5336 
5337  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5338 
5339  res = PSQLexec(buf.data);
5340  termPQExpBuffer(&buf);
5341  if (!res)
5342  return false;
5343 
5344  myopt.nullPrint = NULL;
5345  myopt.title = _("List of subscriptions");
5346  myopt.translate_header = true;
5347  myopt.translate_columns = translate_columns;
5348  myopt.n_translate_columns = lengthof(translate_columns);
5349 
5350  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5351 
5352  PQclear(res);
5353  return true;
5354 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:562
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool describeTableDetails ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 1292 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 208 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 592 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 785 of file describe.c.

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

Referenced by exec_command_list(), and main().

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

Definition at line 3770 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3869 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3628 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3220 of file describe.c.

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

3221 {
3223  PGresult *res;
3224  printQueryOpt myopt = pset.popt;
3225  bool havewhere;
3226 
3227  if (pset.sversion < 90000)
3228  {
3229  char sverbuf[32];
3230 
3231  psql_error("The server (version %s) does not support per-database role settings.\n",
3233  sverbuf, sizeof(sverbuf)));
3234  return true;
3235  }
3236 
3237  initPQExpBuffer(&buf);
3238 
3239  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3240  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3241  "FROM pg_catalog.pg_db_role_setting s\n"
3242  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3243  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3244  gettext_noop("Role"),
3245  gettext_noop("Database"),
3246  gettext_noop("Settings"));
3247  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3248  NULL, "r.rolname", NULL, NULL);
3249  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3250  NULL, "d.datname", NULL, NULL);
3251  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3252 
3253  res = PSQLexec(buf.data);
3254  termPQExpBuffer(&buf);
3255  if (!res)
3256  return false;
3257 
3258  /*
3259  * Most functions in this file are content to print an empty table when
3260  * there are no matching objects. We intentionally deviate from that
3261  * here, but only in !quiet mode, because of the possibility that the user
3262  * is confused about what the two pattern arguments mean.
3263  */
3264  if (PQntuples(res) == 0 && !pset.quiet)
3265  {
3266  if (pattern && pattern2)
3267  psql_error("Did not find any settings for role \"%s\" and database \"%s\".\n",
3268  pattern, pattern2);
3269  else if (pattern)
3270  psql_error("Did not find any settings for role \"%s\".\n",
3271  pattern);
3272  else
3273  psql_error("Did not find any settings.\n");
3274  }
3275  else
3276  {
3277  myopt.nullPrint = NULL;
3278  myopt.title = _("List of settings");
3279  myopt.translate_header = true;
3280 
3281  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3282  }
3283 
3284  PQclear(res);
3285  return true;
3286 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listDefaultACLs ( const char *  pattern)

Definition at line 1015 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3542 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3704 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4966 of file describe.c.

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

Referenced by exec_command_d().

4967 {
4969  PGresult *res;
4970  int i;
4971 
4972  if (pset.sversion < 90100)
4973  {
4974  char sverbuf[32];
4975 
4976  psql_error("The server (version %s) does not support extensions.\n",
4978  sverbuf, sizeof(sverbuf)));
4979  return true;
4980  }
4981 
4982  initPQExpBuffer(&buf);
4983  printfPQExpBuffer(&buf,
4984  "SELECT e.extname, e.oid\n"
4985  "FROM pg_catalog.pg_extension e\n");
4986 
4987  processSQLNamePattern(pset.db, &buf, pattern,
4988  false, false,
4989  NULL, "e.extname", NULL,
4990  NULL);
4991 
4992  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4993 
4994  res = PSQLexec(buf.data);
4995  termPQExpBuffer(&buf);
4996  if (!res)
4997  return false;
4998 
4999  if (PQntuples(res) == 0)
5000  {
5001  if (!pset.quiet)
5002  {
5003  if (pattern)
5004  psql_error("Did not find any extension named \"%s\".\n",
5005  pattern);
5006  else
5007  psql_error("Did not find any extensions.\n");
5008  }
5009  PQclear(res);
5010  return false;
5011  }
5012 
5013  for (i = 0; i < PQntuples(res); i++)
5014  {
5015  const char *extname;
5016  const char *oid;
5017 
5018  extname = PQgetvalue(res, i, 0);
5019  oid = PQgetvalue(res, i, 1);
5020 
5021  if (!listOneExtensionContents(extname, oid))
5022  {
5023  PQclear(res);
5024  return false;
5025  }
5026  if (cancel_pressed)
5027  {
5028  PQclear(res);
5029  return false;
5030  }
5031  }
5032 
5033  PQclear(res);
5034  return true;
5035 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
PsqlSettings pset
Definition: startup.c:33
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
volatile bool cancel_pressed
Definition: print.c:46
static char * buf
Definition: pg_test_fsync.c:66
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5038
void psql_error(const char *fmt,...)
Definition: common.c:220
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listExtensions ( const char *  pattern)

Definition at line 4909 of file describe.c.

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

Referenced by exec_command_d().

4910 {
4912  PGresult *res;
4913  printQueryOpt myopt = pset.popt;
4914 
4915  if (pset.sversion < 90100)
4916  {
4917  char sverbuf[32];
4918 
4919  psql_error("The server (version %s) does not support extensions.\n",
4921  sverbuf, sizeof(sverbuf)));
4922  return true;
4923  }
4924 
4925  initPQExpBuffer(&buf);
4926  printfPQExpBuffer(&buf,
4927  "SELECT e.extname AS \"%s\", "
4928  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4929  "FROM pg_catalog.pg_extension e "
4930  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4931  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4932  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4933  gettext_noop("Name"),
4934  gettext_noop("Version"),
4935  gettext_noop("Schema"),
4936  gettext_noop("Description"));
4937 
4938  processSQLNamePattern(pset.db, &buf, pattern,
4939  false, false,
4940  NULL, "e.extname", NULL,
4941  NULL);
4942 
4943  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4944 
4945  res = PSQLexec(buf.data);
4946  termPQExpBuffer(&buf);
4947  if (!res)
4948  return false;
4949 
4950  myopt.nullPrint = NULL;
4951  myopt.title = _("List of installed extensions");
4952  myopt.translate_header = true;
4953 
4954  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4955 
4956  PQclear(res);
4957  return true;
4958 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 4605 of file describe.c.

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

Referenced by exec_command_d().

4606 {
4608  PGresult *res;
4609  printQueryOpt myopt = pset.popt;
4610 
4611  if (pset.sversion < 80400)
4612  {
4613  char sverbuf[32];
4614 
4615  psql_error("The server (version %s) does not support foreign-data wrappers.\n",
4617  sverbuf, sizeof(sverbuf)));
4618  return true;
4619  }
4620 
4621  initPQExpBuffer(&buf);
4622  printfPQExpBuffer(&buf,
4623  "SELECT fdw.fdwname AS \"%s\",\n"
4624  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4625  gettext_noop("Name"),
4626  gettext_noop("Owner"));
4627  if (pset.sversion >= 90100)
4628  appendPQExpBuffer(&buf,
4629  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4630  gettext_noop("Handler"));
4631  appendPQExpBuffer(&buf,
4632  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4633  gettext_noop("Validator"));
4634 
4635  if (verbose)
4636  {
4637  appendPQExpBufferStr(&buf, ",\n ");
4638  printACLColumn(&buf, "fdwacl");
4639  appendPQExpBuffer(&buf,
4640  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4641  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4642  " pg_catalog.quote_ident(option_name) || ' ' || "
4643  " pg_catalog.quote_literal(option_value) FROM "
4644  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
4645  " END AS \"%s\"",
4646  gettext_noop("FDW options"));
4647 
4648  if (pset.sversion >= 90100)
4649  appendPQExpBuffer(&buf,
4650  ",\n d.description AS \"%s\" ",
4651  gettext_noop("Description"));
4652  }
4653 
4654  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4655 
4656  if (verbose && pset.sversion >= 90100)
4657  appendPQExpBufferStr(&buf,
4658  "LEFT JOIN pg_catalog.pg_description d\n"
4659  " ON d.classoid = fdw.tableoid "
4660  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4661 
4662  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4663  NULL, "fdwname", NULL, NULL);
4664 
4665  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4666 
4667  res = PSQLexec(buf.data);
4668  termPQExpBuffer(&buf);
4669  if (!res)
4670  return false;
4671 
4672  myopt.nullPrint = NULL;
4673  myopt.title = _("List of foreign-data wrappers");
4674  myopt.translate_header = true;
4675 
4676  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4677 
4678  PQclear(res);
4679  return true;
4680 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5364
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 4688 of file describe.c.

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

Referenced by exec_command_d().

4689 {
4691  PGresult *res;
4692  printQueryOpt myopt = pset.popt;
4693 
4694  if (pset.sversion < 80400)
4695  {
4696  char sverbuf[32];
4697 
4698  psql_error("The server (version %s) does not support foreign servers.\n",
4700  sverbuf, sizeof(sverbuf)));
4701  return true;
4702  }
4703 
4704  initPQExpBuffer(&buf);
4705  printfPQExpBuffer(&buf,
4706  "SELECT s.srvname AS \"%s\",\n"
4707  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4708  " f.fdwname AS \"%s\"",
4709  gettext_noop("Name"),
4710  gettext_noop("Owner"),
4711  gettext_noop("Foreign-data wrapper"));
4712 
4713  if (verbose)
4714  {
4715  appendPQExpBufferStr(&buf, ",\n ");
4716  printACLColumn(&buf, "s.srvacl");
4717  appendPQExpBuffer(&buf,
4718  ",\n"
4719  " s.srvtype AS \"%s\",\n"
4720  " s.srvversion AS \"%s\",\n"
4721  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4722  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4723  " pg_catalog.quote_ident(option_name) || ' ' || "
4724  " pg_catalog.quote_literal(option_value) FROM "
4725  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
4726  " END AS \"%s\",\n"
4727  " d.description AS \"%s\"",
4728  gettext_noop("Type"),
4729  gettext_noop("Version"),
4730  gettext_noop("FDW options"),
4731  gettext_noop("Description"));
4732  }
4733 
4734  appendPQExpBufferStr(&buf,
4735  "\nFROM pg_catalog.pg_foreign_server s\n"
4736  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4737 
4738  if (verbose)
4739  appendPQExpBufferStr(&buf,
4740  "LEFT JOIN pg_catalog.pg_description d\n "
4741  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4742  "AND d.objsubid = 0\n");
4743 
4744  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4745  NULL, "s.srvname", NULL, NULL);
4746 
4747  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4748 
4749  res = PSQLexec(buf.data);
4750  termPQExpBuffer(&buf);
4751  if (!res)
4752  return false;
4753 
4754  myopt.nullPrint = NULL;
4755  myopt.title = _("List of foreign servers");
4756  myopt.translate_header = true;
4757 
4758  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4759 
4760  PQclear(res);
4761  return true;
4762 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:5364
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 4831 of file describe.c.

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

Referenced by exec_command_d().

4832 {
4834  PGresult *res;
4835  printQueryOpt myopt = pset.popt;
4836 
4837  if (pset.sversion < 90100)
4838  {
4839  char sverbuf[32];
4840 
4841  psql_error("The server (version %s) does not support foreign tables.\n",
4843  sverbuf, sizeof(sverbuf)));
4844  return true;
4845  }
4846 
4847  initPQExpBuffer(&buf);
4848  printfPQExpBuffer(&buf,
4849  "SELECT n.nspname AS \"%s\",\n"
4850  " c.relname AS \"%s\",\n"
4851  " s.srvname AS \"%s\"",
4852  gettext_noop("Schema"),
4853  gettext_noop("Table"),
4854  gettext_noop("Server"));
4855 
4856  if (verbose)
4857  appendPQExpBuffer(&buf,
4858  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4859  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4860  " pg_catalog.quote_ident(option_name) || ' ' || "
4861  " pg_catalog.quote_literal(option_value) FROM "
4862  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
4863  " END AS \"%s\",\n"
4864  " d.description AS \"%s\"",
4865  gettext_noop("FDW options"),
4866  gettext_noop("Description"));
4867 
4868  appendPQExpBufferStr(&buf,
4869  "\nFROM pg_catalog.pg_foreign_table ft\n"
4870  " INNER JOIN pg_catalog.pg_class c"
4871  " ON c.oid = ft.ftrelid\n"
4872  " INNER JOIN pg_catalog.pg_namespace n"
4873  " ON n.oid = c.relnamespace\n"
4874  " INNER JOIN pg_catalog.pg_foreign_server s"
4875  " ON s.oid = ft.ftserver\n");
4876  if (verbose)
4877  appendPQExpBufferStr(&buf,
4878  " LEFT JOIN pg_catalog.pg_description d\n"
4879  " ON d.classoid = c.tableoid AND "
4880  "d.objoid = c.oid AND d.objsubid = 0\n");
4881 
4882  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4883  "n.nspname", "c.relname", NULL,
4884  "pg_catalog.pg_table_is_visible(c.oid)");
4885 
4886  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4887 
4888  res = PSQLexec(buf.data);
4889  termPQExpBuffer(&buf);
4890  if (!res)
4891  return false;
4892 
4893  myopt.nullPrint = NULL;
4894  myopt.title = _("List of foreign tables");
4895  myopt.translate_header = true;
4896 
4897  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4898 
4899  PQclear(res);
4900  return true;
4901 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listLanguages ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3467 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 5079 of file describe.c.

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

Referenced by exec_command_d().

5080 {
5082  PGresult *res;
5083  printQueryOpt myopt = pset.popt;
5084  static const bool translate_columns[] = {false, false, false, false, false, false};
5085 
5086  if (pset.sversion < 100000)
5087  {
5088  char sverbuf[32];
5089 
5090  psql_error("The server (version %s) does not support publications.\n",
5092  sverbuf, sizeof(sverbuf)));
5093  return true;
5094  }
5095 
5096  initPQExpBuffer(&buf);
5097 
5098  printfPQExpBuffer(&buf,
5099  "SELECT pubname AS \"%s\",\n"
5100  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5101  " puballtables AS \"%s\",\n"
5102  " pubinsert AS \"%s\",\n"
5103  " pubupdate AS \"%s\",\n"
5104  " pubdelete AS \"%s\"\n",
5105  gettext_noop("Name"),
5106  gettext_noop("Owner"),
5107  gettext_noop("All tables"),
5108  gettext_noop("Inserts"),
5109  gettext_noop("Updates"),
5110  gettext_noop("Deletes"));
5111 
5112  appendPQExpBufferStr(&buf,
5113  "\nFROM pg_catalog.pg_publication\n");
5114 
5115  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5116  NULL, "pubname", NULL,
5117  NULL);
5118 
5119  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5120 
5121  res = PSQLexec(buf.data);
5122  termPQExpBuffer(&buf);
5123  if (!res)
5124  return false;
5125 
5126  myopt.nullPrint = NULL;
5127  myopt.title = _("List of publications");
5128  myopt.translate_header = true;
5129  myopt.translate_columns = translate_columns;
5130  myopt.n_translate_columns = lengthof(translate_columns);
5131 
5132  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5133 
5134  PQclear(res);
5135 
5136  return true;
5137 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
#define lengthof(array)
Definition: c.h:562
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:172
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
const bool * translate_columns
Definition: print.h:170
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listSchemas ( const char *  pattern,
bool  verbose,
bool  showSystem 
)

Definition at line 3953 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 3304 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4399 of file describe.c.

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

Referenced by exec_command_d().

4400 {
4402  PGresult *res;
4403  printQueryOpt myopt = pset.popt;
4404 
4405  if (pset.sversion < 80300)
4406  {
4407  char sverbuf[32];
4408 
4409  psql_error("The server (version %s) does not support full text search.\n",
4411  sverbuf, sizeof(sverbuf)));
4412  return true;
4413  }
4414 
4415  if (verbose)
4416  return listTSConfigsVerbose(pattern);
4417 
4418  initPQExpBuffer(&buf);
4419 
4420  printfPQExpBuffer(&buf,
4421  "SELECT\n"
4422  " n.nspname as \"%s\",\n"
4423  " c.cfgname as \"%s\",\n"
4424  " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
4425  "FROM pg_catalog.pg_ts_config c\n"
4426  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
4427  gettext_noop("Schema"),
4428  gettext_noop("Name"),
4429  gettext_noop("Description")
4430  );
4431 
4432  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4433  "n.nspname", "c.cfgname", NULL,
4434  "pg_catalog.pg_ts_config_is_visible(c.oid)");
4435 
4436  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4437 
4438  res = PSQLexec(buf.data);
4439  termPQExpBuffer(&buf);
4440  if (!res)
4441  return false;
4442 
4443  myopt.nullPrint = NULL;
4444  myopt.title = _("List of text search configurations");
4445  myopt.translate_header = true;
4446 
4447  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4448 
4449  PQclear(res);
4450  return true;
4451 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:4454
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 4257 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4010 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 4328 of file describe.c.

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

Referenced by exec_command_d().

4329 {
4331  PGresult *res;
4332  printQueryOpt myopt = pset.popt;
4333 
4334  if (pset.sversion < 80300)
4335  {
4336  char sverbuf[32];
4337 
4338  psql_error("The server (version %s) does not support full text search.\n",
4340  sverbuf, sizeof(sverbuf)));
4341  return true;
4342  }
4343 
4344  initPQExpBuffer(&buf);
4345 
4346  if (verbose)
4347  printfPQExpBuffer(&buf,
4348  "SELECT\n"
4349  " n.nspname AS \"%s\",\n"
4350  " t.tmplname AS \"%s\",\n"
4351  " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
4352  " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
4353  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4354  gettext_noop("Schema"),
4355  gettext_noop("Name"),
4356  gettext_noop("Init"),
4357  gettext_noop("Lexize"),
4358  gettext_noop("Description"));
4359  else
4360  printfPQExpBuffer(&buf,
4361  "SELECT\n"
4362  " n.nspname AS \"%s\",\n"
4363  " t.tmplname AS \"%s\",\n"
4364  " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
4365  gettext_noop("Schema"),
4366  gettext_noop("Name"),
4367  gettext_noop("Description"));
4368 
4369  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
4370  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
4371 
4372  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4373  "n.nspname", "t.tmplname", NULL,
4374  "pg_catalog.pg_ts_template_is_visible(t.oid)");
4375 
4376  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4377 
4378  res = PSQLexec(buf.data);
4379  termPQExpBuffer(&buf);
4380  if (!res)
4381  return false;
4382 
4383  myopt.nullPrint = NULL;
4384  myopt.title = _("List of text search templates");
4385  myopt.translate_header = true;
4386 
4387  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4388 
4389  PQclear(res);
4390  return true;
4391 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool listUserMappings ( const char *  pattern,
bool  verbose 
)

Definition at line 4770 of file describe.c.

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

Referenced by exec_command_d().

4771 {
4773  PGresult *res;
4774  printQueryOpt myopt = pset.popt;
4775 
4776  if (pset.sversion < 80400)
4777  {
4778  char sverbuf[32];
4779 
4780  psql_error("The server (version %s) does not support user mappings.\n",
4782  sverbuf, sizeof(sverbuf)));
4783  return true;
4784  }
4785 
4786  initPQExpBuffer(&buf);
4787  printfPQExpBuffer(&buf,
4788  "SELECT um.srvname AS \"%s\",\n"
4789  " um.usename AS \"%s\"",
4790  gettext_noop("Server"),
4791  gettext_noop("User name"));
4792 
4793  if (verbose)
4794  appendPQExpBuffer(&buf,
4795  ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4796  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
4797  " pg_catalog.quote_ident(option_name) || ' ' || "
4798  " pg_catalog.quote_literal(option_value) FROM "
4799  " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
4800  " END AS \"%s\"",
4801  gettext_noop("FDW options"));
4802 
4803  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4804 
4805  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4806  NULL, "um.srvname", "um.usename", NULL);
4807 
4808  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4809 
4810  res = PSQLexec(buf.data);
4811  termPQExpBuffer(&buf);
4812  if (!res)
4813  return false;
4814 
4815  myopt.nullPrint = NULL;
4816  myopt.title = _("List of user mappings");
4817  myopt.translate_header = true;
4818 
4819  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4820 
4821  PQclear(res);
4822  return true;
4823 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * nullPrint
Definition: print.h:166
PsqlSettings pset
Definition: startup.c:33
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define gettext_noop(x)
Definition: c.h:139
FILE * queryFout
Definition: settings.h:84
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule)
Definition: string_utils.c:833
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:66
bool translate_header
Definition: print.h:169
static int verbose
Definition: pg_basebackup.c:84
void psql_error(const char *fmt,...)
Definition: common.c:220
FILE * logfile
Definition: settings.h:114
void PQclear(PGresult *res)
Definition: fe-exec.c:650
char * title
Definition: print.h:167
#define NULL
Definition: c.h:229
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3285
#define _(x)
Definition: elog.c:84
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:182
PGresult * PSQLexec(const char *query)
Definition: common.c:642
bool objectDescription ( const char *  pattern,
bool  showSystem 
)

Definition at line 1100 of file describe.c.

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

Referenced by exec_command_d().

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

Definition at line 855 of file describe.c.

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

Referenced by exec_command_d(), and exec_command_z().

856 {
858  PGresult *res;
859  printQueryOpt myopt = pset.popt;
860  static const bool translate_columns[] = {false, false, true, false, false, false};
861 
862  initPQExpBuffer(&buf);
863 
864  /*
865  * we ignore indexes and toast tables since they have no meaningful rights
866  */
867  printfPQExpBuffer(&buf,
868  "SELECT n.nspname as \"%s\",\n"
869  " c.relname as \"%s\",\n"
870  " CASE c.relkind"
871  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
872  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
873  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
874  " WHEN " Cpp