PostgreSQL Source Code  git master
describe.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool describeAggregates (const char *pattern, bool verbose, bool showSystem)
 
bool describeAccessMethods (const char *pattern, bool verbose)
 
bool describeTablespaces (const char *pattern, bool verbose)
 
bool describeFunctions (const char *functypes, const char *pattern, bool verbose, bool showSystem)
 
bool describeTypes (const char *pattern, bool verbose, bool showSystem)
 
bool describeOperators (const char *pattern, bool verbose, bool showSystem)
 
bool describeRoles (const char *pattern, bool verbose, bool showSystem)
 
bool listDbRoleSettings (const char *pattern, 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 listPartitionedTables (const char *reltypes, const char *pattern, bool verbose)
 
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)
 
bool listOperatorClasses (const char *access_method_pattern, const char *opclass_pattern, bool verbose)
 
bool listOperatorFamilies (const char *access_method_pattern, const char *opclass_pattern, bool verbose)
 
bool listOpFamilyOperators (const char *accessMethod_pattern, const char *family_pattern, bool verbose)
 
bool listOpFamilyFunctions (const char *access_method_pattern, const char *family_pattern)
 

Function Documentation

◆ describeAccessMethods()

bool describeAccessMethods ( const char *  pattern,
bool  verbose 
)

Definition at line 149 of file describe.c.

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

Referenced by exec_command_d().

150 {
152  PGresult *res;
153  printQueryOpt myopt = pset.popt;
154  static const bool translate_columns[] = {false, true, false, false};
155 
156  if (pset.sversion < 90600)
157  {
158  char sverbuf[32];
159 
160  pg_log_error("The server (version %s) does not support access methods.",
162  sverbuf, sizeof(sverbuf)));
163  return true;
164  }
165 
166  initPQExpBuffer(&buf);
167 
168  printfPQExpBuffer(&buf,
169  "SELECT amname AS \"%s\",\n"
170  " CASE amtype"
171  " WHEN 'i' THEN '%s'"
172  " WHEN 't' THEN '%s'"
173  " END AS \"%s\"",
174  gettext_noop("Name"),
175  gettext_noop("Index"),
176  gettext_noop("Table"),
177  gettext_noop("Type"));
178 
179  if (verbose)
180  {
181  appendPQExpBuffer(&buf,
182  ",\n amhandler AS \"%s\",\n"
183  " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
184  gettext_noop("Handler"),
185  gettext_noop("Description"));
186  }
187 
189  "\nFROM pg_catalog.pg_am\n");
190 
191  processSQLNamePattern(pset.db, &buf, pattern, false, false,
192  NULL, "amname", NULL,
193  NULL);
194 
195  appendPQExpBufferStr(&buf, "ORDER BY 1;");
196 
197  res = PSQLexec(buf.data);
198  termPQExpBuffer(&buf);
199  if (!res)
200  return false;
201 
202  myopt.nullPrint = NULL;
203  myopt.title = _("List of access methods");
204  myopt.translate_header = true;
205  myopt.translate_columns = translate_columns;
206  myopt.n_translate_columns = lengthof(translate_columns);
207 
208  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
209 
210  PQclear(res);
211  return true;
212 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ describeAggregates()

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

Definition at line 63 of file describe.c.

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

Referenced by exec_command_d().

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

◆ describeFunctions()

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

Definition at line 315 of file describe.c.

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

Referenced by exec_command_d().

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

◆ describeOperators()

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

Definition at line 783 of file describe.c.

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

Referenced by exec_command_d().

784 {
786  PGresult *res;
787  printQueryOpt myopt = pset.popt;
788 
789  initPQExpBuffer(&buf);
790 
791  /*
792  * Note: before Postgres 9.1, we did not assign comments to any built-in
793  * operators, preferring to let the comment on the underlying function
794  * suffice. The coalesce() on the obj_description() calls below supports
795  * this convention by providing a fallback lookup of a comment on the
796  * operator's function. As of 9.1 there is a policy that every built-in
797  * operator should have a comment; so the coalesce() is no longer
798  * necessary so far as built-in operators are concerned. We keep it
799  * anyway, for now, because (1) third-party modules may still be following
800  * the old convention, and (2) we'd need to do it anyway when talking to a
801  * pre-9.1 server.
802  */
803 
804  printfPQExpBuffer(&buf,
805  "SELECT n.nspname as \"%s\",\n"
806  " o.oprname AS \"%s\",\n"
807  " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
808  " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
809  " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
810  gettext_noop("Schema"),
811  gettext_noop("Name"),
812  gettext_noop("Left arg type"),
813  gettext_noop("Right arg type"),
814  gettext_noop("Result type"));
815 
816  if (verbose)
817  appendPQExpBuffer(&buf,
818  " o.oprcode AS \"%s\",\n",
819  gettext_noop("Function"));
820 
821  appendPQExpBuffer(&buf,
822  " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
823  " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
824  "FROM pg_catalog.pg_operator o\n"
825  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
826  gettext_noop("Description"));
827 
828  if (!showSystem && !pattern)
829  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
830  " AND n.nspname <> 'information_schema'\n");
831 
832  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
833  "n.nspname", "o.oprname", NULL,
834  "pg_catalog.pg_operator_is_visible(o.oid)");
835 
836  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
837 
838  res = PSQLexec(buf.data);
839  termPQExpBuffer(&buf);
840  if (!res)
841  return false;
842 
843  myopt.nullPrint = NULL;
844  myopt.title = _("List of operators");
845  myopt.translate_header = true;
846 
847  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
848 
849  PQclear(res);
850  return true;
851 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ describePublications()

bool describePublications ( const char *  pattern)

Definition at line 5794 of file describe.c.

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

Referenced by exec_command_d().

5795 {
5797  int i;
5798  PGresult *res;
5799  bool has_pubtruncate;
5800  bool has_pubviaroot;
5801 
5802  if (pset.sversion < 100000)
5803  {
5804  char sverbuf[32];
5805 
5806  pg_log_error("The server (version %s) does not support publications.",
5808  sverbuf, sizeof(sverbuf)));
5809  return true;
5810  }
5811 
5812  has_pubtruncate = (pset.sversion >= 110000);
5813  has_pubviaroot = (pset.sversion >= 130000);
5814 
5815  initPQExpBuffer(&buf);
5816 
5817  printfPQExpBuffer(&buf,
5818  "SELECT oid, pubname,\n"
5819  " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
5820  " puballtables, pubinsert, pubupdate, pubdelete");
5821  if (has_pubtruncate)
5822  appendPQExpBufferStr(&buf,
5823  ", pubtruncate");
5824  if (has_pubviaroot)
5825  appendPQExpBufferStr(&buf,
5826  ", pubviaroot");
5827  appendPQExpBufferStr(&buf,
5828  "\nFROM pg_catalog.pg_publication\n");
5829 
5830  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5831  NULL, "pubname", NULL,
5832  NULL);
5833 
5834  appendPQExpBufferStr(&buf, "ORDER BY 2;");
5835 
5836  res = PSQLexec(buf.data);
5837  if (!res)
5838  {
5839  termPQExpBuffer(&buf);
5840  return false;
5841  }
5842 
5843  if (PQntuples(res) == 0)
5844  {
5845  if (!pset.quiet)
5846  {
5847  if (pattern)
5848  pg_log_error("Did not find any publication named \"%s\".",
5849  pattern);
5850  else
5851  pg_log_error("Did not find any publications.");
5852  }
5853 
5854  termPQExpBuffer(&buf);
5855  PQclear(res);
5856  return false;
5857  }
5858 
5859  for (i = 0; i < PQntuples(res); i++)
5860  {
5861  const char align = 'l';
5862  int ncols = 5;
5863  int nrows = 1;
5864  int tables = 0;
5865  PGresult *tabres;
5866  char *pubid = PQgetvalue(res, i, 0);
5867  char *pubname = PQgetvalue(res, i, 1);
5868  bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
5869  int j;
5870  PQExpBufferData title;
5871  printTableOpt myopt = pset.popt.topt;
5872  printTableContent cont;
5873 
5874  if (has_pubtruncate)
5875  ncols++;
5876  if (has_pubviaroot)
5877  ncols++;
5878 
5879  initPQExpBuffer(&title);
5880  printfPQExpBuffer(&title, _("Publication %s"), pubname);
5881  printTableInit(&cont, &myopt, title.data, ncols, nrows);
5882 
5883  printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
5884  printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
5885  printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
5886  printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
5887  printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
5888  if (has_pubtruncate)
5889  printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
5890  if (has_pubviaroot)
5891  printTableAddHeader(&cont, gettext_noop("Via root"), true, align);
5892 
5893  printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
5894  printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
5895  printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
5896  printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
5897  printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
5898  if (has_pubtruncate)
5899  printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
5900  if (has_pubviaroot)
5901  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
5902 
5903  if (!puballtables)
5904  {
5905  printfPQExpBuffer(&buf,
5906  "SELECT n.nspname, c.relname\n"
5907  "FROM pg_catalog.pg_class c,\n"
5908  " pg_catalog.pg_namespace n,\n"
5909  " pg_catalog.pg_publication_rel pr\n"
5910  "WHERE c.relnamespace = n.oid\n"
5911  " AND c.oid = pr.prrelid\n"
5912  " AND pr.prpubid = '%s'\n"
5913  "ORDER BY 1,2", pubid);
5914 
5915  tabres = PSQLexec(buf.data);
5916  if (!tabres)
5917  {
5918  printTableCleanup(&cont);
5919  PQclear(res);
5920  termPQExpBuffer(&buf);
5921  termPQExpBuffer(&title);
5922  return false;
5923  }
5924  else
5925  tables = PQntuples(tabres);
5926 
5927  if (tables > 0)
5928  printTableAddFooter(&cont, _("Tables:"));
5929 
5930  for (j = 0; j < tables; j++)
5931  {
5932  printfPQExpBuffer(&buf, " \"%s.%s\"",
5933  PQgetvalue(tabres, j, 0),
5934  PQgetvalue(tabres, j, 1));
5935 
5936  printTableAddFooter(&cont, buf.data);
5937  }
5938  PQclear(tabres);
5939  }
5940 
5941  printTable(&cont, pset.queryFout, false, pset.logfile);
5942  printTableCleanup(&cont);
5943 
5944  termPQExpBuffer(&title);
5945  }
5946 
5947  termPQExpBuffer(&buf);
5948  PQclear(res);
5949 
5950  return true;
5951 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
void printTableCleanup(printTableContent *const content)
Definition: print.c:3225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
printTableOpt topt
Definition: print.h:169
#define gettext_noop(x)
Definition: c.h:1159
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:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3094
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3134
static char * buf
Definition: pg_test_fsync.c:67
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3314
void printTableAddFooter(printTableContent *const content, const char *footer)
Definition: print.c:3182
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
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:3057
int i
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ describeRoles()

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

Definition at line 3413 of file describe.c.

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

Referenced by exec_command_d().

3414 {
3416  PGresult *res;
3417  printTableContent cont;
3418  printTableOpt myopt = pset.popt.topt;
3419  int ncols = 3;
3420  int nrows = 0;
3421  int i;
3422  int conns;
3423  const char align = 'l';
3424  char **attr;
3425 
3426  myopt.default_footer = false;
3427 
3428  initPQExpBuffer(&buf);
3429 
3430  if (pset.sversion >= 80100)
3431  {
3432  printfPQExpBuffer(&buf,
3433  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3434  " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3435  " r.rolconnlimit, r.rolvaliduntil,\n"
3436  " ARRAY(SELECT b.rolname\n"
3437  " FROM pg_catalog.pg_auth_members m\n"
3438  " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3439  " WHERE m.member = r.oid) as memberof");
3440 
3441  if (verbose && pset.sversion >= 80200)
3442  {
3443  appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3444  ncols++;
3445  }
3446  if (pset.sversion >= 90100)
3447  {
3448  appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3449  }
3450 
3451  if (pset.sversion >= 90500)
3452  {
3453  appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3454  }
3455 
3456  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3457 
3458  if (!showSystem && !pattern)
3459  appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3460 
3461  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3462  NULL, "r.rolname", NULL, NULL);
3463  }
3464  else
3465  {
3466  printfPQExpBuffer(&buf,
3467  "SELECT u.usename AS rolname,\n"
3468  " u.usesuper AS rolsuper,\n"
3469  " true AS rolinherit, false AS rolcreaterole,\n"
3470  " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
3471  " -1 AS rolconnlimit,"
3472  " u.valuntil as rolvaliduntil,\n"
3473  " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
3474  "\nFROM pg_catalog.pg_user u\n");
3475 
3476  processSQLNamePattern(pset.db, &buf, pattern, false, false,
3477  NULL, "u.usename", NULL, NULL);
3478  }
3479 
3480  appendPQExpBufferStr(&buf, "ORDER BY 1;");
3481 
3482  res = PSQLexec(buf.data);
3483  if (!res)
3484  return false;
3485 
3486  nrows = PQntuples(res);
3487  attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3488 
3489  printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3490 
3491  printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3492  printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3493  printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
3494 
3495  if (verbose && pset.sversion >= 80200)
3496  printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3497 
3498  for (i = 0; i < nrows; i++)
3499  {
3500  printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3501 
3502  resetPQExpBuffer(&buf);
3503  if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3504  add_role_attribute(&buf, _("Superuser"));
3505 
3506  if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3507  add_role_attribute(&buf, _("No inheritance"));
3508 
3509  if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3510  add_role_attribute(&buf, _("Create role"));
3511 
3512  if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3513  add_role_attribute(&buf, _("Create DB"));
3514 
3515  if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3516  add_role_attribute(&buf, _("Cannot login"));
3517 
3518  if (pset.sversion >= 90100)
3519  if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3520  add_role_attribute(&buf, _("Replication"));
3521 
3522  if (pset.sversion >= 90500)
3523  if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
3524  add_role_attribute(&buf, _("Bypass RLS"));
3525 
3526  conns = atoi(PQgetvalue(res, i, 6));
3527  if (conns >= 0)
3528  {
3529  if (buf.len > 0)
3530  appendPQExpBufferChar(&buf, '\n');
3531 
3532  if (conns == 0)
3533  appendPQExpBufferStr(&buf, _("No connections"));
3534  else
3535  appendPQExpBuffer(&buf, ngettext("%d connection",
3536  "%d connections",
3537  conns),
3538  conns);
3539  }
3540 
3541  if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3542  {
3543  if (buf.len > 0)
3544  appendPQExpBufferChar(&buf, '\n');
3545  appendPQExpBufferStr(&buf, _("Password valid until "));
3546  appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
3547  }
3548 
3549  attr[i] = pg_strdup(buf.data);
3550 
3551  printTableAddCell(&cont, attr[i], false, false);
3552 
3553  printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3554 
3555  if (verbose && pset.sversion >= 80200)
3556  printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
3557  }
3558  termPQExpBuffer(&buf);
3559 
3560  printTable(&cont, pset.queryFout, false, pset.logfile);
3561  printTableCleanup(&cont);
3562 
3563  for (i = 0; i < nrows; i++)
3564  free(attr[i]);
3565  free(attr);
3566 
3567  PQclear(res);
3568  return true;
3569 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
void printTableCleanup(printTableContent *const content)
Definition: print.c:3225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
printTableOpt topt
Definition: print.h:169
#define gettext_noop(x)
Definition: c.h:1159
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:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3572
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3094
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:3134
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3314
static int verbose
#define ngettext(s, p, n)
Definition: c.h:1145
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define free(a)
Definition: header.h:65
bool default_footer
Definition: print.h:113
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:3057
int i
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ describeSubscriptions()

bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 5960 of file describe.c.

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

Referenced by exec_command_d().

5961 {
5963  PGresult *res;
5964  printQueryOpt myopt = pset.popt;
5965  static const bool translate_columns[] = {false, false, false, false,
5966  false, false};
5967 
5968  if (pset.sversion < 100000)
5969  {
5970  char sverbuf[32];
5971 
5972  pg_log_error("The server (version %s) does not support subscriptions.",
5974  sverbuf, sizeof(sverbuf)));
5975  return true;
5976  }
5977 
5978  initPQExpBuffer(&buf);
5979 
5980  printfPQExpBuffer(&buf,
5981  "SELECT subname AS \"%s\"\n"
5982  ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
5983  ", subenabled AS \"%s\"\n"
5984  ", subpublications AS \"%s\"\n",
5985  gettext_noop("Name"),
5986  gettext_noop("Owner"),
5987  gettext_noop("Enabled"),
5988  gettext_noop("Publication"));
5989 
5990  if (verbose)
5991  {
5992  appendPQExpBuffer(&buf,
5993  ", subsynccommit AS \"%s\"\n"
5994  ", subconninfo AS \"%s\"\n",
5995  gettext_noop("Synchronous commit"),
5996  gettext_noop("Conninfo"));
5997  }
5998 
5999  /* Only display subscriptions in current database. */
6000  appendPQExpBufferStr(&buf,
6001  "FROM pg_catalog.pg_subscription\n"
6002  "WHERE subdbid = (SELECT oid\n"
6003  " FROM pg_catalog.pg_database\n"
6004  " WHERE datname = pg_catalog.current_database())");
6005 
6006  processSQLNamePattern(pset.db, &buf, pattern, true, false,
6007  NULL, "subname", NULL,
6008  NULL);
6009 
6010  appendPQExpBufferStr(&buf, "ORDER BY 1;");
6011 
6012  res = PSQLexec(buf.data);
6013  termPQExpBuffer(&buf);
6014  if (!res)
6015  return false;
6016 
6017  myopt.nullPrint = NULL;
6018  myopt.title = _("List of subscriptions");
6019  myopt.translate_header = true;
6020  myopt.translate_columns = translate_columns;
6021  myopt.n_translate_columns = lengthof(translate_columns);
6022 
6023  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6024 
6025  PQclear(res);
6026  return true;
6027 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ describeTableDetails()

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

Definition at line 1367 of file describe.c.

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

Referenced by exec_command_d().

1368 {
1370  PGresult *res;
1371  int i;
1372 
1373  initPQExpBuffer(&buf);
1374 
1375  printfPQExpBuffer(&buf,
1376  "SELECT c.oid,\n"
1377  " n.nspname,\n"
1378  " c.relname\n"
1379  "FROM pg_catalog.pg_class c\n"
1380  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1381 
1382  if (!showSystem && !pattern)
1383  appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1384  " AND n.nspname <> 'information_schema'\n");
1385 
1386  processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1387  "n.nspname", "c.relname", NULL,
1388  "pg_catalog.pg_table_is_visible(c.oid)");
1389 
1390  appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1391 
1392  res = PSQLexec(buf.data);
1393  termPQExpBuffer(&buf);
1394  if (!res)
1395  return false;
1396 
1397  if (PQntuples(res) == 0)
1398  {
1399  if (!pset.quiet)
1400  {
1401  if (pattern)
1402  pg_log_error("Did not find any relation named \"%s\".",
1403  pattern);
1404  else
1405  pg_log_error("Did not find any relations.");
1406  }
1407  PQclear(res);
1408  return false;
1409  }
1410 
1411  for (i = 0; i < PQntuples(res); i++)
1412  {
1413  const char *oid;
1414  const char *nspname;
1415  const char *relname;
1416 
1417  oid = PQgetvalue(res, i, 0);
1418  nspname = PQgetvalue(res, i, 1);
1419  relname = PQgetvalue(res, i, 2);
1420 
1421  if (!describeOneTableDetails(nspname, relname, oid, verbose))
1422  {
1423  PQclear(res);
1424  return false;
1425  }
1426  if (cancel_pressed)
1427  {
1428  PQclear(res);
1429  return false;
1430  }
1431  }
1432 
1433  PQclear(res);
1434  return true;
1435 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
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:827
NameData relname
Definition: pg_class.h:38
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
static char * buf
Definition: pg_test_fsync.c:67
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1445
static int verbose
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
void PQclear(PGresult *res)
Definition: fe-exec.c:694
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ describeTablespaces()

bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 219 of file describe.c.

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

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

◆ describeTypes()

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

Definition at line 667 of file describe.c.

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

Referenced by exec_command_d().

668 {
670  PGresult *res;
671  printQueryOpt myopt = pset.popt;
672 
673  initPQExpBuffer(&buf);
674 
675  printfPQExpBuffer(&buf,
676  "SELECT n.nspname as \"%s\",\n"
677  " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
678  gettext_noop("Schema"),
679  gettext_noop("Name"));
680  if (verbose)
681  appendPQExpBuffer(&buf,
682  " t.typname AS \"%s\",\n"
683  " CASE WHEN t.typrelid != 0\n"
684  " THEN CAST('tuple' AS pg_catalog.text)\n"
685  " WHEN t.typlen < 0\n"
686  " THEN CAST('var' AS pg_catalog.text)\n"
687  " ELSE CAST(t.typlen AS pg_catalog.text)\n"
688  " END AS \"%s\",\n",
689  gettext_noop("Internal name"),
690  gettext_noop("Size"));
691  if (verbose && pset.sversion >= 80300)
692  {
694  " pg_catalog.array_to_string(\n"
695  " ARRAY(\n"
696  " SELECT e.enumlabel\n"
697  " FROM pg_catalog.pg_enum e\n"
698  " WHERE e.enumtypid = t.oid\n");
699 
700  if (pset.sversion >= 90100)
702  " ORDER BY e.enumsortorder\n");
703  else
705  " ORDER BY e.oid\n");
706 
707  appendPQExpBuffer(&buf,
708  " ),\n"
709  " E'\\n'\n"
710  " ) AS \"%s\",\n",
711  gettext_noop("Elements"));
712  }
713  if (verbose)
714  {
715  appendPQExpBuffer(&buf,
716  " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
717  gettext_noop("Owner"));
718  }
719  if (verbose && pset.sversion >= 90200)
720  {
721  printACLColumn(&buf, "t.typacl");
722  appendPQExpBufferStr(&buf, ",\n ");
723  }
724 
725  appendPQExpBuffer(&buf,
726  " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
727  gettext_noop("Description"));
728 
729  appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
730  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
731 
732  /*
733  * do not include complex types (typrelid!=0) unless they are standalone
734  * composite types
735  */
736  appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
737  appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = " CppAsString2(RELKIND_COMPOSITE_TYPE)
738  " FROM pg_catalog.pg_class c "
739  "WHERE c.oid = t.typrelid))\n");
740 
741  /*
742  * do not include array types (before 8.3 we have to use the assumption
743  * that their names start with underscore)
744  */
745  if (pset.sversion >= 80300)
746  appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
747  else
748  appendPQExpBufferStr(&buf, " AND t.typname !~ '^_'\n");
749 
750  if (!showSystem && !pattern)
751  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
752  " AND n.nspname <> 'information_schema'\n");
753 
754  /* Match name pattern against either internal or external name */
755  processSQLNamePattern(pset.db, &buf, pattern, true, false,
756  "n.nspname", "t.typname",
757  "pg_catalog.format_type(t.oid, NULL)",
758  "pg_catalog.pg_type_is_visible(t.oid)");
759 
760  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
761 
762  res = PSQLexec(buf.data);
763  termPQExpBuffer(&buf);
764  if (!res)
765  return false;
766 
767  myopt.nullPrint = NULL;
768  myopt.title = _("List of data types");
769  myopt.translate_header = true;
770 
771  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
772 
773  PQclear(res);
774  return true;
775 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
#define CppAsString2(x)
Definition: c.h:222
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listAllDbs()

bool listAllDbs ( const char *  pattern,
bool  verbose 
)

Definition at line 860 of file describe.c.

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

Referenced by exec_command_list(), and main().

861 {
862  PGresult *res;
864  printQueryOpt myopt = pset.popt;
865 
866  initPQExpBuffer(&buf);
867 
868  printfPQExpBuffer(&buf,
869  "SELECT d.datname as \"%s\",\n"
870  " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
871  " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
872  gettext_noop("Name"),
873  gettext_noop("Owner"),
874  gettext_noop("Encoding"));
875  if (pset.sversion >= 80400)
876  appendPQExpBuffer(&buf,
877  " d.datcollate as \"%s\",\n"
878  " d.datctype as \"%s\",\n",
879  gettext_noop("Collate"),
880  gettext_noop("Ctype"));
881  appendPQExpBufferStr(&buf, " ");
882  printACLColumn(&buf, "d.datacl");
883  if (verbose && pset.sversion >= 80200)
884  appendPQExpBuffer(&buf,
885  ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
886  " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
887  " ELSE 'No Access'\n"
888  " END as \"%s\"",
889  gettext_noop("Size"));
890  if (verbose && pset.sversion >= 80000)
891  appendPQExpBuffer(&buf,
892  ",\n t.spcname as \"%s\"",
893  gettext_noop("Tablespace"));
894  if (verbose && pset.sversion >= 80200)
895  appendPQExpBuffer(&buf,
896  ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
897  gettext_noop("Description"));
899  "\nFROM pg_catalog.pg_database d\n");
900  if (verbose && pset.sversion >= 80000)
902  " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
903 
904  if (pattern)
905  processSQLNamePattern(pset.db, &buf, pattern, false, false,
906  NULL, "d.datname", NULL, NULL);
907 
908  appendPQExpBufferStr(&buf, "ORDER BY 1;");
909  res = PSQLexec(buf.data);
910  termPQExpBuffer(&buf);
911  if (!res)
912  return false;
913 
914  myopt.nullPrint = NULL;
915  myopt.title = _("List of databases");
916  myopt.translate_header = true;
917 
918  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
919 
920  PQclear(res);
921  return true;
922 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listCasts()

bool listCasts ( const char *  pattern,
bool  verbose 
)

Definition at line 4376 of file describe.c.

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

Referenced by exec_command_d().

4377 {
4379  PGresult *res;
4380  printQueryOpt myopt = pset.popt;
4381  static const bool translate_columns[] = {false, false, false, true, false};
4382 
4383  initPQExpBuffer(&buf);
4384 
4385  printfPQExpBuffer(&buf,
4386  "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4387  " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4388  gettext_noop("Source type"),
4389  gettext_noop("Target type"));
4390 
4391  /*
4392  * We don't attempt to localize '(binary coercible)' or '(with inout)',
4393  * because there's too much risk of gettext translating a function name
4394  * that happens to match some string in the PO database.
4395  */
4396  if (pset.sversion >= 80400)
4397  appendPQExpBuffer(&buf,
4398  " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4399  " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4400  " ELSE p.proname\n"
4401  " END AS \"%s\",\n",
4402  COERCION_METHOD_BINARY,
4403  COERCION_METHOD_INOUT,
4404  gettext_noop("Function"));
4405  else
4406  appendPQExpBuffer(&buf,
4407  " CASE WHEN c.castfunc = 0 THEN '(binary coercible)'\n"
4408  " ELSE p.proname\n"
4409  " END AS \"%s\",\n",
4410  gettext_noop("Function"));
4411 
4412  appendPQExpBuffer(&buf,
4413  " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4414  " WHEN c.castcontext = '%c' THEN '%s'\n"
4415  " ELSE '%s'\n"
4416  " END AS \"%s\"",
4417  COERCION_CODE_EXPLICIT,
4418  gettext_noop("no"),
4419  COERCION_CODE_ASSIGNMENT,
4420  gettext_noop("in assignment"),
4421  gettext_noop("yes"),
4422  gettext_noop("Implicit?"));
4423 
4424  if (verbose)
4425  appendPQExpBuffer(&buf,
4426  ",\n d.description AS \"%s\"",
4427  gettext_noop("Description"));
4428 
4429  /*
4430  * We need a left join to pg_proc for binary casts; the others are just
4431  * paranoia.
4432  */
4433  appendPQExpBufferStr(&buf,
4434  "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4435  " ON c.castfunc = p.oid\n"
4436  " LEFT JOIN pg_catalog.pg_type ts\n"
4437  " ON c.castsource = ts.oid\n"
4438  " LEFT JOIN pg_catalog.pg_namespace ns\n"
4439  " ON ns.oid = ts.typnamespace\n"
4440  " LEFT JOIN pg_catalog.pg_type tt\n"
4441  " ON c.casttarget = tt.oid\n"
4442  " LEFT JOIN pg_catalog.pg_namespace nt\n"
4443  " ON nt.oid = tt.typnamespace\n");
4444 
4445  if (verbose)
4446  appendPQExpBufferStr(&buf,
4447  " LEFT JOIN pg_catalog.pg_description d\n"
4448  " ON d.classoid = c.tableoid AND d.objoid = "
4449  "c.oid AND d.objsubid = 0\n");
4450 
4451  appendPQExpBufferStr(&buf, "WHERE ( (true");
4452 
4453  /*
4454  * Match name pattern against either internal or external name of either
4455  * castsource or casttarget
4456  */
4457  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4458  "ns.nspname", "ts.typname",
4459  "pg_catalog.format_type(ts.oid, NULL)",
4460  "pg_catalog.pg_type_is_visible(ts.oid)");
4461 
4462  appendPQExpBufferStr(&buf, ") OR (true");
4463 
4464  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4465  "nt.nspname", "tt.typname",
4466  "pg_catalog.format_type(tt.oid, NULL)",
4467  "pg_catalog.pg_type_is_visible(tt.oid)");
4468 
4469  appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
4470 
4471  res = PSQLexec(buf.data);
4472  termPQExpBuffer(&buf);
4473  if (!res)
4474  return false;
4475 
4476  myopt.nullPrint = NULL;
4477  myopt.title = _("List of casts");
4478  myopt.translate_header = true;
4479  myopt.translate_columns = translate_columns;
4480  myopt.n_translate_columns = lengthof(translate_columns);
4481 
4482  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4483 
4484  PQclear(res);
4485  return true;
4486 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listCollations()

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

Definition at line 4494 of file describe.c.

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

Referenced by exec_command_d().

4495 {
4497  PGresult *res;
4498  printQueryOpt myopt = pset.popt;
4499  static const bool translate_columns[] = {false, false, false, false, false, true, false};
4500 
4501  if (pset.sversion < 90100)
4502  {
4503  char sverbuf[32];
4504 
4505  pg_log_error("The server (version %s) does not support collations.",
4507  sverbuf, sizeof(sverbuf)));
4508  return true;
4509  }
4510 
4511  initPQExpBuffer(&buf);
4512 
4513  printfPQExpBuffer(&buf,
4514  "SELECT n.nspname AS \"%s\",\n"
4515  " c.collname AS \"%s\",\n"
4516  " c.collcollate AS \"%s\",\n"
4517  " c.collctype AS \"%s\"",
4518  gettext_noop("Schema"),
4519  gettext_noop("Name"),
4520  gettext_noop("Collate"),
4521  gettext_noop("Ctype"));
4522 
4523  if (pset.sversion >= 100000)
4524  appendPQExpBuffer(&buf,
4525  ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
4526  gettext_noop("Provider"));
4527  else
4528  appendPQExpBuffer(&buf,
4529  ",\n 'libc' AS \"%s\"",
4530  gettext_noop("Provider"));
4531 
4532  if (pset.sversion >= 120000)
4533  appendPQExpBuffer(&buf,
4534  ",\n CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4535  gettext_noop("yes"), gettext_noop("no"),
4536  gettext_noop("Deterministic?"));
4537  else
4538  appendPQExpBuffer(&buf,
4539  ",\n '%s' AS \"%s\"",
4540  gettext_noop("yes"),
4541  gettext_noop("Deterministic?"));
4542 
4543  if (verbose)
4544  appendPQExpBuffer(&buf,
4545  ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4546  gettext_noop("Description"));
4547 
4548  appendPQExpBufferStr(&buf,
4549  "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4550  "WHERE n.oid = c.collnamespace\n");
4551 
4552  if (!showSystem && !pattern)
4553  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4554  " AND n.nspname <> 'information_schema'\n");
4555 
4556  /*
4557  * Hide collations that aren't usable in the current database's encoding.
4558  * If you think to change this, note that pg_collation_is_visible rejects
4559  * unusable collations, so you will need to hack name pattern processing
4560  * somehow to avoid inconsistent behavior.
4561  */
4562  appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4563 
4564  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4565  "n.nspname", "c.collname", NULL,
4566  "pg_catalog.pg_collation_is_visible(c.oid)");
4567 
4568  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4569 
4570  res = PSQLexec(buf.data);
4571  termPQExpBuffer(&buf);
4572  if (!res)
4573  return false;
4574 
4575  myopt.nullPrint = NULL;
4576  myopt.title = _("List of collations");
4577  myopt.translate_header = true;
4578  myopt.translate_columns = translate_columns;
4579  myopt.n_translate_columns = lengthof(translate_columns);
4580 
4581  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4582 
4583  PQclear(res);
4584  return true;
4585 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listConversions()

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

Definition at line 4234 of file describe.c.

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

Referenced by exec_command_d().

4235 {
4237  PGresult *res;
4238  printQueryOpt myopt = pset.popt;
4239  static const bool translate_columns[] =
4240  {false, false, false, false, true, false};
4241 
4242  initPQExpBuffer(&buf);
4243 
4244  printfPQExpBuffer(&buf,
4245  "SELECT n.nspname AS \"%s\",\n"
4246  " c.conname AS \"%s\",\n"
4247  " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4248  " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4249  " CASE WHEN c.condefault THEN '%s'\n"
4250  " ELSE '%s' END AS \"%s\"",
4251  gettext_noop("Schema"),
4252  gettext_noop("Name"),
4253  gettext_noop("Source"),
4254  gettext_noop("Destination"),
4255  gettext_noop("yes"), gettext_noop("no"),
4256  gettext_noop("Default?"));
4257 
4258  if (verbose)
4259  appendPQExpBuffer(&buf,
4260  ",\n d.description AS \"%s\"",
4261  gettext_noop("Description"));
4262 
4263  appendPQExpBufferStr(&buf,
4264  "\nFROM pg_catalog.pg_conversion c\n"
4265  " JOIN pg_catalog.pg_namespace n "
4266  "ON n.oid = c.connamespace\n");
4267 
4268  if (verbose)
4269  appendPQExpBufferStr(&buf,
4270  "LEFT JOIN pg_catalog.pg_description d "
4271  "ON d.classoid = c.tableoid\n"
4272  " AND d.objoid = c.oid "
4273  "AND d.objsubid = 0\n");
4274 
4275  appendPQExpBufferStr(&buf, "WHERE true\n");
4276 
4277  if (!showSystem && !pattern)
4278  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4279  " AND n.nspname <> 'information_schema'\n");
4280 
4281  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4282  "n.nspname", "c.conname", NULL,
4283  "pg_catalog.pg_conversion_is_visible(c.oid)");
4284 
4285  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4286 
4287  res = PSQLexec(buf.data);
4288  termPQExpBuffer(&buf);
4289  if (!res)
4290  return false;
4291 
4292  myopt.nullPrint = NULL;
4293  myopt.title = _("List of conversions");
4294  myopt.translate_header = true;
4295  myopt.translate_columns = translate_columns;
4296  myopt.n_translate_columns = lengthof(translate_columns);
4297 
4298  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4299 
4300  PQclear(res);
4301  return true;
4302 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listDbRoleSettings()

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

Definition at line 3584 of file describe.c.

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

Referenced by exec_command_d().

3585 {
3587  PGresult *res;
3588  printQueryOpt myopt = pset.popt;
3589  bool havewhere;
3590 
3591  if (pset.sversion < 90000)
3592  {
3593  char sverbuf[32];
3594 
3595  pg_log_error("The server (version %s) does not support per-database role settings.",
3597  sverbuf, sizeof(sverbuf)));
3598  return true;
3599  }
3600 
3601  initPQExpBuffer(&buf);
3602 
3603  printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3604  "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3605  "FROM pg_catalog.pg_db_role_setting s\n"
3606  "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3607  "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3608  gettext_noop("Role"),
3609  gettext_noop("Database"),
3610  gettext_noop("Settings"));
3611  havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
3612  NULL, "r.rolname", NULL, NULL);
3613  processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
3614  NULL, "d.datname", NULL, NULL);
3615  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3616 
3617  res = PSQLexec(buf.data);
3618  termPQExpBuffer(&buf);
3619  if (!res)
3620  return false;
3621 
3622  /*
3623  * Most functions in this file are content to print an empty table when
3624  * there are no matching objects. We intentionally deviate from that
3625  * here, but only in !quiet mode, because of the possibility that the user
3626  * is confused about what the two pattern arguments mean.
3627  */
3628  if (PQntuples(res) == 0 && !pset.quiet)
3629  {
3630  if (pattern && pattern2)
3631  pg_log_error("Did not find any settings for role \"%s\" and database \"%s\".",
3632  pattern, pattern2);
3633  else if (pattern)
3634  pg_log_error("Did not find any settings for role \"%s\".",
3635  pattern);
3636  else
3637  pg_log_error("Did not find any settings.");
3638  }
3639  else
3640  {
3641  myopt.nullPrint = NULL;
3642  myopt.title = _("List of settings");
3643  myopt.translate_header = true;
3644 
3645  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3646  }
3647 
3648  PQclear(res);
3649  return true;
3650 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1090 of file describe.c.

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

Referenced by exec_command_d().

1091 {
1093  PGresult *res;
1094  printQueryOpt myopt = pset.popt;
1095  static const bool translate_columns[] = {false, false, true, false};
1096 
1097  if (pset.sversion < 90000)
1098  {
1099  char sverbuf[32];
1100 
1101  pg_log_error("The server (version %s) does not support altering default privileges.",
1103  sverbuf, sizeof(sverbuf)));
1104  return true;
1105  }
1106 
1107  initPQExpBuffer(&buf);
1108 
1109  printfPQExpBuffer(&buf,
1110  "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1111  " n.nspname AS \"%s\",\n"
1112  " 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"
1113  " ",
1114  gettext_noop("Owner"),
1115  gettext_noop("Schema"),
1116  DEFACLOBJ_RELATION,
1117  gettext_noop("table"),
1118  DEFACLOBJ_SEQUENCE,
1119  gettext_noop("sequence"),
1120  DEFACLOBJ_FUNCTION,
1121  gettext_noop("function"),
1122  DEFACLOBJ_TYPE,
1123  gettext_noop("type"),
1124  DEFACLOBJ_NAMESPACE,
1125  gettext_noop("schema"),
1126  gettext_noop("Type"));
1127 
1128  printACLColumn(&buf, "d.defaclacl");
1129 
1130  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1131  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1132 
1133  processSQLNamePattern(pset.db, &buf, pattern, false, false,
1134  NULL,
1135  "n.nspname",
1136  "pg_catalog.pg_get_userbyid(d.defaclrole)",
1137  NULL);
1138 
1139  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1140 
1141  res = PSQLexec(buf.data);
1142  if (!res)
1143  {
1144  termPQExpBuffer(&buf);
1145  return false;
1146  }
1147 
1148  myopt.nullPrint = NULL;
1149  printfPQExpBuffer(&buf, _("Default access privileges"));
1150  myopt.title = buf.data;
1151  myopt.translate_header = true;
1152  myopt.translate_columns = translate_columns;
1153  myopt.n_translate_columns = lengthof(translate_columns);
1154 
1155  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1156 
1157  termPQExpBuffer(&buf);
1158  PQclear(res);
1159  return true;
1160 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listDomains()

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

Definition at line 4148 of file describe.c.

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

Referenced by exec_command_d().

4149 {
4151  PGresult *res;
4152  printQueryOpt myopt = pset.popt;
4153 
4154  initPQExpBuffer(&buf);
4155 
4156  printfPQExpBuffer(&buf,
4157  "SELECT n.nspname as \"%s\",\n"
4158  " t.typname as \"%s\",\n"
4159  " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n",
4160  gettext_noop("Schema"),
4161  gettext_noop("Name"),
4162  gettext_noop("Type"));
4163 
4164  if (pset.sversion >= 90100)
4165  appendPQExpBuffer(&buf,
4166  " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4167  " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n",
4168  gettext_noop("Collation"));
4169  appendPQExpBuffer(&buf,
4170  " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4171  " t.typdefault as \"%s\",\n"
4172  " pg_catalog.array_to_string(ARRAY(\n"
4173  " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4174  " ), ' ') as \"%s\"",
4175  gettext_noop("Nullable"),
4176  gettext_noop("Default"),
4177  gettext_noop("Check"));
4178 
4179  if (verbose)
4180  {
4181  if (pset.sversion >= 90200)
4182  {
4183  appendPQExpBufferStr(&buf, ",\n ");
4184  printACLColumn(&buf, "t.typacl");
4185  }
4186  appendPQExpBuffer(&buf,
4187  ",\n d.description as \"%s\"",
4188  gettext_noop("Description"));
4189  }
4190 
4191  appendPQExpBufferStr(&buf,
4192  "\nFROM pg_catalog.pg_type t\n"
4193  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4194 
4195  if (verbose)
4196  appendPQExpBufferStr(&buf,
4197  " LEFT JOIN pg_catalog.pg_description d "
4198  "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4199  "AND d.objsubid = 0\n");
4200 
4201  appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
4202 
4203  if (!showSystem && !pattern)
4204  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4205  " AND n.nspname <> 'information_schema'\n");
4206 
4207  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4208  "n.nspname", "t.typname", NULL,
4209  "pg_catalog.pg_type_is_visible(t.oid)");
4210 
4211  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4212 
4213  res = PSQLexec(buf.data);
4214  termPQExpBuffer(&buf);
4215  if (!res)
4216  return false;
4217 
4218  myopt.nullPrint = NULL;
4219  myopt.title = _("List of domains");
4220  myopt.translate_header = true;
4221 
4222  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4223 
4224  PQclear(res);
4225  return true;
4226 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listEventTriggers()

bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 4310 of file describe.c.

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

Referenced by exec_command_d().

4311 {
4313  PGresult *res;
4314  printQueryOpt myopt = pset.popt;
4315  static const bool translate_columns[] =
4316  {false, false, false, true, false, false, false};
4317 
4318  initPQExpBuffer(&buf);
4319 
4320  printfPQExpBuffer(&buf,
4321  "SELECT evtname as \"%s\", "
4322  "evtevent as \"%s\", "
4323  "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4324  " case evtenabled when 'O' then '%s'"
4325  " when 'R' then '%s'"
4326  " when 'A' then '%s'"
4327  " when 'D' then '%s' end as \"%s\",\n"
4328  " e.evtfoid::pg_catalog.regproc as \"%s\", "
4329  "pg_catalog.array_to_string(array(select x"
4330  " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4331  gettext_noop("Name"),
4332  gettext_noop("Event"),
4333  gettext_noop("Owner"),
4334  gettext_noop("enabled"),
4335  gettext_noop("replica"),
4336  gettext_noop("always"),
4337  gettext_noop("disabled"),
4338  gettext_noop("Enabled"),
4339  gettext_noop("Function"),
4340  gettext_noop("Tags"));
4341  if (verbose)
4342  appendPQExpBuffer(&buf,
4343  ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4344  gettext_noop("Description"));
4345  appendPQExpBufferStr(&buf,
4346  "\nFROM pg_catalog.pg_event_trigger e ");
4347 
4348  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4349  NULL, "evtname", NULL, NULL);
4350 
4351  appendPQExpBufferStr(&buf, "ORDER BY 1");
4352 
4353  res = PSQLexec(buf.data);
4354  termPQExpBuffer(&buf);
4355  if (!res)
4356  return false;
4357 
4358  myopt.nullPrint = NULL;
4359  myopt.title = _("List of event triggers");
4360  myopt.translate_header = true;
4361  myopt.translate_columns = translate_columns;
4362  myopt.n_translate_columns = lengthof(translate_columns);
4363 
4364  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4365 
4366  PQclear(res);
4367  return true;
4368 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listExtensionContents()

bool listExtensionContents ( const char *  pattern)

Definition at line 5606 of file describe.c.

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

Referenced by exec_command_d().

5607 {
5609  PGresult *res;
5610  int i;
5611 
5612  if (pset.sversion < 90100)
5613  {
5614  char sverbuf[32];
5615 
5616  pg_log_error("The server (version %s) does not support extensions.",
5618  sverbuf, sizeof(sverbuf)));
5619  return true;
5620  }
5621 
5622  initPQExpBuffer(&buf);
5623  printfPQExpBuffer(&buf,
5624  "SELECT e.extname, e.oid\n"
5625  "FROM pg_catalog.pg_extension e\n");
5626 
5627  processSQLNamePattern(pset.db, &buf, pattern,
5628  false, false,
5629  NULL, "e.extname", NULL,
5630  NULL);
5631 
5632  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5633 
5634  res = PSQLexec(buf.data);
5635  termPQExpBuffer(&buf);
5636  if (!res)
5637  return false;
5638 
5639  if (PQntuples(res) == 0)
5640  {
5641  if (!pset.quiet)
5642  {
5643  if (pattern)
5644  pg_log_error("Did not find any extension named \"%s\".",
5645  pattern);
5646  else
5647  pg_log_error("Did not find any extensions.");
5648  }
5649  PQclear(res);
5650  return false;
5651  }
5652 
5653  for (i = 0; i < PQntuples(res); i++)
5654  {
5655  const char *extname;
5656  const char *oid;
5657 
5658  extname = PQgetvalue(res, i, 0);
5659  oid = PQgetvalue(res, i, 1);
5660 
5661  if (!listOneExtensionContents(extname, oid))
5662  {
5663  PQclear(res);
5664  return false;
5665  }
5666  if (cancel_pressed)
5667  {
5668  PQclear(res);
5669  return false;
5670  }
5671  }
5672 
5673  PQclear(res);
5674  return true;
5675 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
PsqlSettings pset
Definition: startup.c:31
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
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:827
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
static char * buf
Definition: pg_test_fsync.c:67
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:5678
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
void PQclear(PGresult *res)
Definition: fe-exec.c:694
int i
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listExtensions()

bool listExtensions ( const char *  pattern)

Definition at line 5549 of file describe.c.

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

Referenced by exec_command_d().

5550 {
5552  PGresult *res;
5553  printQueryOpt myopt = pset.popt;
5554 
5555  if (pset.sversion < 90100)
5556  {
5557  char sverbuf[32];
5558 
5559  pg_log_error("The server (version %s) does not support extensions.",
5561  sverbuf, sizeof(sverbuf)));
5562  return true;
5563  }
5564 
5565  initPQExpBuffer(&buf);
5566  printfPQExpBuffer(&buf,
5567  "SELECT e.extname AS \"%s\", "
5568  "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
5569  "FROM pg_catalog.pg_extension e "
5570  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
5571  "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
5572  "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
5573  gettext_noop("Name"),
5574  gettext_noop("Version"),
5575  gettext_noop("Schema"),
5576  gettext_noop("Description"));
5577 
5578  processSQLNamePattern(pset.db, &buf, pattern,
5579  false, false,
5580  NULL, "e.extname", NULL,
5581  NULL);
5582 
5583  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5584 
5585  res = PSQLexec(buf.data);
5586  termPQExpBuffer(&buf);
5587  if (!res)
5588  return false;
5589 
5590  myopt.nullPrint = NULL;
5591  myopt.title = _("List of installed extensions");
5592  myopt.translate_header = true;
5593 
5594  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5595 
5596  PQclear(res);
5597  return true;
5598 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 5245 of file describe.c.

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

5246 {
5248  PGresult *res;
5249  printQueryOpt myopt = pset.popt;
5250 
5251  if (pset.sversion < 80400)
5252  {
5253  char sverbuf[32];
5254 
5255  pg_log_error("The server (version %s) does not support foreign-data wrappers.",
5257  sverbuf, sizeof(sverbuf)));
5258  return true;
5259  }
5260 
5261  initPQExpBuffer(&buf);
5262  printfPQExpBuffer(&buf,
5263  "SELECT fdw.fdwname AS \"%s\",\n"
5264  " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
5265  gettext_noop("Name"),
5266  gettext_noop("Owner"));
5267  if (pset.sversion >= 90100)
5268  appendPQExpBuffer(&buf,
5269  " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
5270  gettext_noop("Handler"));
5271  appendPQExpBuffer(&buf,
5272  " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5273  gettext_noop("Validator"));
5274 
5275  if (verbose)
5276  {
5277  appendPQExpBufferStr(&buf, ",\n ");
5278  printACLColumn(&buf, "fdwacl");
5279  appendPQExpBuffer(&buf,
5280  ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5281  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5282  " pg_catalog.quote_ident(option_name) || ' ' || "
5283  " pg_catalog.quote_literal(option_value) FROM "
5284  " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5285  " END AS \"%s\"",
5286  gettext_noop("FDW options"));
5287 
5288  if (pset.sversion >= 90100)
5289  appendPQExpBuffer(&buf,
5290  ",\n d.description AS \"%s\" ",
5291  gettext_noop("Description"));
5292  }
5293 
5294  appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
5295 
5296  if (verbose && pset.sversion >= 90100)
5297  appendPQExpBufferStr(&buf,
5298  "LEFT JOIN pg_catalog.pg_description d\n"
5299  " ON d.classoid = fdw.tableoid "
5300  "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5301 
5302  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5303  NULL, "fdwname", NULL, NULL);
5304 
5305  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5306 
5307  res = PSQLexec(buf.data);
5308  termPQExpBuffer(&buf);
5309  if (!res)
5310  return false;
5311 
5312  myopt.nullPrint = NULL;
5313  myopt.title = _("List of foreign-data wrappers");
5314  myopt.translate_header = true;
5315 
5316  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5317 
5318  PQclear(res);
5319  return true;
5320 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listForeignServers()

bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 5328 of file describe.c.

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

5329 {
5331  PGresult *res;
5332  printQueryOpt myopt = pset.popt;
5333 
5334  if (pset.sversion < 80400)
5335  {
5336  char sverbuf[32];
5337 
5338  pg_log_error("The server (version %s) does not support foreign servers.",
5340  sverbuf, sizeof(sverbuf)));
5341  return true;
5342  }
5343 
5344  initPQExpBuffer(&buf);
5345  printfPQExpBuffer(&buf,
5346  "SELECT s.srvname AS \"%s\",\n"
5347  " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5348  " f.fdwname AS \"%s\"",
5349  gettext_noop("Name"),
5350  gettext_noop("Owner"),
5351  gettext_noop("Foreign-data wrapper"));
5352 
5353  if (verbose)
5354  {
5355  appendPQExpBufferStr(&buf, ",\n ");
5356  printACLColumn(&buf, "s.srvacl");
5357  appendPQExpBuffer(&buf,
5358  ",\n"
5359  " s.srvtype AS \"%s\",\n"
5360  " s.srvversion AS \"%s\",\n"
5361  " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5362  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5363  " pg_catalog.quote_ident(option_name) || ' ' || "
5364  " pg_catalog.quote_literal(option_value) FROM "
5365  " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
5366  " END AS \"%s\",\n"
5367  " d.description AS \"%s\"",
5368  gettext_noop("Type"),
5369  gettext_noop("Version"),
5370  gettext_noop("FDW options"),
5371  gettext_noop("Description"));
5372  }
5373 
5374  appendPQExpBufferStr(&buf,
5375  "\nFROM pg_catalog.pg_foreign_server s\n"
5376  " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
5377 
5378  if (verbose)
5379  appendPQExpBufferStr(&buf,
5380  "LEFT JOIN pg_catalog.pg_description d\n "
5381  "ON d.classoid = s.tableoid AND d.objoid = s.oid "
5382  "AND d.objsubid = 0\n");
5383 
5384  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5385  NULL, "s.srvname", NULL, NULL);
5386 
5387  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5388 
5389  res = PSQLexec(buf.data);
5390  termPQExpBuffer(&buf);
5391  if (!res)
5392  return false;
5393 
5394  myopt.nullPrint = NULL;
5395  myopt.title = _("List of foreign servers");
5396  myopt.translate_header = true;
5397 
5398  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5399 
5400  PQclear(res);
5401  return true;
5402 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listForeignTables()

bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 5471 of file describe.c.

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

Referenced by exec_command_d().

5472 {
5474  PGresult *res;
5475  printQueryOpt myopt = pset.popt;
5476 
5477  if (pset.sversion < 90100)
5478  {
5479  char sverbuf[32];
5480 
5481  pg_log_error("The server (version %s) does not support foreign tables.",
5483  sverbuf, sizeof(sverbuf)));
5484  return true;
5485  }
5486 
5487  initPQExpBuffer(&buf);
5488  printfPQExpBuffer(&buf,
5489  "SELECT n.nspname AS \"%s\",\n"
5490  " c.relname AS \"%s\",\n"
5491  " s.srvname AS \"%s\"",
5492  gettext_noop("Schema"),
5493  gettext_noop("Table"),
5494  gettext_noop("Server"));
5495 
5496  if (verbose)
5497  appendPQExpBuffer(&buf,
5498  ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
5499  " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5500  " pg_catalog.quote_ident(option_name) || ' ' || "
5501  " pg_catalog.quote_literal(option_value) FROM "
5502  " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
5503  " END AS \"%s\",\n"
5504  " d.description AS \"%s\"",
5505  gettext_noop("FDW options"),
5506  gettext_noop("Description"));
5507 
5508  appendPQExpBufferStr(&buf,
5509  "\nFROM pg_catalog.pg_foreign_table ft\n"
5510  " INNER JOIN pg_catalog.pg_class c"
5511  " ON c.oid = ft.ftrelid\n"
5512  " INNER JOIN pg_catalog.pg_namespace n"
5513  " ON n.oid = c.relnamespace\n"
5514  " INNER JOIN pg_catalog.pg_foreign_server s"
5515  " ON s.oid = ft.ftserver\n");
5516  if (verbose)
5517  appendPQExpBufferStr(&buf,
5518  " LEFT JOIN pg_catalog.pg_description d\n"
5519  " ON d.classoid = c.tableoid AND "
5520  "d.objoid = c.oid AND d.objsubid = 0\n");
5521 
5522  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5523  "n.nspname", "c.relname", NULL,
5524  "pg_catalog.pg_table_is_visible(c.oid)");
5525 
5526  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5527 
5528  res = PSQLexec(buf.data);
5529  termPQExpBuffer(&buf);
5530  if (!res)
5531  return false;
5532 
5533  myopt.nullPrint = NULL;
5534  myopt.title = _("List of foreign tables");
5535  myopt.translate_header = true;
5536 
5537  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5538 
5539  PQclear(res);
5540  return true;
5541 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listLanguages()

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

Definition at line 4073 of file describe.c.

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

Referenced by exec_command_d().

4074 {
4076  PGresult *res;
4077  printQueryOpt myopt = pset.popt;
4078 
4079  initPQExpBuffer(&buf);
4080 
4081  printfPQExpBuffer(&buf,
4082  "SELECT l.lanname AS \"%s\",\n",
4083  gettext_noop("Name"));
4084  if (pset.sversion >= 80300)
4085  appendPQExpBuffer(&buf,
4086  " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
4087  gettext_noop("Owner"));
4088 
4089  appendPQExpBuffer(&buf,
4090  " l.lanpltrusted AS \"%s\"",
4091  gettext_noop("Trusted"));
4092 
4093  if (verbose)
4094  {
4095  appendPQExpBuffer(&buf,
4096  ",\n NOT l.lanispl AS \"%s\",\n"
4097  " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4098  " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n ",
4099  gettext_noop("Internal language"),
4100  gettext_noop("Call handler"),
4101  gettext_noop("Validator"));
4102  if (pset.sversion >= 90000)
4103  appendPQExpBuffer(&buf, "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4104  gettext_noop("Inline handler"));
4105  printACLColumn(&buf, "l.lanacl");
4106  }
4107 
4108  appendPQExpBuffer(&buf,
4109  ",\n d.description AS \"%s\""
4110  "\nFROM pg_catalog.pg_language l\n"
4111  "LEFT JOIN pg_catalog.pg_description d\n"
4112  " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4113  " AND d.objsubid = 0\n",
4114  gettext_noop("Description"));
4115 
4116  if (pattern)
4117  processSQLNamePattern(pset.db, &buf, pattern, false, false,
4118  NULL, "l.lanname", NULL, NULL);
4119 
4120  if (!showSystem && !pattern)
4121  appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
4122 
4123 
4124  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4125 
4126  res = PSQLexec(buf.data);
4127  termPQExpBuffer(&buf);
4128  if (!res)
4129  return false;
4130 
4131  myopt.nullPrint = NULL;
4132  myopt.title = _("List of languages");
4133  myopt.translate_header = true;
4134 
4135  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4136 
4137  PQclear(res);
4138  return true;
4139 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listOperatorClasses()

bool listOperatorClasses ( const char *  access_method_pattern,
const char *  opclass_pattern,
bool  verbose 
)

Definition at line 6056 of file describe.c.

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

Referenced by exec_command_d().

6058 {
6060  PGresult *res;
6061  printQueryOpt myopt = pset.popt;
6062  bool have_where = false;
6063  static const bool translate_columns[] = {false, false, false, false, false, false, false};
6064 
6065  initPQExpBuffer(&buf);
6066 
6067  printfPQExpBuffer(&buf,
6068  "SELECT DISTINCT"
6069  " am.amname AS \"%s\",\n"
6070  " c.opcintype::pg_catalog.regtype AS \"%s\",\n"
6071  " (CASE WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6072  " THEN c.opckeytype\n"
6073  " ELSE NULL -- c.opcintype\n"
6074  " END)::pg_catalog.regtype AS \"%s\",\n"
6075  " CASE\n"
6076  " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6077  " THEN format('%%I', c.opcname)\n"
6078  " ELSE format('%%I.%%I', n.nspname, c.opcname)\n"
6079  " END AS \"%s\",\n"
6080  " (CASE WHEN c.opcdefault\n"
6081  " THEN '%s'\n"
6082  " ELSE '%s'\n"
6083  " END) AS \"%s\"",
6084  gettext_noop("AM"),
6085  gettext_noop("Input type"),
6086  gettext_noop("Storage type"),
6087  gettext_noop("Operator class"),
6088  gettext_noop("yes"),
6089  gettext_noop("no"),
6090  gettext_noop("Default?"));
6091  if (verbose)
6092  appendPQExpBuffer(&buf,
6093  ",\n CASE\n"
6094  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6095  " THEN format('%%I', of.opfname)\n"
6096  " ELSE format('%%I.%%I', ofn.nspname, of.opfname)\n"
6097  " END AS \"%s\",\n"
6098  " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6099  gettext_noop("Operator family"),
6100  gettext_noop("Owner"));
6101  appendPQExpBuffer(&buf,
6102  "\nFROM pg_catalog.pg_opclass c\n"
6103  " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6104  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6105  " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6106  );
6107  if (verbose)
6108  appendPQExpBuffer(&buf,
6109  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6110  " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6111 
6112  if (access_method_pattern)
6113  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6114  false, false, NULL, "am.amname", NULL, NULL);
6115  if (type_pattern)
6116  processSQLNamePattern(pset.db, &buf, type_pattern, have_where, false,
6117  NULL, "t.typname", NULL, NULL);
6118 
6119  appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
6120  res = PSQLexec(buf.data);
6121  termPQExpBuffer(&buf);
6122  if (!res)
6123  return false;
6124 
6125  myopt.nullPrint = NULL;
6126  myopt.title = _("List of operator classes");
6127  myopt.translate_header = true;
6128  myopt.translate_columns = translate_columns;
6129  myopt.n_translate_columns = lengthof(translate_columns);
6130 
6131  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6132 
6133  PQclear(res);
6134  return true;
6135 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listOperatorFamilies()

bool listOperatorFamilies ( const char *  access_method_pattern,
const char *  opclass_pattern,
bool  verbose 
)

Definition at line 6144 of file describe.c.

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

Referenced by exec_command_d().

6146 {
6148  PGresult *res;
6149  printQueryOpt myopt = pset.popt;
6150  bool have_where = false;
6151  static const bool translate_columns[] = {false, false, false, false};
6152 
6153  initPQExpBuffer(&buf);
6154 
6155  printfPQExpBuffer(&buf,
6156  "SELECT DISTINCT"
6157  " am.amname AS \"%s\",\n"
6158  " CASE\n"
6159  " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
6160  " THEN format('%%I', f.opfname)\n"
6161  " ELSE format('%%I.%%I', n.nspname, f.opfname)\n"
6162  " END AS \"%s\",\n"
6163  " (SELECT\n"
6164  " string_agg(format_type(oc.opcintype, -1), ', ')\n"
6165  " FROM pg_opclass oc\n"
6166  " WHERE oc.opcfamily = f.oid) \"%s\"",
6167  gettext_noop("AM"),
6168  gettext_noop("Operator family"),
6169  gettext_noop("Applicable types"));
6170  if (verbose)
6171  appendPQExpBuffer(&buf,
6172  ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
6173  gettext_noop("Owner"));
6174  appendPQExpBuffer(&buf,
6175  "\nFROM pg_catalog.pg_opfamily f\n"
6176  " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
6177  " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n"
6178  );
6179 
6180  if (access_method_pattern)
6181  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6182  false, false, NULL, "am.amname", NULL, NULL);
6183  if (type_pattern)
6184  {
6185  appendPQExpBuffer(&buf,
6186  "\n %s EXISTS (\n"
6187  " SELECT 1\n"
6188  " FROM pg_type t\n"
6189  " JOIN pg_opclass oc ON oc.opcintype = t.oid\n"
6190  " WHERE oc.opcfamily = f.oid",
6191  have_where ? "AND" : "WHERE");
6192  processSQLNamePattern(pset.db, &buf, type_pattern, true, false,
6193  NULL, "t.typname", NULL, NULL);
6194  appendPQExpBuffer(&buf, ")");
6195  }
6196 
6197  appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6198  res = PSQLexec(buf.data);
6199  termPQExpBuffer(&buf);
6200  if (!res)
6201  return false;
6202 
6203  myopt.nullPrint = NULL;
6204  myopt.title = _("List of operator families");
6205  myopt.translate_header = true;
6206  myopt.translate_columns = translate_columns;
6207  myopt.n_translate_columns = lengthof(translate_columns);
6208 
6209  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6210 
6211  PQclear(res);
6212  return true;
6213 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listOpFamilyFunctions()

bool listOpFamilyFunctions ( const char *  access_method_pattern,
const char *  family_pattern 
)

Definition at line 6319 of file describe.c.

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

Referenced by exec_command_d().

6321 {
6323  PGresult *res;
6324  printQueryOpt myopt = pset.popt;
6325  bool have_where = false;
6326  static const bool translate_columns[] = {false, false, false, false, false, false};
6327 
6328  initPQExpBuffer(&buf);
6329 
6330  printfPQExpBuffer(&buf,
6331  "SELECT\n"
6332  " am.amname AS \"%s\",\n"
6333  " CASE\n"
6334  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6335  " THEN format('%%I', of.opfname)\n"
6336  " ELSE format('%%I.%%I', ns.nspname, of.opfname)\n"
6337  " END AS \"%s\",\n"
6338  " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
6339  " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
6340  " ap.amprocnum AS \"%s\"\n,"
6341  " p.proname AS \"%s\"\n",
6342  gettext_noop("AM"),
6343  gettext_noop("Operator family"),
6344  gettext_noop("Left arg type"),
6345  gettext_noop("Right arg type"),
6346  gettext_noop("Number"),
6347  gettext_noop("Function"));
6348 
6349  appendPQExpBuffer(&buf,
6350  "FROM pg_catalog.pg_amproc ap\n"
6351  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
6352  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
6353  " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
6354  " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
6355 
6356  if (access_method_pattern)
6357  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6358  false, false, NULL, "am.amname",
6359  NULL, NULL);
6360  if (family_pattern)
6361  processSQLNamePattern(pset.db, &buf, family_pattern, have_where, false,
6362  "ns.nspname", "of.opfname", NULL, NULL);
6363 
6364  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6365  " ap.amproclefttype = ap.amprocrighttype DESC,\n"
6366  " 3, 4, 5;");
6367 
6368  res = PSQLexec(buf.data);
6369  termPQExpBuffer(&buf);
6370  if (!res)
6371  return false;
6372 
6373  myopt.nullPrint = NULL;
6374  myopt.title = _("List of support functions of operator families");
6375  myopt.translate_header = true;
6376  myopt.translate_columns = translate_columns;
6377  myopt.n_translate_columns = lengthof(translate_columns);
6378 
6379  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6380 
6381  PQclear(res);
6382  return true;
6383 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listOpFamilyOperators()

bool listOpFamilyOperators ( const char *  accessMethod_pattern,
const char *  family_pattern,
bool  verbose 
)

Definition at line 6223 of file describe.c.

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

Referenced by exec_command_d().

6225 {
6227  PGresult *res;
6228  printQueryOpt myopt = pset.popt;
6229  bool have_where = false;
6230 
6231  static const bool translate_columns[] = {false, false, false, false, false, false};
6232 
6233  initPQExpBuffer(&buf);
6234 
6235  printfPQExpBuffer(&buf,
6236  "SELECT\n"
6237  " am.amname AS \"%s\",\n"
6238  " CASE\n"
6239  " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6240  " THEN format('%%I', of.opfname)\n"
6241  " ELSE format('%%I.%%I', nsf.nspname, of.opfname)\n"
6242  " END AS \"%s\",\n"
6243  " format ('%%s (%%s, %%s)',\n"
6244  " CASE\n"
6245  " WHEN pg_catalog.pg_operator_is_visible(op.oid) \n"
6246  " THEN op.oprname::pg_catalog.text \n"
6247  " ELSE o.amopopr::pg_catalog.regoper::pg_catalog.text \n"
6248  " END,\n"
6249  " pg_catalog.format_type(o.amoplefttype, NULL),\n"
6250  " pg_catalog.format_type(o.amoprighttype, NULL)\n"
6251  " ) AS \"%s\"\n",
6252  gettext_noop("AM"),
6253  gettext_noop("Operator family"),
6254  gettext_noop("Operator"));
6255 
6256  if (verbose)
6257  appendPQExpBuffer(&buf,
6258  ", o.amopstrategy AS \"%s\",\n"
6259  " CASE o.amoppurpose\n"
6260  " WHEN 'o' THEN '%s'\n"
6261  " WHEN 's' THEN '%s'\n"
6262  " END AS \"%s\",\n"
6263  " ofs.opfname AS \"%s\"\n",
6264  gettext_noop("Strategy"),
6265  gettext_noop("ordering"),
6266  gettext_noop("search"),
6267  gettext_noop("Purpose"),
6268  gettext_noop("Sort opfamily"));
6269  appendPQExpBuffer(&buf,
6270  "FROM pg_catalog.pg_amop o\n"
6271  " LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
6272  " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
6273  " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
6274  " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
6275  if (verbose)
6276  appendPQExpBuffer(&buf,
6277  " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n");
6278 
6279  if (access_method_pattern)
6280  have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
6281  false, false, NULL, "am.amname",
6282  NULL, NULL);
6283 
6284  if (family_pattern)
6285  processSQLNamePattern(pset.db, &buf, family_pattern, have_where, false,
6286  "nsf.nspname", "of.opfname", NULL, NULL);
6287 
6288  appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
6289  " o.amoplefttype = o.amoprighttype DESC,\n"
6290  " pg_catalog.format_type(o.amoplefttype, NULL),\n"
6291  " pg_catalog.format_type(o.amoprighttype, NULL),\n"
6292  " o.amopstrategy;");
6293 
6294  res = PSQLexec(buf.data);
6295  termPQExpBuffer(&buf);
6296  if (!res)
6297  return false;
6298 
6299  myopt.nullPrint = NULL;
6300  myopt.title = _("List of operators of operator families");
6301  myopt.translate_header = true;
6302  myopt.translate_columns = translate_columns;
6303  myopt.n_translate_columns = lengthof(translate_columns);
6304 
6305  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6306 
6307  PQclear(res);
6308  return true;
6309 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listPartitionedTables()

bool listPartitionedTables ( const char *  reltypes,
const char *  pattern,
bool  verbose 
)

Definition at line 3869 of file describe.c.

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

Referenced by exec_command_d().

3870 {
3871  bool showTables = strchr(reltypes, 't') != NULL;
3872  bool showIndexes = strchr(reltypes, 'i') != NULL;
3873  bool showNested = strchr(reltypes, 'n') != NULL;
3875  PQExpBufferData title;
3876  PGresult *res;
3877  printQueryOpt myopt = pset.popt;
3878  bool translate_columns[] = {false, false, false, false, false, false, false, false, false};
3879  const char *tabletitle;
3880  bool mixed_output = false;
3881 
3882  /*
3883  * Note: Declarative table partitioning is only supported as of Pg 10.0.
3884  */
3885  if (pset.sversion < 100000)
3886  {
3887  char sverbuf[32];
3888 
3889  pg_log_error("The server (version %s) does not support declarative table partitioning.",
3891  sverbuf, sizeof(sverbuf)));
3892  return true;
3893  }
3894 
3895  /* If no relation kind was selected, show them all */
3896  if (!showTables && !showIndexes)
3897  showTables = showIndexes = true;
3898 
3899  if (showIndexes && !showTables)
3900  tabletitle = _("List of partitioned indexes"); /* \dPi */
3901  else if (showTables && !showIndexes)
3902  tabletitle = _("List of partitioned tables"); /* \dPt */
3903  else
3904  {
3905  /* show all kinds */
3906  tabletitle = _("List of partitioned relations");
3907  mixed_output = true;
3908  }
3909 
3910  initPQExpBuffer(&buf);
3911 
3912  printfPQExpBuffer(&buf,
3913  "SELECT n.nspname as \"%s\",\n"
3914  " c.relname as \"%s\",\n"
3915  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3916  gettext_noop("Schema"),
3917  gettext_noop("Name"),
3918  gettext_noop("Owner"));
3919 
3920  if (mixed_output)
3921  {
3922  appendPQExpBuffer(&buf,
3923  ",\n CASE c.relkind"
3924  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3925  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
3926  " END as \"%s\"",
3927  gettext_noop("partitioned table"),
3928  gettext_noop("partitioned index"),
3929  gettext_noop("Type"));
3930 
3931  translate_columns[3] = true;
3932  }
3933 
3934  if (showNested || pattern)
3935  appendPQExpBuffer(&buf,
3936  ",\n inh.inhparent::regclass as \"%s\"",
3937  gettext_noop("Parent name"));
3938 
3939  if (showIndexes)
3940  appendPQExpBuffer(&buf,
3941  ",\n c2.oid::regclass as \"%s\"",
3942  gettext_noop("Table"));
3943 
3944  if (verbose)
3945  {
3946  if (showNested)
3947  {
3948  appendPQExpBuffer(&buf,
3949  ",\n s.dps as \"%s\"",
3950  gettext_noop("Leaf partition size"));
3951  appendPQExpBuffer(&buf,
3952  ",\n s.tps as \"%s\"",
3953  gettext_noop("Total size"));
3954  }
3955  else
3956  /* Sizes of all partitions are considered in this case. */
3957  appendPQExpBuffer(&buf,
3958  ",\n s.tps as \"%s\"",
3959  gettext_noop("Total size"));
3960 
3961  appendPQExpBuffer(&buf,
3962  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3963  gettext_noop("Description"));
3964  }
3965 
3966  appendPQExpBufferStr(&buf,
3967  "\nFROM pg_catalog.pg_class c"
3968  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3969 
3970  if (showIndexes)
3971  appendPQExpBufferStr(&buf,
3972  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3973  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3974 
3975  if (showNested || pattern)
3976  appendPQExpBufferStr(&buf,
3977  "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
3978 
3979  if (verbose)
3980  {
3981  if (pset.sversion < 120000)
3982  {
3983  appendPQExpBufferStr(&buf,
3984  ",\n LATERAL (WITH RECURSIVE d\n"
3985  " AS (SELECT inhrelid AS oid, 1 AS level\n"
3986  " FROM pg_catalog.pg_inherits\n"
3987  " WHERE inhparent = c.oid\n"
3988  " UNION ALL\n"
3989  " SELECT inhrelid, level + 1\n"
3990  " FROM pg_catalog.pg_inherits i\n"
3991  " JOIN d ON i.inhparent = d.oid)\n"
3992  " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
3993  "d.oid))) AS tps,\n"
3994  " pg_catalog.pg_size_pretty(sum("
3995  "\n CASE WHEN d.level = 1"
3996  " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
3997  " FROM d) s");
3998  }
3999  else
4000  {
4001  /* PostgreSQL 12 has pg_partition_tree function */
4002  appendPQExpBufferStr(&buf,
4003  ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4004  "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4005  "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4006  " ELSE 0 END)) AS dps"
4007  ",\n pg_catalog.pg_size_pretty(sum("
4008  "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4009  "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4010  }
4011  }
4012 
4013  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4014  if (showTables)
4015  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
4016  if (showIndexes)
4017  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
4018  appendPQExpBufferStr(&buf, "''"); /* dummy */
4019  appendPQExpBufferStr(&buf, ")\n");
4020 
4021  appendPQExpBufferStr(&buf, !showNested && !pattern ?
4022  " AND NOT c.relispartition\n" : "");
4023 
4024  if (!pattern)
4025  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4026  " AND n.nspname <> 'information_schema'\n");
4027 
4028  /*
4029  * TOAST objects are suppressed unconditionally. Since we don't provide
4030  * any way to select RELKIND_TOASTVALUE above, we would never show toast
4031  * tables in any case; it seems a bit confusing to allow their indexes to
4032  * be shown. Use plain \d if you really need to look at a TOAST
4033  * table/index.
4034  */
4035  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
4036 
4037  processSQLNamePattern(pset.db, &buf, pattern, true, false,
4038  "n.nspname", "c.relname", NULL,
4039  "pg_catalog.pg_table_is_visible(c.oid)");
4040 
4041  appendPQExpBuffer(&buf, "ORDER BY \"Schema\", %s%s\"Name\";",
4042  mixed_output ? "\"Type\" DESC, " : "",
4043  showNested || pattern ? "\"Parent name\" NULLS FIRST, " : "");
4044 
4045  res = PSQLexec(buf.data);
4046  termPQExpBuffer(&buf);
4047  if (!res)
4048  return false;
4049 
4050  initPQExpBuffer(&title);
4051  appendPQExpBufferStr(&title, tabletitle);
4052 
4053  myopt.nullPrint = NULL;
4054  myopt.title = title.data;
4055  myopt.translate_header = true;
4056  myopt.translate_columns = translate_columns;
4057  myopt.n_translate_columns = lengthof(translate_columns);
4058 
4059  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4060 
4061  termPQExpBuffer(&title);
4062 
4063  PQclear(res);
4064  return true;
4065 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
#define CppAsString2(x)
Definition: c.h:222
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listPublications()

bool listPublications ( const char *  pattern)

Definition at line 5719 of file describe.c.

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

Referenced by exec_command_d().

5720 {
5722  PGresult *res;
5723  printQueryOpt myopt = pset.popt;
5724  static const bool translate_columns[] = {false, false, false, false, false, false, false, false};
5725 
5726  if (pset.sversion < 100000)
5727  {
5728  char sverbuf[32];
5729 
5730  pg_log_error("The server (version %s) does not support publications.",
5732  sverbuf, sizeof(sverbuf)));
5733  return true;
5734  }
5735 
5736  initPQExpBuffer(&buf);
5737 
5738  printfPQExpBuffer(&buf,
5739  "SELECT pubname AS \"%s\",\n"
5740  " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5741  " puballtables AS \"%s\",\n"
5742  " pubinsert AS \"%s\",\n"
5743  " pubupdate AS \"%s\",\n"
5744  " pubdelete AS \"%s\"",
5745  gettext_noop("Name"),
5746  gettext_noop("Owner"),
5747  gettext_noop("All tables"),
5748  gettext_noop("Inserts"),
5749  gettext_noop("Updates"),
5750  gettext_noop("Deletes"));
5751  if (pset.sversion >= 110000)
5752  appendPQExpBuffer(&buf,
5753  ",\n pubtruncate AS \"%s\"",
5754  gettext_noop("Truncates"));
5755  if (pset.sversion >= 130000)
5756  appendPQExpBuffer(&buf,
5757  ",\n pubviaroot AS \"%s\"",
5758  gettext_noop("Via root"));
5759 
5760  appendPQExpBufferStr(&buf,
5761  "\nFROM pg_catalog.pg_publication\n");
5762 
5763  processSQLNamePattern(pset.db, &buf, pattern, false, false,
5764  NULL, "pubname", NULL,
5765  NULL);
5766 
5767  appendPQExpBufferStr(&buf, "ORDER BY 1;");
5768 
5769  res = PSQLexec(buf.data);
5770  termPQExpBuffer(&buf);
5771  if (!res)
5772  return false;
5773 
5774  myopt.nullPrint = NULL;
5775  myopt.title = _("List of publications");
5776  myopt.translate_header = true;
5777  myopt.translate_columns = translate_columns;
5778  myopt.n_translate_columns = lengthof(translate_columns);
5779 
5780  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5781 
5782  PQclear(res);
5783 
5784  return true;
5785 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listSchemas()

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

Definition at line 4593 of file describe.c.

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

Referenced by exec_command_d().

4594 {
4596  PGresult *res;
4597  printQueryOpt myopt = pset.popt;
4598 
4599  initPQExpBuffer(&buf);
4600  printfPQExpBuffer(&buf,
4601  "SELECT n.nspname AS \"%s\",\n"
4602  " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4603  gettext_noop("Name"),
4604  gettext_noop("Owner"));
4605 
4606  if (verbose)
4607  {
4608  appendPQExpBufferStr(&buf, ",\n ");
4609  printACLColumn(&buf, "n.nspacl");
4610  appendPQExpBuffer(&buf,
4611  ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4612  gettext_noop("Description"));
4613  }
4614 
4615  appendPQExpBufferStr(&buf,
4616  "\nFROM pg_catalog.pg_namespace n\n");
4617 
4618  if (!showSystem && !pattern)
4619  appendPQExpBufferStr(&buf,
4620  "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
4621 
4622  processSQLNamePattern(pset.db, &buf, pattern,
4623  !showSystem && !pattern, false,
4624  NULL, "n.nspname", NULL,
4625  NULL);
4626 
4627  appendPQExpBufferStr(&buf, "ORDER BY 1;");
4628 
4629  res = PSQLexec(buf.data);
4630  termPQExpBuffer(&buf);
4631  if (!res)
4632  return false;
4633 
4634  myopt.nullPrint = NULL;
4635  myopt.title = _("List of schemas");
4636  myopt.translate_header = true;
4637 
4638  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4639 
4640  PQclear(res);
4641  return true;
4642 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6037
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult * PSQLexec(const char *query)
Definition: common.c:536

◆ listTables()

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

Definition at line 3668 of file describe.c.

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

Referenced by exec_command_d().

3669 {
3670  bool showTables = strchr(tabtypes, 't') != NULL;
3671  bool showIndexes = strchr(tabtypes, 'i') != NULL;
3672  bool showViews = strchr(tabtypes, 'v') != NULL;
3673  bool showMatViews = strchr(tabtypes, 'm') != NULL;
3674  bool showSeq = strchr(tabtypes, 's') != NULL;
3675  bool showForeign = strchr(tabtypes, 'E') != NULL;
3676 
3678  PGresult *res;
3679  printQueryOpt myopt = pset.popt;
3680  int cols_so_far;
3681  bool translate_columns[] = {false, false, true, false, false, false, false, false};
3682 
3683  /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
3684  if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3685  showTables = showViews = showMatViews = showSeq = showForeign = true;
3686 
3687  initPQExpBuffer(&buf);
3688 
3689  /*
3690  * Note: as of Pg 8.2, we no longer use relkind 's' (special), but we keep
3691  * it here for backwards compatibility.
3692  */
3693  printfPQExpBuffer(&buf,
3694  "SELECT n.nspname as \"%s\",\n"
3695  " c.relname as \"%s\",\n"
3696  " CASE c.relkind"
3697  " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
3698  " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
3699  " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
3700  " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
3701  " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
3702  " WHEN 's' THEN '%s'"
3703  " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
3704  " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
3705  " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
3706  " END as \"%s\",\n"
3707  " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3708  gettext_noop("Schema"),
3709  gettext_noop("Name"),
3710  gettext_noop("table"),
3711  gettext_noop("view"),
3712  gettext_noop("materialized view"),
3713  gettext_noop("index"),
3714  gettext_noop("sequence"),
3715  gettext_noop("special"),
3716  gettext_noop("foreign table"),
3717  gettext_noop("partitioned table"),
3718  gettext_noop("partitioned index"),
3719  gettext_noop("Type"),
3720  gettext_noop("Owner"));
3721  cols_so_far = 4;
3722 
3723  if (showIndexes)
3724  {
3725  appendPQExpBuffer(&buf,
3726  ",\n c2.relname as \"%s\"",
3727  gettext_noop("Table"));
3728  cols_so_far++;
3729  }
3730 
3731  if (verbose)
3732  {
3733  /*
3734  * Show whether a relation is permanent, temporary, or unlogged. Like
3735  * describeOneTableDetails(), we consider that persistence emerged in
3736  * v9.1, even though related concepts existed before.
3737  */
3738  if (pset.sversion >= 90100)
3739  {
3740  appendPQExpBuffer(&buf,
3741  ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3742  gettext_noop("permanent"),
3743  gettext_noop("temporary"),
3744  gettext_noop("unlogged"),
3745  gettext_noop("Persistence"));
3746  translate_columns[cols_so_far] = true;
3747  }
3748 
3749  /*
3750  * We don't bother to count cols_so_far below here, as there's no need
3751  * to; this might change with future additions to the output columns.
3752  */
3753 
3754  /*
3755  * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
3756  * size of a table, including FSM, VM and TOAST tables.
3757  */
3758  if (pset.sversion >= 90000)
3759  appendPQExpBuffer(&buf,
3760  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
3761  gettext_noop("Size"));
3762  else if (pset.sversion >= 80100)
3763  appendPQExpBuffer(&buf,
3764  ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
3765  gettext_noop("Size"));
3766 
3767  appendPQExpBuffer(&buf,
3768  ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3769  gettext_noop("Description"));
3770  }
3771 
3772  appendPQExpBufferStr(&buf,
3773  "\nFROM pg_catalog.pg_class c"
3774  "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3775  if (showIndexes)
3776  appendPQExpBufferStr(&buf,
3777  "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3778  "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3779 
3780  appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
3781  if (showTables)
3782  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
3783  CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
3784  if (showViews)
3785  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
3786  if (showMatViews)
3787  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_MATVIEW) ",");
3788  if (showIndexes)
3789  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_INDEX) ","
3790  CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
3791  if (showSeq)
3792  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ",");
3793  if (showSystem || pattern)
3794  appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
3795  if (showForeign)
3796  appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ",");
3797 
3798  appendPQExpBufferStr(&buf, "''"); /* dummy */
3799  appendPQExpBufferStr(&buf, ")\n");
3800 
3801  if (!showSystem && !pattern)
3802  appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3803  " AND n.nspname <> 'information_schema'\n");
3804 
3805  /*
3806  * TOAST objects are suppressed unconditionally. Since we don't provide
3807  * any way to select RELKIND_TOASTVALUE above, we would never show toast
3808  * tables in any case; it seems a bit confusing to allow their indexes to
3809  * be shown. Use plain \d if you really need to look at a TOAST
3810  * table/index.
3811  */
3812  appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
3813 
3814  processSQLNamePattern(pset.db, &buf, pattern, true, false,
3815  "n.nspname", "c.relname", NULL,
3816  "pg_catalog.pg_table_is_visible(c.oid)");
3817 
3818  appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
3819 
3820  res = PSQLexec(buf.data);
3821  termPQExpBuffer(&buf);
3822  if (!res)
3823  return false;
3824 
3825  /*
3826  * Most functions in this file are content to print an empty table when
3827  * there are no matching objects. We intentionally deviate from that
3828  * here, but only in !quiet mode, for historical reasons.
3829  */
3830  if (PQntuples(res) == 0 && !pset.quiet)
3831  {
3832  if (pattern)
3833  pg_log_error("Did not find any relation named \"%s\".",
3834  pattern);
3835  else
3836  pg_log_error("Did not find any relations.");
3837  }
3838  else
3839  {
3840  myopt.nullPrint = NULL;
3841  myopt.title = _("List of relations");
3842  myopt.translate_header = true;
3843  myopt.translate_columns = translate_columns;
3844  myopt.n_translate_columns = lengthof(translate_columns);
3845 
3846  printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3847  }
3848 
3849  PQclear(res);
3850  return true;
3851 }
PGconn * db
Definition: settings.h:82
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * nullPrint
Definition: print.h:170
PsqlSettings pset
Definition: startup.c:31
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:79
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
#define gettext_noop(x)
Definition: c.h:1159
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:827
#define lengthof(array)
Definition: c.h:668
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
static char * buf
Definition: pg_test_fsync.c:67
bool translate_header
Definition: print.h:173
static int verbose
#define CppAsString2(x)
Definition: c.h:222
FILE * logfile
Definition: settings.h:116
void PQclear(PGresult *res)
Definition: fe-exec.c:694
char * title
Definition: print.h:171
printQueryOpt popt
Definition: settings.h:91
int n_translate_columns
Definition: print.h:176
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3417
const bool * translate_columns
Definition: print.h:174
#define _(x)
Definition: elog.c:88
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
PGresult *