PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 *func_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
 
bool describeTypes (const char *pattern, bool verbose, bool showSystem)
 
bool describeOperators (const char *oper_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
 
bool describeRoles (const char *pattern, bool verbose, bool showSystem)
 
bool listDbRoleSettings (const char *pattern, const char *pattern2)
 
bool describeRoleGrants (const char *pattern, bool showSystem)
 
bool permissionsList (const char *pattern, bool showSystem)
 
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 describeConfigurationParameters (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 listExtendedStats (const char *pattern, bool verbose)
 
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 *type_pattern, bool verbose)
 
bool listOperatorFamilies (const char *access_method_pattern, const char *type_pattern, bool verbose)
 
bool listOpFamilyOperators (const char *access_method_pattern, const char *family_pattern, bool verbose)
 
bool listOpFamilyFunctions (const char *access_method_pattern, const char *family_pattern, bool verbose)
 
bool listLargeObjects (bool verbose)
 

Function Documentation

◆ describeAccessMethods()

bool describeAccessMethods ( const char pattern,
bool  verbose 
)
extern

Definition at line 150 of file describe.c.

151{
153 PGresult *res;
155 static const bool translate_columns[] = {false, true, false, false};
156
158
159 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching access methods"));
161 "SELECT amname AS \"%s\",\n"
162 " CASE amtype"
163 " WHEN " CppAsString2(AMTYPE_INDEX) " THEN '%s'"
164 " WHEN " CppAsString2(AMTYPE_TABLE) " THEN '%s'"
165 " END AS \"%s\"",
166 gettext_noop("Name"),
167 gettext_noop("Index"),
168 gettext_noop("Table"),
169 gettext_noop("Type"));
170
171 if (verbose)
172 {
174 ",\n amhandler AS \"%s\",\n"
175 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
176 gettext_noop("Handler"),
177 gettext_noop("Description"));
178 }
179
181 "\nFROM pg_catalog.pg_am\n");
182
183 if (!validateSQLNamePattern(&buf, pattern, false, false,
184 NULL, "amname", NULL,
185 NULL,
186 NULL, 1))
187 {
189 return false;
190 }
191
192 appendPQExpBufferStr(&buf, "ORDER BY 1;");
193
194 res = PSQLexec(buf.data);
196 if (!res)
197 return false;
198
199 myopt.title = _("List of access methods");
200 myopt.translate_header = true;
201 myopt.translate_columns = translate_columns;
202 myopt.n_translate_columns = lengthof(translate_columns);
203
204 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
205
206 PQclear(res);
207 return true;
208}
PGresult * PSQLexec(const char *query)
Definition common.c:657
#define gettext_noop(x)
Definition c.h:1344
#define CppAsString2(x)
Definition c.h:565
#define lengthof(array)
Definition c.h:932
static bool validateSQLNamePattern(PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, bool *added_clause, int maxparts)
Definition describe.c:6428
#define _(x)
Definition elog.c:96
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition print.c:3760
#define PQclear
static int verbose
static char buf[DEFAULT_XLOG_SEG_SIZE]
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
Definition pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
static int fb(int x)
PsqlSettings pset
Definition startup.c:33
printQueryOpt popt
Definition settings.h:112
FILE * logfile
Definition settings.h:149
FILE * queryFout
Definition settings.h:105

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ describeAggregates()

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

Definition at line 79 of file describe.c.

80{
82 PGresult *res;
84
86
87 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching aggregates"));
89 "SELECT n.nspname as \"%s\",\n"
90 " p.proname AS \"%s\",\n"
91 " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n"
92 " CASE WHEN p.pronargs = 0\n"
93 " THEN CAST('*' AS pg_catalog.text)\n"
94 " ELSE pg_catalog.pg_get_function_arguments(p.oid)\n"
95 " END AS \"%s\",\n",
96 gettext_noop("Schema"),
97 gettext_noop("Name"),
98 gettext_noop("Result data type"),
99 gettext_noop("Argument data types"));
100
101 if (pset.sversion >= 110000)
103 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
104 "FROM pg_catalog.pg_proc p\n"
105 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
106 "WHERE p.prokind = " CppAsString2(PROKIND_AGGREGATE) "\n",
107 gettext_noop("Description"));
108 else
110 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
111 "FROM pg_catalog.pg_proc p\n"
112 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
113 "WHERE p.proisagg\n",
114 gettext_noop("Description"));
115
116 if (!showSystem && !pattern)
117 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
118 " AND n.nspname <> 'information_schema'\n");
119
120 if (!validateSQLNamePattern(&buf, pattern, true, false,
121 "n.nspname", "p.proname", NULL,
122 "pg_catalog.pg_function_is_visible(p.oid)",
123 NULL, 3))
124 {
126 return false;
127 }
128
129 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
130
131 res = PSQLexec(buf.data);
133 if (!res)
134 return false;
135
136 myopt.title = _("List of aggregate functions");
137 myopt.translate_header = true;
138
139 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
140
141 PQclear(res);
142 return true;
143}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ describeConfigurationParameters()

bool describeConfigurationParameters ( const char pattern,
bool  verbose,
bool  showSystem 
)
extern

Definition at line 4780 of file describe.c.

4782{
4784 PGresult *res;
4786
4788
4789 printfPQExpBuffer(&buf, "/* %s */\n",
4790 _("Get matching configuration parameters"));
4792 "SELECT s.name AS \"%s\", "
4793 "pg_catalog.current_setting(s.name) AS \"%s\"",
4794 gettext_noop("Parameter"),
4795 gettext_noop("Value"));
4796
4797 if (verbose)
4798 {
4800 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4801 gettext_noop("Type"),
4802 gettext_noop("Context"));
4803 if (pset.sversion >= 150000)
4804 printACLColumn(&buf, "p.paracl");
4805 else
4806 appendPQExpBuffer(&buf, "NULL AS \"%s\"",
4807 gettext_noop("Access privileges"));
4808 }
4809
4810 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_settings s\n");
4811
4812 if (verbose && pset.sversion >= 150000)
4814 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4815 " ON pg_catalog.lower(s.name) = p.parname\n");
4816
4817 if (pattern)
4818 processSQLNamePattern(pset.db, &buf, pattern,
4819 false, false,
4820 NULL, "pg_catalog.lower(s.name)", NULL,
4821 NULL, NULL, NULL);
4822 else
4823 appendPQExpBufferStr(&buf, "WHERE s.source <> 'default' AND\n"
4824 " s.setting IS DISTINCT FROM s.boot_val\n");
4825
4826 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4827
4828 res = PSQLexec(buf.data);
4830 if (!res)
4831 return false;
4832
4833 if (pattern)
4834 myopt.title = _("List of configuration parameters");
4835 else
4836 myopt.title = _("List of non-default configuration parameters");
4837 myopt.translate_header = true;
4838
4839 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4840
4841 PQclear(res);
4842 return true;
4843}
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition describe.c:7018
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, PQExpBuffer dbnamebuf, int *dotcnt)
PGconn * db
Definition settings.h:103

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, _psqlSettings::db, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), and verbose.

Referenced by exec_command_d().

◆ describeFunctions()

bool describeFunctions ( const char functypes,
const char func_pattern,
char **  arg_patterns,
int  num_arg_patterns,
bool  verbose,
bool  showSystem 
)
extern

Definition at line 289 of file describe.c.

292{
293 const char *df_options = "anptwSx+";
294 bool showAggregate = strchr(functypes, 'a') != NULL;
295 bool showNormal = strchr(functypes, 'n') != NULL;
296 bool showProcedure = strchr(functypes, 'p') != NULL;
297 bool showTrigger = strchr(functypes, 't') != NULL;
298 bool showWindow = strchr(functypes, 'w') != NULL;
299 bool have_where;
301 PGresult *res;
303 static const bool translate_columns[] = {false, false, false, false, true, true, true, false, true, true, false, false, false, false};
304
306 {
307 pg_log_error("\\df only takes [%s] as options", df_options);
308 return true;
309 }
310
311 if (showProcedure && pset.sversion < 110000)
312 {
313 char sverbuf[32];
314
315 pg_log_error("\\df does not take a \"%c\" option with server version %s",
316 'p',
318 sverbuf, sizeof(sverbuf)));
319 return true;
320 }
321
323 {
325 if (pset.sversion >= 110000)
326 showProcedure = true;
327 }
328
330
331 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching functions"));
333 "SELECT n.nspname as \"%s\",\n"
334 " p.proname as \"%s\",\n",
335 gettext_noop("Schema"),
336 gettext_noop("Name"));
337
338 if (pset.sversion >= 110000)
340 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
341 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
342 " CASE p.prokind\n"
343 " WHEN " CppAsString2(PROKIND_AGGREGATE) " THEN '%s'\n"
344 " WHEN " CppAsString2(PROKIND_WINDOW) " THEN '%s'\n"
345 " WHEN " CppAsString2(PROKIND_PROCEDURE) " THEN '%s'\n"
346 " ELSE '%s'\n"
347 " END as \"%s\"",
348 gettext_noop("Result data type"),
349 gettext_noop("Argument data types"),
350 /* translator: "agg" is short for "aggregate" */
351 gettext_noop("agg"),
352 gettext_noop("window"),
353 gettext_noop("proc"),
354 gettext_noop("func"),
355 gettext_noop("Type"));
356 else
358 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
359 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
360 " CASE\n"
361 " WHEN p.proisagg THEN '%s'\n"
362 " WHEN p.proiswindow THEN '%s'\n"
363 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
364 " ELSE '%s'\n"
365 " END as \"%s\"",
366 gettext_noop("Result data type"),
367 gettext_noop("Argument data types"),
368 /* translator: "agg" is short for "aggregate" */
369 gettext_noop("agg"),
370 gettext_noop("window"),
371 gettext_noop("trigger"),
372 gettext_noop("func"),
373 gettext_noop("Type"));
374
375 if (verbose)
376 {
378 ",\n CASE\n"
379 " WHEN p.provolatile = "
380 CppAsString2(PROVOLATILE_IMMUTABLE) " THEN '%s'\n"
381 " WHEN p.provolatile = "
382 CppAsString2(PROVOLATILE_STABLE) " THEN '%s'\n"
383 " WHEN p.provolatile = "
384 CppAsString2(PROVOLATILE_VOLATILE) " THEN '%s'\n"
385 " END as \"%s\"",
386 gettext_noop("immutable"),
387 gettext_noop("stable"),
388 gettext_noop("volatile"),
389 gettext_noop("Volatility"));
391 ",\n CASE\n"
392 " WHEN p.proparallel = "
394 " WHEN p.proparallel = "
395 CppAsString2(PROPARALLEL_SAFE) " THEN '%s'\n"
396 " WHEN p.proparallel = "
397 CppAsString2(PROPARALLEL_UNSAFE) " THEN '%s'\n"
398 " END as \"%s\"",
399 gettext_noop("restricted"),
400 gettext_noop("safe"),
401 gettext_noop("unsafe"),
402 gettext_noop("Parallel"));
404 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
405 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\""
406 ",\n CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END as \"%s\"",
407 gettext_noop("Owner"),
408 gettext_noop("definer"),
409 gettext_noop("invoker"),
410 gettext_noop("Security"),
411 gettext_noop("yes"),
412 gettext_noop("no"),
413 gettext_noop("Leakproof?"));
414 appendPQExpBufferStr(&buf, ",\n ");
415 printACLColumn(&buf, "p.proacl");
417 ",\n l.lanname as \"%s\"",
418 gettext_noop("Language"));
420 ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
421 gettext_noop("Internal name"));
423 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
424 gettext_noop("Description"));
425 }
426
428 "\nFROM pg_catalog.pg_proc p"
429 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
430
431 for (int i = 0; i < num_arg_patterns; i++)
432 {
434 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
435 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
436 i, i, i, i, i, i);
437 }
438
439 if (verbose)
441 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
442
443 have_where = false;
444
445 /* filter by function type, if requested */
447 /* Do nothing */ ;
448 else if (showNormal)
449 {
450 if (!showAggregate)
451 {
452 if (have_where)
453 appendPQExpBufferStr(&buf, " AND ");
454 else
455 {
456 appendPQExpBufferStr(&buf, "WHERE ");
457 have_where = true;
458 }
459 if (pset.sversion >= 110000)
460 appendPQExpBufferStr(&buf, "p.prokind <> "
462 else
463 appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
464 }
465 if (!showProcedure && pset.sversion >= 110000)
466 {
467 if (have_where)
468 appendPQExpBufferStr(&buf, " AND ");
469 else
470 {
471 appendPQExpBufferStr(&buf, "WHERE ");
472 have_where = true;
473 }
474 appendPQExpBufferStr(&buf, "p.prokind <> "
476 }
477 if (!showTrigger)
478 {
479 if (have_where)
480 appendPQExpBufferStr(&buf, " AND ");
481 else
482 {
483 appendPQExpBufferStr(&buf, "WHERE ");
484 have_where = true;
485 }
486 appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
487 }
488 if (!showWindow)
489 {
490 if (have_where)
491 appendPQExpBufferStr(&buf, " AND ");
492 else
493 {
494 appendPQExpBufferStr(&buf, "WHERE ");
495 have_where = true;
496 }
497 if (pset.sversion >= 110000)
498 appendPQExpBufferStr(&buf, "p.prokind <> "
500 else
501 appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
502 }
503 }
504 else
505 {
506 bool needs_or = false;
507
508 appendPQExpBufferStr(&buf, "WHERE (\n ");
509 have_where = true;
510 /* Note: at least one of these must be true ... */
511 if (showAggregate)
512 {
513 if (pset.sversion >= 110000)
514 appendPQExpBufferStr(&buf, "p.prokind = "
516 else
517 appendPQExpBufferStr(&buf, "p.proisagg\n");
518 needs_or = true;
519 }
520 if (showTrigger)
521 {
522 if (needs_or)
523 appendPQExpBufferStr(&buf, " OR ");
525 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
526 needs_or = true;
527 }
528 if (showProcedure)
529 {
530 if (needs_or)
531 appendPQExpBufferStr(&buf, " OR ");
532 appendPQExpBufferStr(&buf, "p.prokind = "
534 needs_or = true;
535 }
536 if (showWindow)
537 {
538 if (needs_or)
539 appendPQExpBufferStr(&buf, " OR ");
540 if (pset.sversion >= 110000)
541 appendPQExpBufferStr(&buf, "p.prokind = "
543 else
544 appendPQExpBufferStr(&buf, "p.proiswindow\n");
545 }
546 appendPQExpBufferStr(&buf, " )\n");
547 }
548
550 "n.nspname", "p.proname", NULL,
551 "pg_catalog.pg_function_is_visible(p.oid)",
552 NULL, 3))
553 goto error_return;
554
555 for (int i = 0; i < num_arg_patterns; i++)
556 {
557 if (strcmp(arg_patterns[i], "-") != 0)
558 {
559 /*
560 * Match type-name patterns against either internal or external
561 * name, like \dT. Unlike \dT, there seems no reason to
562 * discriminate against arrays or composite types.
563 */
564 char nspname[64];
565 char typname[64];
566 char ft[64];
567 char tiv[64];
568
569 snprintf(nspname, sizeof(nspname), "nt%d.nspname", i);
570 snprintf(typname, sizeof(typname), "t%d.typname", i);
571 snprintf(ft, sizeof(ft),
572 "pg_catalog.format_type(t%d.oid, NULL)", i);
573 snprintf(tiv, sizeof(tiv),
574 "pg_catalog.pg_type_is_visible(t%d.oid)", i);
577 true, false,
578 nspname, typname, ft, tiv,
579 NULL, 3))
580 goto error_return;
581 }
582 else
583 {
584 /* "-" pattern specifies no such parameter */
585 appendPQExpBuffer(&buf, " AND t%d.typname IS NULL\n", i);
586 }
587 }
588
589 if (!showSystem && !func_pattern)
590 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
591 " AND n.nspname <> 'information_schema'\n");
592
593 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
594
595 res = PSQLexec(buf.data);
597 if (!res)
598 return false;
599
600 myopt.title = _("List of functions");
601 myopt.translate_header = true;
602 myopt.translate_columns = translate_columns;
603 myopt.n_translate_columns = lengthof(translate_columns);
604
605 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
606
607 PQclear(res);
608 return true;
609
612 return false;
613}
static const char * map_typename_pattern(const char *pattern)
Definition describe.c:728
int i
Definition isn.c:77
#define pg_log_error(...)
Definition logging.h:108
NameData typname
Definition pg_type.h:43
#define snprintf
Definition port.h:261
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), formatPGVersionNumber(), gettext_noop, i, initPQExpBuffer(), lengthof, _psqlSettings::logfile, map_typename_pattern(), pg_log_error, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, snprintf, _psqlSettings::sversion, termPQExpBuffer(), typname, validateSQLNamePattern(), and verbose.

Referenced by exec_command_dfo().

◆ describeOperators()

bool describeOperators ( const char oper_pattern,
char **  arg_patterns,
int  num_arg_patterns,
bool  verbose,
bool  showSystem 
)
extern

Definition at line 778 of file describe.c.

781{
783 PGresult *res;
785 static const bool translate_columns[] = {false, false, false, false, false, false, true, false};
786
788
789 /*
790 * Note: before Postgres 9.1, we did not assign comments to any built-in
791 * operators, preferring to let the comment on the underlying function
792 * suffice. The coalesce() on the obj_description() calls below supports
793 * this convention by providing a fallback lookup of a comment on the
794 * operator's function. Since 9.1 there is a policy that every built-in
795 * operator should have a comment; so the coalesce() is no longer
796 * necessary so far as built-in operators are concerned. We keep it
797 * anyway, for now, because third-party modules may still be following the
798 * old convention.
799 *
800 * The support for postfix operators in this query is dead code as of
801 * Postgres 14, but we need to keep it for as long as we support talking
802 * to pre-v14 servers.
803 */
804
805 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operators"));
807 "SELECT n.nspname as \"%s\",\n"
808 " o.oprname AS \"%s\",\n"
809 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
810 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
811 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
812 gettext_noop("Schema"),
813 gettext_noop("Name"),
814 gettext_noop("Left arg type"),
815 gettext_noop("Right arg type"),
816 gettext_noop("Result type"));
817
818 if (verbose)
820 " o.oprcode AS \"%s\",\n"
821 " CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END AS \"%s\",\n",
822 gettext_noop("Function"),
823 gettext_noop("yes"),
824 gettext_noop("no"),
825 gettext_noop("Leakproof?"));
826
828 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
829 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
830 "FROM pg_catalog.pg_operator o\n"
831 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
832 gettext_noop("Description"));
833
834 if (num_arg_patterns >= 2)
835 {
836 num_arg_patterns = 2; /* ignore any additional arguments */
838 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
839 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
840 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
841 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
842 }
843 else if (num_arg_patterns == 1)
844 {
846 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
847 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
848 }
849
850 if (verbose)
852 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = o.oprcode\n");
853
854 if (!showSystem && !oper_pattern)
855 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
856 " AND n.nspname <> 'information_schema'\n");
857
859 !showSystem && !oper_pattern, true,
860 "n.nspname", "o.oprname", NULL,
861 "pg_catalog.pg_operator_is_visible(o.oid)",
862 NULL, 3))
863 goto error_return;
864
865 if (num_arg_patterns == 1)
866 appendPQExpBufferStr(&buf, " AND o.oprleft = 0\n");
867
868 for (int i = 0; i < num_arg_patterns; i++)
869 {
870 if (strcmp(arg_patterns[i], "-") != 0)
871 {
872 /*
873 * Match type-name patterns against either internal or external
874 * name, like \dT. Unlike \dT, there seems no reason to
875 * discriminate against arrays or composite types.
876 */
877 char nspname[64];
878 char typname[64];
879 char ft[64];
880 char tiv[64];
881
882 snprintf(nspname, sizeof(nspname), "nt%d.nspname", i);
883 snprintf(typname, sizeof(typname), "t%d.typname", i);
884 snprintf(ft, sizeof(ft),
885 "pg_catalog.format_type(t%d.oid, NULL)", i);
886 snprintf(tiv, sizeof(tiv),
887 "pg_catalog.pg_type_is_visible(t%d.oid)", i);
890 true, false,
891 nspname, typname, ft, tiv,
892 NULL, 3))
893 goto error_return;
894 }
895 else
896 {
897 /* "-" pattern specifies no such parameter */
898 appendPQExpBuffer(&buf, " AND t%d.typname IS NULL\n", i);
899 }
900 }
901
902 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
903
904 res = PSQLexec(buf.data);
906 if (!res)
907 return false;
908
909 myopt.title = _("List of operators");
910 myopt.translate_header = true;
911 myopt.translate_columns = translate_columns;
912 myopt.n_translate_columns = lengthof(translate_columns);
913
914 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
915
916 PQclear(res);
917 return true;
918
921 return false;
922}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, i, initPQExpBuffer(), lengthof, _psqlSettings::logfile, map_typename_pattern(), _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, snprintf, termPQExpBuffer(), typname, validateSQLNamePattern(), and verbose.

Referenced by exec_command_dfo().

◆ describePublications()

bool describePublications ( const char pattern)

Definition at line 6610 of file describe.c.

6611{
6613 int i;
6614 PGresult *res;
6615 bool has_pubtruncate;
6616 bool has_pubgencols;
6617 bool has_pubviaroot;
6618 bool has_pubsequence;
6619 int ncols = 6;
6620 int nrows = 1;
6621
6622 PQExpBufferData title;
6624
6625 has_pubsequence = (pset.sversion >= 190000);
6626 has_pubtruncate = (pset.sversion >= 110000);
6627 has_pubgencols = (pset.sversion >= 180000);
6628 has_pubviaroot = (pset.sversion >= 130000);
6629
6631
6632 printfPQExpBuffer(&buf, "/* %s */\n", _("Get details about matching publications"));
6634 "SELECT oid, pubname,\n"
6635 " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6636 " puballtables");
6637
6638 if (has_pubsequence)
6640 ", puballsequences");
6641 else
6643 ", false AS puballsequences");
6644
6646 ", pubinsert, pubupdate, pubdelete");
6647
6648 if (has_pubtruncate)
6650 ", pubtruncate");
6651 else
6653 ", false AS pubtruncate");
6654
6655 if (has_pubgencols)
6657 ", (CASE pubgencols\n"
6658 " WHEN '%c' THEN 'none'\n"
6659 " WHEN '%c' THEN 'stored'\n"
6660 " END) AS \"%s\"\n",
6663 gettext_noop("Generated columns"));
6664 else
6666 ", 'none' AS pubgencols");
6667
6668 if (has_pubviaroot)
6670 ", pubviaroot");
6671 else
6673 ", false AS pubviaroot");
6674
6676 ", pg_catalog.obj_description(oid, 'pg_publication')");
6677
6679 "\nFROM pg_catalog.pg_publication\n");
6680
6681 if (!validateSQLNamePattern(&buf, pattern, false, false,
6682 NULL, "pubname", NULL,
6683 NULL,
6684 NULL, 1))
6685 {
6687 return false;
6688 }
6689
6690 appendPQExpBufferStr(&buf, "ORDER BY 2;");
6691
6692 res = PSQLexec(buf.data);
6693 if (!res)
6694 {
6696 return false;
6697 }
6698
6699 if (PQntuples(res) == 0)
6700 {
6701 if (!pset.quiet)
6702 {
6703 if (pattern)
6704 pg_log_error("Did not find any publication named \"%s\".",
6705 pattern);
6706 else
6707 pg_log_error("Did not find any publications.");
6708 }
6709
6711 PQclear(res);
6712 return false;
6713 }
6714
6715 if (has_pubsequence)
6716 ncols++;
6717 if (has_pubtruncate)
6718 ncols++;
6719 if (has_pubgencols)
6720 ncols++;
6721 if (has_pubviaroot)
6722 ncols++;
6723
6724 for (i = 0; i < PQntuples(res); i++)
6725 {
6726 const char align = 'l';
6727 char *pubid = PQgetvalue(res, i, 0);
6728 char *pubname = PQgetvalue(res, i, 1);
6729 bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
6731
6732 initPQExpBuffer(&title);
6733 printfPQExpBuffer(&title, _("Publication %s"), pubname);
6734 printTableInit(&cont, &myopt, title.data, ncols, nrows);
6735
6736 printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
6737 printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
6738 if (has_pubsequence)
6739 printTableAddHeader(&cont, gettext_noop("All sequences"), true, align);
6740 printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
6741 printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
6742 printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
6743 if (has_pubtruncate)
6744 printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
6745 if (has_pubgencols)
6746 printTableAddHeader(&cont, gettext_noop("Generated columns"), true, align);
6747 if (has_pubviaroot)
6748 printTableAddHeader(&cont, gettext_noop("Via root"), true, align);
6749 printTableAddHeader(&cont, gettext_noop("Description"), true, align);
6750
6751 printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
6752 printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
6753 if (has_pubsequence)
6754 printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
6755 printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
6756 printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
6757 printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
6758 if (has_pubtruncate)
6759 printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
6760 if (has_pubgencols)
6761 printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
6762 if (has_pubviaroot)
6763 printTableAddCell(&cont, PQgetvalue(res, i, 10), false, false);
6764 printTableAddCell(&cont, PQgetvalue(res, i, 11), false, false);
6765
6766 if (!puballtables)
6767 {
6768 /* Get the tables for the specified publication */
6769 printfPQExpBuffer(&buf, "/* %s */\n",
6770 _("Get tables published by this publication"));
6771 appendPQExpBufferStr(&buf, "SELECT n.nspname, c.relname");
6772 if (pset.sversion >= 150000)
6773 {
6775 ", pg_catalog.pg_get_expr(pr.prqual, c.oid)");
6777 ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6778 " pg_catalog.array_to_string("
6779 " ARRAY(SELECT attname\n"
6780 " FROM\n"
6781 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6782 " pg_catalog.pg_attribute\n"
6783 " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6784 " ELSE NULL END)");
6785 }
6786 else
6788 ", NULL, NULL");
6790 "\nFROM pg_catalog.pg_class c,\n"
6791 " pg_catalog.pg_namespace n,\n"
6792 " pg_catalog.pg_publication_rel pr\n"
6793 "WHERE c.relnamespace = n.oid\n"
6794 " AND c.oid = pr.prrelid\n"
6795 " AND pr.prpubid = '%s'\n", pubid);
6796
6797 if (pset.sversion >= 190000)
6798 appendPQExpBufferStr(&buf, " AND NOT pr.prexcept\n");
6799
6800 appendPQExpBufferStr(&buf, "ORDER BY 1,2");
6801 if (!addFooterToPublicationDesc(&buf, _("Tables:"), false, &cont))
6802 goto error_return;
6803
6804 if (pset.sversion >= 150000)
6805 {
6806 /* Get the schemas for the specified publication */
6807 printfPQExpBuffer(&buf, "/* %s */\n",
6808 _("Get schemas published by this publication"));
6810 "SELECT n.nspname\n"
6811 "FROM pg_catalog.pg_namespace n\n"
6812 " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6813 "WHERE pn.pnpubid = '%s'\n"
6814 "ORDER BY 1", pubid);
6815 if (!addFooterToPublicationDesc(&buf, _("Tables from schemas:"),
6816 true, &cont))
6817 goto error_return;
6818 }
6819 }
6820 else
6821 {
6822 if (pset.sversion >= 190000)
6823 {
6824 /* Get tables in the EXCEPT clause for this publication */
6825 printfPQExpBuffer(&buf, "/* %s */\n",
6826 _("Get tables excluded by this publication"));
6828 "SELECT n.nspname || '.' || c.relname\n"
6829 "FROM pg_catalog.pg_class c\n"
6830 " JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
6831 " JOIN pg_catalog.pg_publication_rel pr ON c.oid = pr.prrelid\n"
6832 "WHERE pr.prpubid = '%s' AND pr.prexcept\n"
6833 "ORDER BY 1", pubid);
6834 if (!addFooterToPublicationDesc(&buf, _("Except tables:"),
6835 true, &cont))
6836 goto error_return;
6837 }
6838 }
6839
6842
6843 termPQExpBuffer(&title);
6844 }
6845
6847 PQclear(res);
6848
6849 return true;
6850
6853 PQclear(res);
6855 termPQExpBuffer(&title);
6856 return false;
6857}
static bool addFooterToPublicationDesc(PQExpBuffer buf, const char *footermsg, bool as_schema, printTableContent *const cont)
Definition describe.c:6564
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition print.c:3209
void printTableCleanup(printTableContent *const content)
Definition print.c:3390
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition print.c:3297
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition print.c:3654
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition print.c:3257
#define PQgetvalue
#define PQntuples
printTableOpt topt
Definition print.h:185

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

Referenced by exec_command_d().

◆ describeRoleGrants()

bool describeRoleGrants ( const char pattern,
bool  showSystem 
)
extern

Definition at line 3991 of file describe.c.

3992{
3994 PGresult *res;
3996
3998 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching role grants"));
4000 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
4001 " pg_catalog.concat_ws(', ',\n",
4002 gettext_noop("Role name"),
4003 gettext_noop("Member of"));
4004
4005 if (pset.sversion >= 160000)
4007 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
4008 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
4009 " CASE WHEN pam.set_option THEN 'SET' END\n");
4010 else
4012 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
4013 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
4014 " 'SET'\n");
4015
4017 " ) AS \"%s\",\n"
4018 " g.rolname AS \"%s\"\n",
4019 gettext_noop("Options"),
4020 gettext_noop("Grantor"));
4021
4023 "FROM pg_catalog.pg_roles m\n"
4024 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
4025 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
4026 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
4027
4028 if (!showSystem && !pattern)
4029 appendPQExpBufferStr(&buf, "WHERE m.rolname !~ '^pg_'\n");
4030
4031 if (!validateSQLNamePattern(&buf, pattern, false, false,
4032 NULL, "m.rolname", NULL, NULL,
4033 NULL, 1))
4034 {
4036 return false;
4037 }
4038
4039 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;\n");
4040
4041 res = PSQLexec(buf.data);
4043 if (!res)
4044 return false;
4045
4046 myopt.title = _("List of role grants");
4047 myopt.translate_header = true;
4048
4049 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4050
4051 PQclear(res);
4052 return true;
4053}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ describeRoles()

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

Definition at line 3778 of file describe.c.

3779{
3781 PGresult *res;
3784 int ncols = 2;
3785 int nrows = 0;
3786 int i;
3787 int conns;
3788 const char align = 'l';
3789 char **attr;
3790
3791 myopt.default_footer = false;
3792
3794
3795 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching roles"));
3797 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3798 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3799 " r.rolconnlimit, r.rolvaliduntil");
3800
3801 if (verbose)
3802 {
3803 appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3804 ncols++;
3805 }
3806 appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3807 appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3808
3809 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3810
3811 if (!showSystem && !pattern)
3812 appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3813
3814 if (!validateSQLNamePattern(&buf, pattern, false, false,
3815 NULL, "r.rolname", NULL, NULL,
3816 NULL, 1))
3817 {
3819 return false;
3820 }
3821
3822 appendPQExpBufferStr(&buf, "ORDER BY 1;");
3823
3824 res = PSQLexec(buf.data);
3825 if (!res)
3826 return false;
3827
3828 nrows = PQntuples(res);
3829 attr = pg_malloc0_array(char *, nrows + 1);
3830
3831 printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3832
3833 printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3834 printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3835
3836 if (verbose)
3837 printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3838
3839 for (i = 0; i < nrows; i++)
3840 {
3841 printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3842
3844 if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3845 add_role_attribute(&buf, _("Superuser"));
3846
3847 if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3848 add_role_attribute(&buf, _("No inheritance"));
3849
3850 if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3851 add_role_attribute(&buf, _("Create role"));
3852
3853 if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3854 add_role_attribute(&buf, _("Create DB"));
3855
3856 if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3857 add_role_attribute(&buf, _("Cannot login"));
3858
3859 if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0)
3860 add_role_attribute(&buf, _("Replication"));
3861
3862 if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3863 add_role_attribute(&buf, _("Bypass RLS"));
3864
3865 conns = atoi(PQgetvalue(res, i, 6));
3866 if (conns >= 0)
3867 {
3868 if (buf.len > 0)
3869 appendPQExpBufferChar(&buf, '\n');
3870
3871 if (conns == 0)
3872 appendPQExpBufferStr(&buf, _("No connections"));
3873 else
3874 appendPQExpBuffer(&buf, ngettext("%d connection",
3875 "%d connections",
3876 conns),
3877 conns);
3878 }
3879
3880 if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3881 {
3882 if (buf.len > 0)
3883 appendPQExpBufferChar(&buf, '\n');
3884 appendPQExpBufferStr(&buf, _("Password valid until "));
3886 }
3887
3888 attr[i] = pg_strdup(buf.data);
3889
3890 printTableAddCell(&cont, attr[i], false, false);
3891
3892 if (verbose)
3893 printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3894 }
3896
3899
3900 for (i = 0; i < nrows; i++)
3901 pg_free(attr[i]);
3902 pg_free(attr);
3903
3904 PQclear(res);
3905 return true;
3906}
#define ngettext(s, p, n)
Definition c.h:1329
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition describe.c:3909
char * pg_strdup(const char *in)
Definition fe_memutils.c:91
void pg_free(void *ptr)
#define pg_malloc0_array(type, count)
Definition fe_memutils.h:67
static IsoConnInfo * conns
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)

References _, add_role_attribute(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), buf, conns, fb(), gettext_noop, i, initPQExpBuffer(), _psqlSettings::logfile, ngettext, pg_free(), pg_malloc0_array, pg_strdup(), _psqlSettings::popt, PQclear, PQgetvalue, PQntuples, printfPQExpBuffer(), printTable(), printTableAddCell(), printTableAddHeader(), printTableCleanup(), printTableInit(), pset, PSQLexec(), _psqlSettings::queryFout, resetPQExpBuffer(), termPQExpBuffer(), printQueryOpt::topt, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ describeSubscriptions()

bool describeSubscriptions ( const char pattern,
bool  verbose 
)

Definition at line 6866 of file describe.c.

6867{
6869 PGresult *res;
6871 static const bool translate_columns[] = {false, false, false, false,
6872 false, false, false, false, false, false, false, false, false, false,
6873 false, false, false, false, false, false, false};
6874
6876
6877 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching subscriptions"));
6879 "SELECT subname AS \"%s\"\n"
6880 ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6881 ", subenabled AS \"%s\"\n"
6882 ", subpublications AS \"%s\"\n",
6883 gettext_noop("Name"),
6884 gettext_noop("Owner"),
6885 gettext_noop("Enabled"),
6886 gettext_noop("Publication"));
6887
6888 if (verbose)
6889 {
6890 /* Binary mode and streaming are only supported in v14 and higher */
6891 if (pset.sversion >= 140000)
6892 {
6894 ", subbinary AS \"%s\"\n",
6895 gettext_noop("Binary"));
6896
6897 if (pset.sversion >= 160000)
6899 ", (CASE substream\n"
6900 " WHEN " CppAsString2(LOGICALREP_STREAM_OFF) " THEN 'off'\n"
6901 " WHEN " CppAsString2(LOGICALREP_STREAM_ON) " THEN 'on'\n"
6902 " WHEN " CppAsString2(LOGICALREP_STREAM_PARALLEL) " THEN 'parallel'\n"
6903 " END) AS \"%s\"\n",
6904 gettext_noop("Streaming"));
6905 else
6907 ", substream AS \"%s\"\n",
6908 gettext_noop("Streaming"));
6909 }
6910
6911 /* Two_phase and disable_on_error are only supported in v15 and higher */
6912 if (pset.sversion >= 150000)
6914 ", subtwophasestate AS \"%s\"\n"
6915 ", subdisableonerr AS \"%s\"\n",
6916 gettext_noop("Two-phase commit"),
6917 gettext_noop("Disable on error"));
6918
6919 if (pset.sversion >= 160000)
6921 ", suborigin AS \"%s\"\n"
6922 ", subpasswordrequired AS \"%s\"\n"
6923 ", subrunasowner AS \"%s\"\n",
6924 gettext_noop("Origin"),
6925 gettext_noop("Password required"),
6926 gettext_noop("Run as owner?"));
6927
6928 if (pset.sversion >= 170000)
6930 ", subfailover AS \"%s\"\n",
6931 gettext_noop("Failover"));
6932 if (pset.sversion >= 190000)
6933 {
6935 ", (select srvname from pg_catalog.pg_foreign_server where oid=subserver) AS \"%s\"\n",
6936 gettext_noop("Server"));
6937
6939 ", subretaindeadtuples AS \"%s\"\n",
6940 gettext_noop("Retain dead tuples"));
6941
6943 ", submaxretention AS \"%s\"\n",
6944 gettext_noop("Max retention duration"));
6945
6947 ", subretentionactive AS \"%s\"\n",
6948 gettext_noop("Retention active"));
6949 }
6950
6952 ", subsynccommit AS \"%s\"\n"
6953 ", subconninfo AS \"%s\"\n",
6954 gettext_noop("Synchronous commit"),
6955 gettext_noop("Conninfo"));
6956
6957 if (pset.sversion >= 190000)
6959 ", subwalrcvtimeout AS \"%s\"\n",
6960 gettext_noop("Receiver timeout"));
6961
6962 /* Skip LSN is only supported in v15 and higher */
6963 if (pset.sversion >= 150000)
6965 ", subskiplsn AS \"%s\"\n",
6966 gettext_noop("Skip LSN"));
6967
6969 ", pg_catalog.obj_description(oid, 'pg_subscription') AS \"%s\"\n",
6970 gettext_noop("Description"));
6971 }
6972
6973 /* Only display subscriptions in current database. */
6975 "FROM pg_catalog.pg_subscription\n"
6976 "WHERE subdbid = (SELECT oid\n"
6977 " FROM pg_catalog.pg_database\n"
6978 " WHERE datname = pg_catalog.current_database())");
6979
6980 if (!validateSQLNamePattern(&buf, pattern, true, false,
6981 NULL, "subname", NULL,
6982 NULL,
6983 NULL, 1))
6984 {
6986 return false;
6987 }
6988
6989 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6990
6991 res = PSQLexec(buf.data);
6993 if (!res)
6994 return false;
6995
6996 myopt.title = _("List of subscriptions");
6997 myopt.translate_header = true;
6998 myopt.translate_columns = translate_columns;
6999 myopt.n_translate_columns = lengthof(translate_columns);
7000
7001 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7002
7003 PQclear(res);
7004 return true;
7005}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ describeTableDetails()

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

Definition at line 1449 of file describe.c.

1450{
1452 PGresult *res;
1453 int i;
1454
1456
1457 printfPQExpBuffer(&buf, "/* %s */\n",
1458 _("Get matching relations to describe"));
1460 "SELECT c.oid,\n"
1461 " n.nspname,\n"
1462 " c.relname\n"
1463 "FROM pg_catalog.pg_class c\n"
1464 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1465
1466 if (!showSystem && !pattern)
1467 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1468 " AND n.nspname <> 'information_schema'\n");
1469
1470 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1471 "n.nspname", "c.relname", NULL,
1472 "pg_catalog.pg_table_is_visible(c.oid)",
1473 NULL, 3))
1474 {
1476 return false;
1477 }
1478
1479 appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1480
1481 res = PSQLexec(buf.data);
1483 if (!res)
1484 return false;
1485
1486 if (PQntuples(res) == 0)
1487 {
1488 if (!pset.quiet)
1489 {
1490 if (pattern)
1491 pg_log_error("Did not find any relation named \"%s\".",
1492 pattern);
1493 else
1494 pg_log_error("Did not find any relations.");
1495 }
1496 PQclear(res);
1497 return false;
1498 }
1499
1500 for (i = 0; i < PQntuples(res); i++)
1501 {
1502 const char *oid;
1503 const char *nspname;
1504 const char *relname;
1505
1506 oid = PQgetvalue(res, i, 0);
1507 nspname = PQgetvalue(res, i, 1);
1508 relname = PQgetvalue(res, i, 2);
1509
1510 if (!describeOneTableDetails(nspname, relname, oid, verbose))
1511 {
1512 PQclear(res);
1513 return false;
1514 }
1515 if (cancel_pressed)
1516 {
1517 PQclear(res);
1518 return false;
1519 }
1520 }
1521
1522 PQclear(res);
1523 return true;
1524}
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition describe.c:1534
volatile sig_atomic_t cancel_pressed
Definition print.c:48
NameData relname
Definition pg_class.h:40

References _, appendPQExpBufferStr(), buf, cancel_pressed, describeOneTableDetails(), fb(), i, initPQExpBuffer(), pg_log_error, PQclear, PQgetvalue, PQntuples, printfPQExpBuffer(), pset, PSQLexec(), _psqlSettings::quiet, relname, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ describeTablespaces()

bool describeTablespaces ( const char pattern,
bool  verbose 
)
extern

Definition at line 215 of file describe.c.

216{
218 PGresult *res;
220
222
223 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching tablespaces"));
225 "SELECT spcname AS \"%s\",\n"
226 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
227 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
228 gettext_noop("Name"),
229 gettext_noop("Owner"),
230 gettext_noop("Location"));
231
232 if (verbose)
233 {
234 appendPQExpBufferStr(&buf, ",\n ");
235 printACLColumn(&buf, "spcacl");
237 ",\n spcoptions AS \"%s\""
238 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
239 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
240 gettext_noop("Options"),
241 gettext_noop("Size"),
242 gettext_noop("Description"));
243 }
244
246 "\nFROM pg_catalog.pg_tablespace\n");
247
248 if (!validateSQLNamePattern(&buf, pattern, false, false,
249 NULL, "spcname", NULL,
250 NULL,
251 NULL, 1))
252 {
254 return false;
255 }
256
257 appendPQExpBufferStr(&buf, "ORDER BY 1;");
258
259 res = PSQLexec(buf.data);
261 if (!res)
262 return false;
263
264 myopt.title = _("List of tablespaces");
265 myopt.translate_header = true;
266
267 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
268
269 PQclear(res);
270 return true;
271}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ describeTypes()

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

Definition at line 622 of file describe.c.

623{
625 PGresult *res;
627
629
630 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching types"));
632 "SELECT n.nspname as \"%s\",\n"
633 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
634 gettext_noop("Schema"),
635 gettext_noop("Name"));
636 if (verbose)
637 {
639 " t.typname AS \"%s\",\n"
640 " CASE WHEN t.typrelid != 0\n"
641 " THEN CAST('tuple' AS pg_catalog.text)\n"
642 " WHEN t.typlen < 0\n"
643 " THEN CAST('var' AS pg_catalog.text)\n"
644 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
645 " END AS \"%s\",\n"
646 " pg_catalog.array_to_string(\n"
647 " ARRAY(\n"
648 " SELECT e.enumlabel\n"
649 " FROM pg_catalog.pg_enum e\n"
650 " WHERE e.enumtypid = t.oid\n"
651 " ORDER BY e.enumsortorder\n"
652 " ),\n"
653 " E'\\n'\n"
654 " ) AS \"%s\",\n"
655 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
656 gettext_noop("Internal name"),
657 gettext_noop("Size"),
658 gettext_noop("Elements"),
659 gettext_noop("Owner"));
660 printACLColumn(&buf, "t.typacl");
661 appendPQExpBufferStr(&buf, ",\n ");
662 }
663
665 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
666 gettext_noop("Description"));
667
668 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
669 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
670
671 /*
672 * do not include complex types (typrelid!=0) unless they are standalone
673 * composite types
674 */
675 appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
677 " FROM pg_catalog.pg_class c "
678 "WHERE c.oid = t.typrelid))\n");
679
680 /*
681 * do not include array types unless the pattern contains []
682 */
683 if (pattern == NULL || strstr(pattern, "[]") == NULL)
684 appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
685
686 if (!showSystem && !pattern)
687 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
688 " AND n.nspname <> 'information_schema'\n");
689
690 /* Match name pattern against either internal or external name */
692 true, false,
693 "n.nspname", "t.typname",
694 "pg_catalog.format_type(t.oid, NULL)",
695 "pg_catalog.pg_type_is_visible(t.oid)",
696 NULL, 3))
697 {
699 return false;
700 }
701
702 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
703
704 res = PSQLexec(buf.data);
706 if (!res)
707 return false;
708
709 myopt.title = _("List of data types");
710 myopt.translate_header = true;
711
712 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
713
714 PQclear(res);
715 return true;
716}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, map_typename_pattern(), _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listAllDbs()

bool listAllDbs ( const char pattern,
bool  verbose 
)
extern

Definition at line 931 of file describe.c.

932{
933 PGresult *res;
936
938
939 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching databases"));
941 "SELECT\n"
942 " d.datname as \"%s\",\n"
943 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
944 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
945 gettext_noop("Name"),
946 gettext_noop("Owner"),
947 gettext_noop("Encoding"));
948 if (pset.sversion >= 150000)
950 " CASE d.datlocprovider "
951 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' "
952 "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' "
953 "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' "
954 "END AS \"%s\",\n",
955 gettext_noop("Locale Provider"));
956 else
958 " 'libc' AS \"%s\",\n",
959 gettext_noop("Locale Provider"));
961 " d.datcollate as \"%s\",\n"
962 " d.datctype as \"%s\",\n",
963 gettext_noop("Collate"),
964 gettext_noop("Ctype"));
965 if (pset.sversion >= 170000)
967 " d.datlocale as \"%s\",\n",
968 gettext_noop("Locale"));
969 else if (pset.sversion >= 150000)
971 " d.daticulocale as \"%s\",\n",
972 gettext_noop("Locale"));
973 else
975 " NULL as \"%s\",\n",
976 gettext_noop("Locale"));
977 if (pset.sversion >= 160000)
979 " d.daticurules as \"%s\",\n",
980 gettext_noop("ICU Rules"));
981 else
983 " NULL as \"%s\",\n",
984 gettext_noop("ICU Rules"));
986 printACLColumn(&buf, "d.datacl");
987 if (verbose)
989 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
990 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
991 " ELSE 'No Access'\n"
992 " END as \"%s\""
993 ",\n t.spcname as \"%s\""
994 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
995 gettext_noop("Size"),
996 gettext_noop("Tablespace"),
997 gettext_noop("Description"));
999 "\nFROM pg_catalog.pg_database d\n");
1000 if (verbose)
1002 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
1003
1004 if (pattern)
1005 {
1006 if (!validateSQLNamePattern(&buf, pattern, false, false,
1007 NULL, "d.datname", NULL, NULL,
1008 NULL, 1))
1009 {
1011 return false;
1012 }
1013 }
1014
1015 appendPQExpBufferStr(&buf, "ORDER BY 1;");
1016 res = PSQLexec(buf.data);
1018 if (!res)
1019 return false;
1020
1021 myopt.title = _("List of databases");
1022 myopt.translate_header = true;
1023
1024 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1025
1026 PQclear(res);
1027 return true;
1028}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_list(), and main().

◆ listCasts()

bool listCasts ( const char pattern,
bool  verbose 
)
extern

Definition at line 5015 of file describe.c.

5016{
5018 PGresult *res;
5020 static const bool translate_columns[] = {false, false, false, true, true, false};
5021
5023
5024 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching casts"));
5026 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
5027 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
5028 gettext_noop("Source type"),
5029 gettext_noop("Target type"));
5030
5031 /*
5032 * We don't attempt to localize '(binary coercible)' or '(with inout)',
5033 * because there's too much risk of gettext translating a function name
5034 * that happens to match some string in the PO database.
5035 */
5037 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
5038 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
5039 " ELSE p.proname\n"
5040 " END AS \"%s\",\n",
5043 gettext_noop("Function"));
5044
5046 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
5047 " WHEN c.castcontext = '%c' THEN '%s'\n"
5048 " ELSE '%s'\n"
5049 " END AS \"%s\"",
5051 gettext_noop("no"),
5053 gettext_noop("in assignment"),
5054 gettext_noop("yes"),
5055 gettext_noop("Implicit?"));
5056
5057 if (verbose)
5059 ",\n CASE WHEN p.proleakproof THEN '%s'\n"
5060 " ELSE '%s'\n"
5061 " END AS \"%s\",\n"
5062 " d.description AS \"%s\"",
5063 gettext_noop("yes"),
5064 gettext_noop("no"),
5065 gettext_noop("Leakproof?"),
5066 gettext_noop("Description"));
5067
5068 /*
5069 * We need a left join to pg_proc for binary casts; the others are just
5070 * paranoia.
5071 */
5073 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
5074 " ON c.castfunc = p.oid\n"
5075 " LEFT JOIN pg_catalog.pg_type ts\n"
5076 " ON c.castsource = ts.oid\n"
5077 " LEFT JOIN pg_catalog.pg_namespace ns\n"
5078 " ON ns.oid = ts.typnamespace\n"
5079 " LEFT JOIN pg_catalog.pg_type tt\n"
5080 " ON c.casttarget = tt.oid\n"
5081 " LEFT JOIN pg_catalog.pg_namespace nt\n"
5082 " ON nt.oid = tt.typnamespace\n");
5083
5084 if (verbose)
5086 " LEFT JOIN pg_catalog.pg_description d\n"
5087 " ON d.classoid = c.tableoid AND d.objoid = "
5088 "c.oid AND d.objsubid = 0\n");
5089
5090 appendPQExpBufferStr(&buf, "WHERE ( (true");
5091
5092 /*
5093 * Match name pattern against either internal or external name of either
5094 * castsource or casttarget
5095 */
5096 if (!validateSQLNamePattern(&buf, pattern, true, false,
5097 "ns.nspname", "ts.typname",
5098 "pg_catalog.format_type(ts.oid, NULL)",
5099 "pg_catalog.pg_type_is_visible(ts.oid)",
5100 NULL, 3))
5101 goto error_return;
5102
5103 appendPQExpBufferStr(&buf, ") OR (true");
5104
5105 if (!validateSQLNamePattern(&buf, pattern, true, false,
5106 "nt.nspname", "tt.typname",
5107 "pg_catalog.format_type(tt.oid, NULL)",
5108 "pg_catalog.pg_type_is_visible(tt.oid)",
5109 NULL, 3))
5110 goto error_return;
5111
5112 appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
5113
5114 res = PSQLexec(buf.data);
5116 if (!res)
5117 return false;
5118
5119 myopt.title = _("List of casts");
5120 myopt.translate_header = true;
5121 myopt.translate_columns = translate_columns;
5122 myopt.n_translate_columns = lengthof(translate_columns);
5123
5124 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5125
5126 PQclear(res);
5127 return true;
5128
5131 return false;
5132}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listCollations()

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

Definition at line 5140 of file describe.c.

5141{
5143 PGresult *res;
5145 static const bool translate_columns[] = {false, false, false, false, false, false, false, true, false};
5146
5148
5149 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching collations"));
5151 "SELECT\n"
5152 " n.nspname AS \"%s\",\n"
5153 " c.collname AS \"%s\",\n",
5154 gettext_noop("Schema"),
5155 gettext_noop("Name"));
5156
5158 " CASE c.collprovider "
5159 "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' "
5160 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' "
5161 "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' "
5162 "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' "
5163 "END AS \"%s\",\n",
5164 gettext_noop("Provider"));
5165
5167 " c.collcollate AS \"%s\",\n"
5168 " c.collctype AS \"%s\",\n",
5169 gettext_noop("Collate"),
5170 gettext_noop("Ctype"));
5171
5172 if (pset.sversion >= 170000)
5174 " c.colllocale AS \"%s\",\n",
5175 gettext_noop("Locale"));
5176 else if (pset.sversion >= 150000)
5178 " c.colliculocale AS \"%s\",\n",
5179 gettext_noop("Locale"));
5180 else
5182 " c.collcollate AS \"%s\",\n",
5183 gettext_noop("Locale"));
5184
5185 if (pset.sversion >= 160000)
5187 " c.collicurules AS \"%s\",\n",
5188 gettext_noop("ICU Rules"));
5189 else
5191 " NULL AS \"%s\",\n",
5192 gettext_noop("ICU Rules"));
5193
5194 if (pset.sversion >= 120000)
5196 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5197 gettext_noop("yes"), gettext_noop("no"),
5198 gettext_noop("Deterministic?"));
5199 else
5201 " '%s' AS \"%s\"",
5202 gettext_noop("yes"),
5203 gettext_noop("Deterministic?"));
5204
5205 if (verbose)
5207 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5208 gettext_noop("Description"));
5209
5211 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5212 "WHERE n.oid = c.collnamespace\n");
5213
5214 if (!showSystem && !pattern)
5215 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
5216 " AND n.nspname <> 'information_schema'\n");
5217
5218 /*
5219 * Hide collations that aren't usable in the current database's encoding.
5220 * If you think to change this, note that pg_collation_is_visible rejects
5221 * unusable collations, so you will need to hack name pattern processing
5222 * somehow to avoid inconsistent behavior.
5223 */
5224 appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5225
5226 if (!validateSQLNamePattern(&buf, pattern, true, false,
5227 "n.nspname", "c.collname", NULL,
5228 "pg_catalog.pg_collation_is_visible(c.oid)",
5229 NULL, 3))
5230 {
5232 return false;
5233 }
5234
5235 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5236
5237 res = PSQLexec(buf.data);
5239 if (!res)
5240 return false;
5241
5242 myopt.title = _("List of collations");
5243 myopt.translate_header = true;
5244 myopt.translate_columns = translate_columns;
5245 myopt.n_translate_columns = lengthof(translate_columns);
5246
5247 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5248
5249 PQclear(res);
5250 return true;
5251}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listConversions()

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

Definition at line 4699 of file describe.c.

4700{
4702 PGresult *res;
4704 static const bool translate_columns[] =
4705 {false, false, false, false, true, false};
4706
4708
4709 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching conversions"));
4711 "SELECT n.nspname AS \"%s\",\n"
4712 " c.conname AS \"%s\",\n"
4713 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4714 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4715 " CASE WHEN c.condefault THEN '%s'\n"
4716 " ELSE '%s' END AS \"%s\"",
4717 gettext_noop("Schema"),
4718 gettext_noop("Name"),
4719 gettext_noop("Source"),
4720 gettext_noop("Destination"),
4721 gettext_noop("yes"), gettext_noop("no"),
4722 gettext_noop("Default?"));
4723
4724 if (verbose)
4726 ",\n d.description AS \"%s\"",
4727 gettext_noop("Description"));
4728
4730 "\nFROM pg_catalog.pg_conversion c\n"
4731 " JOIN pg_catalog.pg_namespace n "
4732 "ON n.oid = c.connamespace\n");
4733
4734 if (verbose)
4736 "LEFT JOIN pg_catalog.pg_description d "
4737 "ON d.classoid = c.tableoid\n"
4738 " AND d.objoid = c.oid "
4739 "AND d.objsubid = 0\n");
4740
4741 appendPQExpBufferStr(&buf, "WHERE true\n");
4742
4743 if (!showSystem && !pattern)
4744 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4745 " AND n.nspname <> 'information_schema'\n");
4746
4747 if (!validateSQLNamePattern(&buf, pattern, true, false,
4748 "n.nspname", "c.conname", NULL,
4749 "pg_catalog.pg_conversion_is_visible(c.oid)",
4750 NULL, 3))
4751 {
4753 return false;
4754 }
4755
4756 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4757
4758 res = PSQLexec(buf.data);
4760 if (!res)
4761 return false;
4762
4763 myopt.title = _("List of conversions");
4764 myopt.translate_header = true;
4765 myopt.translate_columns = translate_columns;
4766 myopt.n_translate_columns = lengthof(translate_columns);
4767
4768 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4769
4770 PQclear(res);
4771 return true;
4772}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listDbRoleSettings()

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

Definition at line 3921 of file describe.c.

3922{
3924 PGresult *res;
3926 bool havewhere;
3927
3929
3930 printfPQExpBuffer(&buf, "/* %s */\n", _("Get per-database and per-role settings"));
3931 appendPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3932 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3933 "FROM pg_catalog.pg_db_role_setting s\n"
3934 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3935 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3936 gettext_noop("Role"),
3937 gettext_noop("Database"),
3938 gettext_noop("Settings"));
3939 if (!validateSQLNamePattern(&buf, pattern, false, false,
3940 NULL, "r.rolname", NULL, NULL, &havewhere, 1))
3941 goto error_return;
3943 NULL, "d.datname", NULL, NULL,
3944 NULL, 1))
3945 goto error_return;
3946 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3947
3948 res = PSQLexec(buf.data);
3950 if (!res)
3951 return false;
3952
3953 /*
3954 * Most functions in this file are content to print an empty table when
3955 * there are no matching objects. We intentionally deviate from that
3956 * here, but only in !quiet mode, because of the possibility that the user
3957 * is confused about what the two pattern arguments mean.
3958 */
3959 if (PQntuples(res) == 0 && !pset.quiet)
3960 {
3961 if (pattern && pattern2)
3962 pg_log_error("Did not find any settings for role \"%s\" and database \"%s\".",
3963 pattern, pattern2);
3964 else if (pattern)
3965 pg_log_error("Did not find any settings for role \"%s\".",
3966 pattern);
3967 else
3968 pg_log_error("Did not find any settings.");
3969 }
3970 else
3971 {
3972 myopt.title = _("List of settings");
3973 myopt.translate_header = true;
3974
3975 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3976 }
3977
3978 PQclear(res);
3979 return true;
3980
3983 return false;
3984}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, pg_log_error, _psqlSettings::popt, PQclear, PQntuples, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::quiet, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listDefaultACLs()

bool listDefaultACLs ( const char pattern)
extern

Definition at line 1173 of file describe.c.

1174{
1176 PGresult *res;
1178 static const bool translate_columns[] = {false, false, true, false};
1179
1181
1182 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching default ACLs"));
1184 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1185 " n.nspname AS \"%s\",\n"
1186 " CASE d.defaclobjtype "
1187 " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s'"
1188 " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1189 " ",
1190 gettext_noop("Owner"),
1191 gettext_noop("Schema"),
1193 gettext_noop("table"),
1195 gettext_noop("sequence"),
1197 gettext_noop("function"),
1199 gettext_noop("type"),
1201 gettext_noop("schema"),
1203 gettext_noop("large object"),
1204 gettext_noop("Type"));
1205
1206 printACLColumn(&buf, "d.defaclacl");
1207
1208 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1209 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1210
1211 if (!validateSQLNamePattern(&buf, pattern, false, false,
1212 NULL,
1213 "n.nspname",
1214 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1215 NULL,
1216 NULL, 3))
1217 goto error_return;
1218
1219 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1220
1221 res = PSQLexec(buf.data);
1222 if (!res)
1223 goto error_return;
1224
1225 printfPQExpBuffer(&buf, _("Default access privileges"));
1226 myopt.title = buf.data;
1227 myopt.translate_header = true;
1228 myopt.translate_columns = translate_columns;
1229 myopt.n_translate_columns = lengthof(translate_columns);
1230
1231 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1232
1234 PQclear(res);
1235 return true;
1236
1239 return false;
1240}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listDomains()

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

Definition at line 4615 of file describe.c.

4616{
4618 PGresult *res;
4620
4622
4623 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching domains"));
4625 "SELECT n.nspname as \"%s\",\n"
4626 " t.typname as \"%s\",\n"
4627 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4628 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4629 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4630 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4631 " t.typdefault as \"%s\",\n"
4632 " pg_catalog.array_to_string(ARRAY(\n"
4633 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid AND r.contype = " CppAsString2(CONSTRAINT_CHECK) " ORDER BY r.conname\n"
4634 " ), ' ') as \"%s\"",
4635 gettext_noop("Schema"),
4636 gettext_noop("Name"),
4637 gettext_noop("Type"),
4638 gettext_noop("Collation"),
4639 gettext_noop("Nullable"),
4640 gettext_noop("Default"),
4641 gettext_noop("Check"));
4642
4643 if (verbose)
4644 {
4645 appendPQExpBufferStr(&buf, ",\n ");
4646 printACLColumn(&buf, "t.typacl");
4648 ",\n d.description as \"%s\"",
4649 gettext_noop("Description"));
4650 }
4651
4653 "\nFROM pg_catalog.pg_type t\n"
4654 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4655
4656 if (verbose)
4658 " LEFT JOIN pg_catalog.pg_description d "
4659 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4660 "AND d.objsubid = 0\n");
4661
4662 appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
4663
4664 if (!showSystem && !pattern)
4665 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4666 " AND n.nspname <> 'information_schema'\n");
4667
4668 if (!validateSQLNamePattern(&buf, pattern, true, false,
4669 "n.nspname", "t.typname", NULL,
4670 "pg_catalog.pg_type_is_visible(t.oid)",
4671 NULL, 3))
4672 {
4674 return false;
4675 }
4676
4677 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4678
4679 res = PSQLexec(buf.data);
4681 if (!res)
4682 return false;
4683
4684 myopt.title = _("List of domains");
4685 myopt.translate_header = true;
4686
4687 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4688
4689 PQclear(res);
4690 return true;
4691}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listEventTriggers()

bool listEventTriggers ( const char pattern,
bool  verbose 
)
extern

Definition at line 4851 of file describe.c.

4852{
4854 PGresult *res;
4856 static const bool translate_columns[] =
4857 {false, false, false, true, false, false, false};
4858
4860
4861 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching event triggers"));
4863 "SELECT evtname as \"%s\", "
4864 "evtevent as \"%s\", "
4865 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4866 " case evtenabled when 'O' then '%s'"
4867 " when 'R' then '%s'"
4868 " when 'A' then '%s'"
4869 " when 'D' then '%s' end as \"%s\",\n"
4870 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4871 "pg_catalog.array_to_string(array(select x"
4872 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4873 gettext_noop("Name"),
4874 gettext_noop("Event"),
4875 gettext_noop("Owner"),
4876 gettext_noop("enabled"),
4877 gettext_noop("replica"),
4878 gettext_noop("always"),
4879 gettext_noop("disabled"),
4880 gettext_noop("Enabled"),
4881 gettext_noop("Function"),
4882 gettext_noop("Tags"));
4883 if (verbose)
4885 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4886 gettext_noop("Description"));
4888 "\nFROM pg_catalog.pg_event_trigger e ");
4889
4890 if (!validateSQLNamePattern(&buf, pattern, false, false,
4891 NULL, "evtname", NULL, NULL,
4892 NULL, 1))
4893 {
4895 return false;
4896 }
4897
4898 appendPQExpBufferStr(&buf, "ORDER BY 1");
4899
4900 res = PSQLexec(buf.data);
4902 if (!res)
4903 return false;
4904
4905 myopt.title = _("List of event triggers");
4906 myopt.translate_header = true;
4907 myopt.translate_columns = translate_columns;
4908 myopt.n_translate_columns = lengthof(translate_columns);
4909
4910 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4911
4912 PQclear(res);
4913 return true;
4914}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listExtendedStats()

bool listExtendedStats ( const char pattern,
bool  verbose 
)
extern

Definition at line 4922 of file describe.c.

4923{
4925 PGresult *res;
4927
4929
4930 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching extended statistics"));
4932 "SELECT \n"
4933 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4934 "es.stxname AS \"%s\", \n",
4935 gettext_noop("Schema"),
4936 gettext_noop("Name"));
4937
4938 if (pset.sversion >= 140000)
4940 "pg_catalog.format('%%s FROM %%s', \n"
4941 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4942 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4943 gettext_noop("Definition"));
4944 else
4946 "pg_catalog.format('%%s FROM %%s', \n"
4947 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4948 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4949 " JOIN pg_catalog.pg_attribute a \n"
4950 " ON (es.stxrelid = a.attrelid \n"
4951 " AND a.attnum = s.attnum \n"
4952 " AND NOT a.attisdropped)), \n"
4953 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4954 gettext_noop("Definition"));
4955
4957 ",\nCASE WHEN " CppAsString2(STATS_EXT_NDISTINCT) " = any(es.stxkind) THEN 'defined' \n"
4958 "END AS \"%s\", \n"
4959 "CASE WHEN " CppAsString2(STATS_EXT_DEPENDENCIES) " = any(es.stxkind) THEN 'defined' \n"
4960 "END AS \"%s\"",
4961 gettext_noop("Ndistinct"),
4962 gettext_noop("Dependencies"));
4963
4964 /*
4965 * Include the MCV statistics kind.
4966 */
4967 if (pset.sversion >= 120000)
4968 {
4970 ",\nCASE WHEN " CppAsString2(STATS_EXT_MCV) " = any(es.stxkind) THEN 'defined' \n"
4971 "END AS \"%s\" ",
4972 gettext_noop("MCV"));
4973 }
4974
4975 if (verbose)
4977 ", \npg_catalog.obj_description(oid, 'pg_statistic_ext') AS \"%s\"\n",
4978 gettext_noop("Description"));
4979
4981 " \nFROM pg_catalog.pg_statistic_ext es \n");
4982
4983 if (!validateSQLNamePattern(&buf, pattern,
4984 false, false,
4985 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text", "es.stxname",
4986 NULL, "pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4987 NULL, 3))
4988 {
4990 return false;
4991 }
4992
4993 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4994
4995 res = PSQLexec(buf.data);
4997 if (!res)
4998 return false;
4999
5000 myopt.title = _("List of extended statistics");
5001 myopt.translate_header = true;
5002
5003 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5004
5005 PQclear(res);
5006 return true;
5007}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listExtensionContents()

bool listExtensionContents ( const char pattern)
extern

Definition at line 6313 of file describe.c.

6314{
6316 PGresult *res;
6317 int i;
6318
6320
6321 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching installed extensions"));
6323 "SELECT e.extname, e.oid\n"
6324 "FROM pg_catalog.pg_extension e\n");
6325
6326 if (!validateSQLNamePattern(&buf, pattern,
6327 false, false,
6328 NULL, "e.extname", NULL,
6329 NULL,
6330 NULL, 1))
6331 {
6333 return false;
6334 }
6335
6336 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6337
6338 res = PSQLexec(buf.data);
6340 if (!res)
6341 return false;
6342
6343 if (PQntuples(res) == 0)
6344 {
6345 if (!pset.quiet)
6346 {
6347 if (pattern)
6348 pg_log_error("Did not find any extension named \"%s\".",
6349 pattern);
6350 else
6351 pg_log_error("Did not find any extensions.");
6352 }
6353 PQclear(res);
6354 return false;
6355 }
6356
6357 for (i = 0; i < PQntuples(res); i++)
6358 {
6359 const char *extname;
6360 const char *oid;
6361
6362 extname = PQgetvalue(res, i, 0);
6363 oid = PQgetvalue(res, i, 1);
6364
6365 if (!listOneExtensionContents(extname, oid))
6366 {
6367 PQclear(res);
6368 return false;
6369 }
6370 if (cancel_pressed)
6371 {
6372 PQclear(res);
6373 return false;
6374 }
6375 }
6376
6377 PQclear(res);
6378 return true;
6379}
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition describe.c:6382

References _, appendPQExpBufferStr(), buf, cancel_pressed, fb(), i, initPQExpBuffer(), listOneExtensionContents(), pg_log_error, PQclear, PQgetvalue, PQntuples, printfPQExpBuffer(), pset, PSQLexec(), _psqlSettings::quiet, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listExtensions()

bool listExtensions ( const char pattern)
extern

Definition at line 6257 of file describe.c.

6258{
6260 PGresult *res;
6262
6264
6265 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching installed extensions"));
6267 "SELECT e.extname AS \"%s\", "
6268 "e.extversion AS \"%s\", ae.default_version AS \"%s\","
6269 "n.nspname AS \"%s\", d.description AS \"%s\"\n"
6270 "FROM pg_catalog.pg_extension e "
6271 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
6272 "LEFT JOIN pg_catalog.pg_description d ON d.objoid = e.oid "
6273 "AND d.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass "
6274 "LEFT JOIN pg_catalog.pg_available_extensions() ae(name, default_version, comment) ON ae.name = e.extname\n",
6275 gettext_noop("Name"),
6276 gettext_noop("Version"),
6277 gettext_noop("Default version"),
6278 gettext_noop("Schema"),
6279 gettext_noop("Description"));
6280
6281 if (!validateSQLNamePattern(&buf, pattern,
6282 false, false,
6283 NULL, "e.extname", NULL,
6284 NULL,
6285 NULL, 1))
6286 {
6288 return false;
6289 }
6290
6291 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6292
6293 res = PSQLexec(buf.data);
6295 if (!res)
6296 return false;
6297
6298 myopt.title = _("List of installed extensions");
6299 myopt.translate_header = true;
6300
6301 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6302
6303 PQclear(res);
6304 return true;
6305}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char pattern,
bool  verbose 
)
extern

Definition at line 5975 of file describe.c.

5976{
5978 PGresult *res;
5980
5982
5983 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign-data wrappers"));
5985 "SELECT fdw.fdwname AS \"%s\",\n"
5986 " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5987 " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5988 " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5989 gettext_noop("Name"),
5990 gettext_noop("Owner"),
5991 gettext_noop("Handler"),
5992 gettext_noop("Validator"));
5993
5994 if (verbose)
5995 {
5996 appendPQExpBufferStr(&buf, ",\n ");
5997 printACLColumn(&buf, "fdwacl");
5999 ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
6000 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6001 " pg_catalog.quote_ident(option_name) || ' ' || "
6002 " pg_catalog.quote_literal(option_value) FROM "
6003 " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
6004 " END AS \"%s\""
6005 ",\n d.description AS \"%s\" ",
6006 gettext_noop("FDW options"),
6007 gettext_noop("Description"));
6008 }
6009
6010 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
6011
6012 if (verbose)
6014 "LEFT JOIN pg_catalog.pg_description d\n"
6015 " ON d.classoid = fdw.tableoid "
6016 "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
6017
6018 if (!validateSQLNamePattern(&buf, pattern, false, false,
6019 NULL, "fdwname", NULL, NULL,
6020 NULL, 1))
6021 {
6023 return false;
6024 }
6025
6026 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6027
6028 res = PSQLexec(buf.data);
6030 if (!res)
6031 return false;
6032
6033 myopt.title = _("List of foreign-data wrappers");
6034 myopt.translate_header = true;
6035
6036 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6037
6038 PQclear(res);
6039 return true;
6040}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listForeignServers()

bool listForeignServers ( const char pattern,
bool  verbose 
)
extern

Definition at line 6048 of file describe.c.

6049{
6051 PGresult *res;
6053
6055
6056 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign servers"));
6058 "SELECT s.srvname AS \"%s\",\n"
6059 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
6060 " f.fdwname AS \"%s\"",
6061 gettext_noop("Name"),
6062 gettext_noop("Owner"),
6063 gettext_noop("Foreign-data wrapper"));
6064
6065 if (verbose)
6066 {
6067 appendPQExpBufferStr(&buf, ",\n ");
6068 printACLColumn(&buf, "s.srvacl");
6070 ",\n"
6071 " s.srvtype AS \"%s\",\n"
6072 " s.srvversion AS \"%s\",\n"
6073 " CASE WHEN srvoptions IS NULL THEN '' ELSE "
6074 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6075 " pg_catalog.quote_ident(option_name) || ' ' || "
6076 " pg_catalog.quote_literal(option_value) FROM "
6077 " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
6078 " END AS \"%s\",\n"
6079 " d.description AS \"%s\"",
6080 gettext_noop("Type"),
6081 gettext_noop("Version"),
6082 gettext_noop("FDW options"),
6083 gettext_noop("Description"));
6084 }
6085
6087 "\nFROM pg_catalog.pg_foreign_server s\n"
6088 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
6089
6090 if (verbose)
6092 "LEFT JOIN pg_catalog.pg_description d\n "
6093 "ON d.classoid = s.tableoid AND d.objoid = s.oid "
6094 "AND d.objsubid = 0\n");
6095
6096 if (!validateSQLNamePattern(&buf, pattern, false, false,
6097 NULL, "s.srvname", NULL, NULL,
6098 NULL, 1))
6099 {
6101 return false;
6102 }
6103
6104 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6105
6106 res = PSQLexec(buf.data);
6108 if (!res)
6109 return false;
6110
6111 myopt.title = _("List of foreign servers");
6112 myopt.translate_header = true;
6113
6114 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6115
6116 PQclear(res);
6117 return true;
6118}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listForeignTables()

bool listForeignTables ( const char pattern,
bool  verbose 
)
extern

Definition at line 6183 of file describe.c.

6184{
6186 PGresult *res;
6188
6190
6191 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign tables"));
6193 "SELECT n.nspname AS \"%s\",\n"
6194 " c.relname AS \"%s\",\n"
6195 " s.srvname AS \"%s\"",
6196 gettext_noop("Schema"),
6197 gettext_noop("Table"),
6198 gettext_noop("Server"));
6199
6200 if (verbose)
6202 ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
6203 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6204 " pg_catalog.quote_ident(option_name) || ' ' || "
6205 " pg_catalog.quote_literal(option_value) FROM "
6206 " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
6207 " END AS \"%s\",\n"
6208 " d.description AS \"%s\"",
6209 gettext_noop("FDW options"),
6210 gettext_noop("Description"));
6211
6213 "\nFROM pg_catalog.pg_foreign_table ft\n"
6214 " INNER JOIN pg_catalog.pg_class c"
6215 " ON c.oid = ft.ftrelid\n"
6216 " INNER JOIN pg_catalog.pg_namespace n"
6217 " ON n.oid = c.relnamespace\n"
6218 " INNER JOIN pg_catalog.pg_foreign_server s"
6219 " ON s.oid = ft.ftserver\n");
6220 if (verbose)
6222 " LEFT JOIN pg_catalog.pg_description d\n"
6223 " ON d.classoid = c.tableoid AND "
6224 "d.objoid = c.oid AND d.objsubid = 0\n");
6225
6226 if (!validateSQLNamePattern(&buf, pattern, false, false,
6227 "n.nspname", "c.relname", NULL,
6228 "pg_catalog.pg_table_is_visible(c.oid)",
6229 NULL, 3))
6230 {
6232 return false;
6233 }
6234
6235 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6236
6237 res = PSQLexec(buf.data);
6239 if (!res)
6240 return false;
6241
6242 myopt.title = _("List of foreign tables");
6243 myopt.translate_header = true;
6244
6245 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6246
6247 PQclear(res);
6248 return true;
6249}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listLanguages()

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

Definition at line 4538 of file describe.c.

4539{
4541 PGresult *res;
4543
4545
4546 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching procedural languages"));
4548 "SELECT l.lanname AS \"%s\",\n"
4549 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4550 " l.lanpltrusted AS \"%s\"",
4551 gettext_noop("Name"),
4552 gettext_noop("Owner"),
4553 gettext_noop("Trusted"));
4554
4555 if (verbose)
4556 {
4558 ",\n NOT l.lanispl AS \"%s\",\n"
4559 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4560 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4561 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4562 gettext_noop("Internal language"),
4563 gettext_noop("Call handler"),
4564 gettext_noop("Validator"),
4565 gettext_noop("Inline handler"));
4566 printACLColumn(&buf, "l.lanacl");
4567 }
4568
4570 ",\n d.description AS \"%s\""
4571 "\nFROM pg_catalog.pg_language l\n"
4572 "LEFT JOIN pg_catalog.pg_description d\n"
4573 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4574 " AND d.objsubid = 0\n",
4575 gettext_noop("Description"));
4576
4577 if (pattern)
4578 {
4579 if (!validateSQLNamePattern(&buf, pattern, false, false,
4580 NULL, "l.lanname", NULL, NULL,
4581 NULL, 2))
4582 {
4584 return false;
4585 }
4586 }
4587
4588 if (!showSystem && !pattern)
4589 appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
4590
4591
4592 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4593
4594 res = PSQLexec(buf.data);
4596 if (!res)
4597 return false;
4598
4599 myopt.title = _("List of languages");
4600 myopt.translate_header = true;
4601
4602 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4603
4604 PQclear(res);
4605 return true;
4606}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listLargeObjects()

bool listLargeObjects ( bool  verbose)
extern

Definition at line 7427 of file describe.c.

7428{
7430 PGresult *res;
7432
7434
7435 printfPQExpBuffer(&buf, "/* %s */\n", _("Get large objects"));
7437 "SELECT oid as \"%s\",\n"
7438 " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
7439 gettext_noop("ID"),
7440 gettext_noop("Owner"));
7441
7442 if (verbose)
7443 {
7444 printACLColumn(&buf, "lomacl");
7445 appendPQExpBufferStr(&buf, ",\n ");
7446 }
7447
7449 "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
7450 "FROM pg_catalog.pg_largeobject_metadata\n"
7451 "ORDER BY oid",
7452 gettext_noop("Description"));
7453
7454 res = PSQLexec(buf.data);
7456 if (!res)
7457 return false;
7458
7459 myopt.title = _("Large objects");
7460 myopt.translate_header = true;
7461
7462 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7463
7464 PQclear(res);
7465 return true;
7466}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), and verbose.

Referenced by exec_command_d(), and exec_command_lo().

◆ listOperatorClasses()

bool listOperatorClasses ( const char access_method_pattern,
const char type_pattern,
bool  verbose 
)
extern

Definition at line 7036 of file describe.c.

7038{
7040 PGresult *res;
7042 bool have_where = false;
7043 static const bool translate_columns[] = {false, false, false, false, false, false, false};
7044
7046
7047 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operator classes"));
7049 "SELECT\n"
7050 " am.amname AS \"%s\",\n"
7051 " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
7052 " CASE\n"
7053 " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
7054 " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
7055 " ELSE NULL\n"
7056 " END AS \"%s\",\n"
7057 " CASE\n"
7058 " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
7059 " THEN pg_catalog.format('%%I', c.opcname)\n"
7060 " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
7061 " END AS \"%s\",\n"
7062 " (CASE WHEN c.opcdefault\n"
7063 " THEN '%s'\n"
7064 " ELSE '%s'\n"
7065 " END) AS \"%s\"",
7066 gettext_noop("AM"),
7067 gettext_noop("Input type"),
7068 gettext_noop("Storage type"),
7069 gettext_noop("Operator class"),
7070 gettext_noop("yes"),
7071 gettext_noop("no"),
7072 gettext_noop("Default?"));
7073 if (verbose)
7075 ",\n CASE\n"
7076 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7077 " THEN pg_catalog.format('%%I', of.opfname)\n"
7078 " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
7079 " END AS \"%s\",\n"
7080 " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
7081 gettext_noop("Operator family"),
7082 gettext_noop("Owner"));
7084 "\nFROM pg_catalog.pg_opclass c\n"
7085 " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
7086 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
7087 " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
7088 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
7089 if (verbose)
7091 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
7092 " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
7093
7096 false, false, NULL, "am.amname", NULL, NULL,
7097 &have_where, 1))
7098 goto error_return;
7099 if (type_pattern)
7100 {
7101 /* Match type name pattern against either internal or external name */
7103 "tn.nspname", "t.typname",
7104 "pg_catalog.format_type(t.oid, NULL)",
7105 "pg_catalog.pg_type_is_visible(t.oid)",
7106 NULL, 3))
7107 goto error_return;
7108 }
7109
7110 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
7111 res = PSQLexec(buf.data);
7113 if (!res)
7114 return false;
7115
7116 myopt.title = _("List of operator classes");
7117 myopt.translate_header = true;
7118 myopt.translate_columns = translate_columns;
7119 myopt.n_translate_columns = lengthof(translate_columns);
7120
7121 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7122
7123 PQclear(res);
7124 return true;
7125
7128 return false;
7129}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listOperatorFamilies()

bool listOperatorFamilies ( const char access_method_pattern,
const char type_pattern,
bool  verbose 
)
extern

Definition at line 7138 of file describe.c.

7140{
7142 PGresult *res;
7144 bool have_where = false;
7145 static const bool translate_columns[] = {false, false, false, false};
7146
7148
7149 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operator families"));
7151 "SELECT\n"
7152 " am.amname AS \"%s\",\n"
7153 " CASE\n"
7154 " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
7155 " THEN pg_catalog.format('%%I', f.opfname)\n"
7156 " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
7157 " END AS \"%s\",\n"
7158 " (SELECT\n"
7159 " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
7160 " FROM pg_catalog.pg_opclass oc\n"
7161 " WHERE oc.opcfamily = f.oid) \"%s\"",
7162 gettext_noop("AM"),
7163 gettext_noop("Operator family"),
7164 gettext_noop("Applicable types"));
7165 if (verbose)
7167 ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
7168 gettext_noop("Owner"));
7170 "\nFROM pg_catalog.pg_opfamily f\n"
7171 " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
7172 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
7173
7176 false, false, NULL, "am.amname", NULL, NULL,
7177 &have_where, 1))
7178 goto error_return;
7179 if (type_pattern)
7180 {
7182 " %s EXISTS (\n"
7183 " SELECT 1\n"
7184 " FROM pg_catalog.pg_type t\n"
7185 " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
7186 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
7187 " WHERE oc.opcfamily = f.oid\n",
7188 have_where ? "AND" : "WHERE");
7189 /* Match type name pattern against either internal or external name */
7190 if (!validateSQLNamePattern(&buf, type_pattern, true, false,
7191 "tn.nspname", "t.typname",
7192 "pg_catalog.format_type(t.oid, NULL)",
7193 "pg_catalog.pg_type_is_visible(t.oid)",
7194 NULL, 3))
7195 goto error_return;
7196 appendPQExpBufferStr(&buf, " )\n");
7197 }
7198
7199 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
7200 res = PSQLexec(buf.data);
7202 if (!res)
7203 return false;
7204
7205 myopt.title = _("List of operator families");
7206 myopt.translate_header = true;
7207 myopt.translate_columns = translate_columns;
7208 myopt.n_translate_columns = lengthof(translate_columns);
7209
7210 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7211
7212 PQclear(res);
7213 return true;
7214
7217 return false;
7218}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listOpFamilyFunctions()

bool listOpFamilyFunctions ( const char access_method_pattern,
const char family_pattern,
bool  verbose 
)
extern

Definition at line 7336 of file describe.c.

7338{
7340 PGresult *res;
7342 bool have_where = false;
7343 static const bool translate_columns[] = {false, false, false, false, false, false};
7344
7346
7347 printfPQExpBuffer(&buf, "/* %s */\n",
7348 _("Get support functions of matching operator families"));
7350 "SELECT\n"
7351 " am.amname AS \"%s\",\n"
7352 " CASE\n"
7353 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7354 " THEN pg_catalog.format('%%I', of.opfname)\n"
7355 " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
7356 " END AS \"%s\",\n"
7357 " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
7358 " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
7359 " ap.amprocnum AS \"%s\"\n",
7360 gettext_noop("AM"),
7361 gettext_noop("Operator family"),
7362 gettext_noop("Registered left type"),
7363 gettext_noop("Registered right type"),
7364 gettext_noop("Number"));
7365
7366 if (!verbose)
7368 ", p.proname AS \"%s\"\n",
7369 gettext_noop("Function"));
7370 else
7372 ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
7373 gettext_noop("Function"));
7374
7376 "FROM pg_catalog.pg_amproc ap\n"
7377 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
7378 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
7379 " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
7380 " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
7381
7383 {
7385 false, false, NULL, "am.amname",
7386 NULL, NULL,
7387 &have_where, 1))
7388 goto error_return;
7389 }
7390 if (family_pattern)
7391 {
7393 "ns.nspname", "of.opfname", NULL, NULL,
7394 NULL, 3))
7395 goto error_return;
7396 }
7397
7398 appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
7399 " ap.amproclefttype = ap.amprocrighttype DESC,\n"
7400 " 3, 4, 5;");
7401
7402 res = PSQLexec(buf.data);
7404 if (!res)
7405 return false;
7406
7407 myopt.title = _("List of support functions of operator families");
7408 myopt.translate_header = true;
7409 myopt.translate_columns = translate_columns;
7410 myopt.n_translate_columns = lengthof(translate_columns);
7411
7412 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7413
7414 PQclear(res);
7415 return true;
7416
7419 return false;
7420}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listOpFamilyOperators()

bool listOpFamilyOperators ( const char access_method_pattern,
const char family_pattern,
bool  verbose 
)
extern

Definition at line 7228 of file describe.c.

7230{
7232 PGresult *res;
7234 bool have_where = false;
7235
7236 static const bool translate_columns[] = {false, false, false, false, false, false, true};
7237
7239
7240 printfPQExpBuffer(&buf, "/* %s */\n", _("Get operators of matching operator families"));
7242 "SELECT\n"
7243 " am.amname AS \"%s\",\n"
7244 " CASE\n"
7245 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7246 " THEN pg_catalog.format('%%I', of.opfname)\n"
7247 " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
7248 " END AS \"%s\",\n"
7249 " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
7250 " o.amopstrategy AS \"%s\",\n"
7251 " CASE o.amoppurpose\n"
7252 " WHEN " CppAsString2(AMOP_ORDER) " THEN '%s'\n"
7253 " WHEN " CppAsString2(AMOP_SEARCH) " THEN '%s'\n"
7254 " END AS \"%s\"\n",
7255 gettext_noop("AM"),
7256 gettext_noop("Operator family"),
7257 gettext_noop("Operator"),
7258 gettext_noop("Strategy"),
7259 gettext_noop("ordering"),
7260 gettext_noop("search"),
7261 gettext_noop("Purpose"));
7262
7263 if (verbose)
7265 ", ofs.opfname AS \"%s\",\n"
7266 " CASE\n"
7267 " WHEN p.proleakproof THEN '%s'\n"
7268 " ELSE '%s'\n"
7269 " END AS \"%s\"\n",
7270 gettext_noop("Sort opfamily"),
7271 gettext_noop("yes"),
7272 gettext_noop("no"),
7273 gettext_noop("Leakproof?"));
7275 "FROM pg_catalog.pg_amop o\n"
7276 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
7277 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
7278 " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
7279 if (verbose)
7281 " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n"
7282 " LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
7283 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = op.oprcode\n");
7284
7286 {
7288 false, false, NULL, "am.amname",
7289 NULL, NULL,
7290 &have_where, 1))
7291 goto error_return;
7292 }
7293
7294 if (family_pattern)
7295 {
7297 "nsf.nspname", "of.opfname", NULL, NULL,
7298 NULL, 3))
7299 goto error_return;
7300 }
7301
7302 appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
7303 " o.amoplefttype = o.amoprighttype DESC,\n"
7304 " pg_catalog.format_type(o.amoplefttype, NULL),\n"
7305 " pg_catalog.format_type(o.amoprighttype, NULL),\n"
7306 " o.amopstrategy;");
7307
7308 res = PSQLexec(buf.data);
7310 if (!res)
7311 return false;
7312
7313 myopt.title = _("List of operators of operator families");
7314 myopt.translate_header = true;
7315 myopt.translate_columns = translate_columns;
7316 myopt.n_translate_columns = lengthof(translate_columns);
7317
7318 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7319
7320 PQclear(res);
7321 return true;
7322
7325 return false;
7326}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listPartitionedTables()

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

Definition at line 4339 of file describe.c.

4340{
4341 bool showTables = strchr(reltypes, 't') != NULL;
4342 bool showIndexes = strchr(reltypes, 'i') != NULL;
4343 bool showNested = strchr(reltypes, 'n') != NULL;
4345 PQExpBufferData title;
4346 PGresult *res;
4348 bool translate_columns[] = {false, false, false, false, false, false, false, false, false, false};
4349 const char *tabletitle;
4350 bool mixed_output = false;
4351
4352 /* If no relation kind was selected, show them all */
4353 if (!showTables && !showIndexes)
4354 showTables = showIndexes = true;
4355
4356 if (showIndexes && !showTables)
4357 tabletitle = _("List of partitioned indexes"); /* \dPi */
4358 else if (showTables && !showIndexes)
4359 tabletitle = _("List of partitioned tables"); /* \dPt */
4360 else
4361 {
4362 /* show all kinds */
4363 tabletitle = _("List of partitioned relations");
4364 mixed_output = true;
4365 }
4366
4368
4369 printfPQExpBuffer(&buf, "/* %s */\n",
4370 _("Get matching partitioned relations"));
4372 "SELECT n.nspname as \"%s\",\n"
4373 " c.relname as \"%s\",\n"
4374 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4375 gettext_noop("Schema"),
4376 gettext_noop("Name"),
4377 gettext_noop("Owner"));
4378
4379 if (mixed_output)
4380 {
4382 ",\n CASE c.relkind"
4383 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
4384 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
4385 " END as \"%s\"",
4386 gettext_noop("partitioned table"),
4387 gettext_noop("partitioned index"),
4388 gettext_noop("Type"));
4389
4390 translate_columns[3] = true;
4391 }
4392
4393 if (showNested || pattern)
4395 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4396 gettext_noop("Parent name"));
4397
4398 if (showIndexes)
4400 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4401 gettext_noop("Table"));
4402
4403 if (verbose)
4404 {
4405 /*
4406 * Table access methods were introduced in v12, and can be set on
4407 * partitioned tables since v17.
4408 */
4409 appendPQExpBuffer(&buf, ",\n am.amname as \"%s\"",
4410 gettext_noop("Access method"));
4411
4412 if (showNested)
4413 {
4415 ",\n s.dps as \"%s\"",
4416 gettext_noop("Leaf partition size"));
4418 ",\n s.tps as \"%s\"",
4419 gettext_noop("Total size"));
4420 }
4421 else
4422 /* Sizes of all partitions are considered in this case. */
4424 ",\n s.tps as \"%s\"",
4425 gettext_noop("Total size"));
4426
4428 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4429 gettext_noop("Description"));
4430 }
4431
4433 "\nFROM pg_catalog.pg_class c"
4434 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4435
4436 if (showIndexes)
4438 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4439 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4440
4441 if (showNested || pattern)
4443 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4444
4445 if (verbose)
4446 {
4448 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4449
4450 if (pset.sversion < 120000)
4451 {
4453 ",\n LATERAL (WITH RECURSIVE d\n"
4454 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4455 " FROM pg_catalog.pg_inherits\n"
4456 " WHERE inhparent = c.oid\n"
4457 " UNION ALL\n"
4458 " SELECT inhrelid, level + 1\n"
4459 " FROM pg_catalog.pg_inherits i\n"
4460 " JOIN d ON i.inhparent = d.oid)\n"
4461 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4462 "d.oid))) AS tps,\n"
4463 " pg_catalog.pg_size_pretty(sum("
4464 "\n CASE WHEN d.level = 1"
4465 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4466 " FROM d) s");
4467 }
4468 else
4469 {
4470 /* PostgreSQL 12 has pg_partition_tree function */
4472 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4473 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4474 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4475 " ELSE 0 END)) AS dps"
4476 ",\n pg_catalog.pg_size_pretty(sum("
4477 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4478 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4479 }
4480 }
4481
4482 appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4483 if (showTables)
4485 if (showIndexes)
4487 appendPQExpBufferStr(&buf, "''"); /* dummy */
4488 appendPQExpBufferStr(&buf, ")\n");
4489
4490 appendPQExpBufferStr(&buf, !showNested && !pattern ?
4491 " AND NOT c.relispartition\n" : "");
4492
4493 if (!pattern)
4494 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4495 " AND n.nspname !~ '^pg_toast'\n"
4496 " AND n.nspname <> 'information_schema'\n");
4497
4498 if (!validateSQLNamePattern(&buf, pattern, true, false,
4499 "n.nspname", "c.relname", NULL,
4500 "pg_catalog.pg_table_is_visible(c.oid)",
4501 NULL, 3))
4502 {
4504 return false;
4505 }
4506
4507 appendPQExpBuffer(&buf, "ORDER BY \"Schema\", %s%s\"Name\";",
4508 mixed_output ? "\"Type\" DESC, " : "",
4509 showNested || pattern ? "\"Parent name\" NULLS FIRST, " : "");
4510
4511 res = PSQLexec(buf.data);
4513 if (!res)
4514 return false;
4515
4516 initPQExpBuffer(&title);
4518
4519 myopt.title = title.data;
4520 myopt.translate_header = true;
4521 myopt.translate_columns = translate_columns;
4522 myopt.n_translate_columns = lengthof(translate_columns);
4523
4524 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4525
4526 termPQExpBuffer(&title);
4527
4528 PQclear(res);
4529 return true;
4530}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, PQExpBufferData::data, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listPublications()

bool listPublications ( const char pattern)

Definition at line 6481 of file describe.c.

6482{
6484 PGresult *res;
6486 static const bool translate_columns[] = {false, false, false, false, false, false, false, false, false, false};
6487
6489
6490 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching publications"));
6492 "SELECT pubname AS \"%s\",\n"
6493 " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6494 " puballtables AS \"%s\"",
6495 gettext_noop("Name"),
6496 gettext_noop("Owner"),
6497 gettext_noop("All tables"));
6498
6499 if (pset.sversion >= 190000)
6501 ",\n puballsequences AS \"%s\"",
6502 gettext_noop("All sequences"));
6503
6505 ",\n pubinsert AS \"%s\",\n"
6506 " pubupdate AS \"%s\",\n"
6507 " pubdelete AS \"%s\"",
6508 gettext_noop("Inserts"),
6509 gettext_noop("Updates"),
6510 gettext_noop("Deletes"));
6511 if (pset.sversion >= 110000)
6513 ",\n pubtruncate AS \"%s\"",
6514 gettext_noop("Truncates"));
6515 if (pset.sversion >= 180000)
6517 ",\n (CASE pubgencols\n"
6518 " WHEN '%c' THEN 'none'\n"
6519 " WHEN '%c' THEN 'stored'\n"
6520 " END) AS \"%s\"",
6523 gettext_noop("Generated columns"));
6524 if (pset.sversion >= 130000)
6526 ",\n pubviaroot AS \"%s\"",
6527 gettext_noop("Via root"));
6528
6530 "\nFROM pg_catalog.pg_publication\n");
6531
6532 if (!validateSQLNamePattern(&buf, pattern, false, false,
6533 NULL, "pubname", NULL,
6534 NULL,
6535 NULL, 1))
6536 {
6538 return false;
6539 }
6540
6541 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6542
6543 res = PSQLexec(buf.data);
6545 if (!res)
6546 return false;
6547
6548 myopt.title = _("List of publications");
6549 myopt.translate_header = true;
6550 myopt.translate_columns = translate_columns;
6551 myopt.n_translate_columns = lengthof(translate_columns);
6552
6553 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6554
6555 PQclear(res);
6556
6557 return true;
6558}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::sversion, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listSchemas()

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

Definition at line 5259 of file describe.c.

5260{
5262 PGresult *res;
5264 int pub_schema_tuples = 0;
5265 char **footers = NULL;
5266
5268
5269 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching schemas"));
5271 "SELECT n.nspname AS \"%s\",\n"
5272 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5273 gettext_noop("Name"),
5274 gettext_noop("Owner"));
5275
5276 if (verbose)
5277 {
5278 appendPQExpBufferStr(&buf, ",\n ");
5279 printACLColumn(&buf, "n.nspacl");
5281 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5282 gettext_noop("Description"));
5283 }
5284
5286 "\nFROM pg_catalog.pg_namespace n\n");
5287
5288 if (!showSystem && !pattern)
5290 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5291
5292 if (!validateSQLNamePattern(&buf, pattern,
5293 !showSystem && !pattern, false,
5294 NULL, "n.nspname", NULL,
5295 NULL,
5296 NULL, 2))
5297 goto error_return;
5298
5299 appendPQExpBufferStr(&buf, "ORDER BY 1;");
5300
5301 res = PSQLexec(buf.data);
5302 if (!res)
5303 goto error_return;
5304
5305 myopt.title = _("List of schemas");
5306 myopt.translate_header = true;
5307
5308 if (pattern && pset.sversion >= 150000)
5309 {
5311 int i;
5312
5313 printfPQExpBuffer(&buf, "/* %s */\n",
5314 _("Get publications that publish this schema"));
5316 "SELECT pubname \n"
5317 "FROM pg_catalog.pg_publication p\n"
5318 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5319 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5320 "WHERE n.nspname = '%s'\n"
5321 "ORDER BY 1",
5322 pattern);
5323 result = PSQLexec(buf.data);
5324 if (!result)
5325 goto error_return;
5326 else
5328
5329 if (pub_schema_tuples > 0)
5330 {
5331 /*
5332 * Allocate memory for footers. Size of footers will be 1 (for
5333 * storing "Included in publications:" string) + publication
5334 * schema mapping count + 1 (for storing NULL).
5335 */
5336 footers = pg_malloc_array(char *, 1 + pub_schema_tuples + 1);
5337 footers[0] = pg_strdup(_("Included in publications:"));
5338
5339 /* Might be an empty set - that's ok */
5340 for (i = 0; i < pub_schema_tuples; i++)
5341 {
5342 printfPQExpBuffer(&buf, " \"%s\"",
5343 PQgetvalue(result, i, 0));
5344
5345 footers[i + 1] = pg_strdup(buf.data);
5346 }
5347
5348 footers[i + 1] = NULL;
5349 myopt.footers = footers;
5350 }
5351
5352 PQclear(result);
5353 }
5354
5355 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5356
5358 PQclear(res);
5359
5360 /* Free the memory allocated for the footer */
5361 if (footers)
5362 {
5363 char **footer = NULL;
5364
5365 for (footer = footers; *footer; footer++)
5366 pg_free(*footer);
5367
5368 pg_free(footers);
5369 }
5370
5371 return true;
5372
5375 return false;
5376}
uint32 result
#define pg_malloc_array(type, count)
Definition fe_memutils.h:66

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, i, initPQExpBuffer(), _psqlSettings::logfile, pg_free(), pg_malloc_array, pg_strdup(), _psqlSettings::popt, PQclear, PQgetvalue, PQntuples, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, result, _psqlSettings::sversion, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTables()

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

Definition at line 4072 of file describe.c.

4073{
4074 bool showTables = strchr(tabtypes, 't') != NULL;
4075 bool showIndexes = strchr(tabtypes, 'i') != NULL;
4076 bool showViews = strchr(tabtypes, 'v') != NULL;
4077 bool showMatViews = strchr(tabtypes, 'm') != NULL;
4078 bool showSeq = strchr(tabtypes, 's') != NULL;
4079 bool showForeign = strchr(tabtypes, 'E') != NULL;
4080 bool showPropGraphs = strchr(tabtypes, 'G') != NULL;
4081
4082 int ntypes;
4084 PGresult *res;
4086 int cols_so_far;
4087 bool translate_columns[] = {false, false, true, false, false, false, false, false, false};
4088
4089 /* Count the number of explicitly-requested relation types */
4092 /* If none, we default to \dtvmsEG (but see also command.c) */
4093 if (ntypes == 0)
4095
4097
4098 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching relations"));
4100 "SELECT n.nspname as \"%s\",\n"
4101 " c.relname as \"%s\",\n"
4102 " CASE c.relkind"
4103 " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
4104 " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
4105 " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
4106 " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
4107 " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
4108 " WHEN " CppAsString2(RELKIND_TOASTVALUE) " THEN '%s'"
4109 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
4110 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
4111 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
4112 " WHEN " CppAsString2(RELKIND_PROPGRAPH) " THEN '%s'"
4113 " END as \"%s\",\n"
4114 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4115 gettext_noop("Schema"),
4116 gettext_noop("Name"),
4117 gettext_noop("table"),
4118 gettext_noop("view"),
4119 gettext_noop("materialized view"),
4120 gettext_noop("index"),
4121 gettext_noop("sequence"),
4122 gettext_noop("TOAST table"),
4123 gettext_noop("foreign table"),
4124 gettext_noop("partitioned table"),
4125 gettext_noop("partitioned index"),
4126 gettext_noop("property graph"),
4127 gettext_noop("Type"),
4128 gettext_noop("Owner"));
4129 cols_so_far = 4;
4130
4131 if (showIndexes)
4132 {
4134 ",\n c2.relname as \"%s\"",
4135 gettext_noop("Table"));
4136 cols_so_far++;
4137 }
4138
4139 if (verbose)
4140 {
4141 /*
4142 * Show whether a relation is permanent, temporary, or unlogged.
4143 */
4145 ",\n CASE c.relpersistence "
4146 "WHEN " CppAsString2(RELPERSISTENCE_PERMANENT) " THEN '%s' "
4147 "WHEN " CppAsString2(RELPERSISTENCE_TEMP) " THEN '%s' "
4148 "WHEN " CppAsString2(RELPERSISTENCE_UNLOGGED) " THEN '%s' "
4149 "END as \"%s\"",
4150 gettext_noop("permanent"),
4151 gettext_noop("temporary"),
4152 gettext_noop("unlogged"),
4153 gettext_noop("Persistence"));
4154 translate_columns[cols_so_far] = true;
4155
4156 /*
4157 * We don't bother to count cols_so_far below here, as there's no need
4158 * to; this might change with future additions to the output columns.
4159 */
4160
4161 /*
4162 * Access methods exist for tables, materialized views and indexes.
4163 * This has been introduced in PostgreSQL 12 for tables.
4164 */
4165 if (pset.sversion >= 120000 && !pset.hide_tableam &&
4168 ",\n am.amname as \"%s\"",
4169 gettext_noop("Access method"));
4170
4172 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4173 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4174 gettext_noop("Size"),
4175 gettext_noop("Description"));
4176 }
4177
4179 "\nFROM pg_catalog.pg_class c"
4180 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4181
4182 if (pset.sversion >= 120000 && !pset.hide_tableam &&
4185 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4186
4187 if (showIndexes)
4189 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4190 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4191
4192 appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4193 if (showTables)
4194 {
4197 /* with 'S' or a pattern, allow 't' to match TOAST tables too */
4198 if (showSystem || pattern)
4200 }
4201 if (showViews)
4203 if (showMatViews)
4205 if (showIndexes)
4208 if (showSeq)
4210 if (showSystem || pattern)
4211 appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
4212 if (showForeign)
4214 if (showPropGraphs)
4216
4217 appendPQExpBufferStr(&buf, "''"); /* dummy */
4218 appendPQExpBufferStr(&buf, ")\n");
4219
4220 if (!showSystem && !pattern)
4221 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4222 " AND n.nspname !~ '^pg_toast'\n"
4223 " AND n.nspname <> 'information_schema'\n");
4224
4225 if (!validateSQLNamePattern(&buf, pattern, true, false,
4226 "n.nspname", "c.relname", NULL,
4227 "pg_catalog.pg_table_is_visible(c.oid)",
4228 NULL, 3))
4229 {
4231 return false;
4232 }
4233
4234 appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
4235
4236 res = PSQLexec(buf.data);
4238 if (!res)
4239 return false;
4240
4241 /*
4242 * Most functions in this file are content to print an empty table when
4243 * there are no matching objects. We intentionally deviate from that
4244 * here, but only in !quiet mode, for historical reasons.
4245 */
4246 if (PQntuples(res) == 0 && !pset.quiet)
4247 {
4248 if (pattern)
4249 {
4250 if (ntypes != 1)
4251 pg_log_error("Did not find any relations named \"%s\".",
4252 pattern);
4253 else if (showTables)
4254 pg_log_error("Did not find any tables named \"%s\".",
4255 pattern);
4256 else if (showIndexes)
4257 pg_log_error("Did not find any indexes named \"%s\".",
4258 pattern);
4259 else if (showViews)
4260 pg_log_error("Did not find any views named \"%s\".",
4261 pattern);
4262 else if (showMatViews)
4263 pg_log_error("Did not find any materialized views named \"%s\".",
4264 pattern);
4265 else if (showSeq)
4266 pg_log_error("Did not find any sequences named \"%s\".",
4267 pattern);
4268 else if (showForeign)
4269 pg_log_error("Did not find any foreign tables named \"%s\".",
4270 pattern);
4271 else if (showPropGraphs)
4272 pg_log_error("Did not find any property graphs named \"%s\".",
4273 pattern);
4274 else /* should not get here */
4275 pg_log_error_internal("Did not find any ??? named \"%s\".",
4276 pattern);
4277 }
4278 else
4279 {
4280 if (ntypes != 1)
4281 pg_log_error("Did not find any relations.");
4282 else if (showTables)
4283 pg_log_error("Did not find any tables.");
4284 else if (showIndexes)
4285 pg_log_error("Did not find any indexes.");
4286 else if (showViews)
4287 pg_log_error("Did not find any views.");
4288 else if (showMatViews)
4289 pg_log_error("Did not find any materialized views.");
4290 else if (showSeq)
4291 pg_log_error("Did not find any sequences.");
4292 else if (showForeign)
4293 pg_log_error("Did not find any foreign tables.");
4294 else if (showPropGraphs)
4295 pg_log_error("Did not find any property graphs.");
4296 else /* should not get here */
4297 pg_log_error_internal("Did not find any ??? relations.");
4298 }
4299 }
4300 else
4301 {
4302 myopt.title =
4303 (ntypes != 1) ? _("List of relations") :
4304 (showTables) ? _("List of tables") :
4305 (showIndexes) ? _("List of indexes") :
4306 (showViews) ? _("List of views") :
4307 (showMatViews) ? _("List of materialized views") :
4308 (showSeq) ? _("List of sequences") :
4309 (showForeign) ? _("List of foreign tables") :
4310 (showPropGraphs) ? _("List of property graphs") :
4311 "List of ???"; /* should not get here */
4312 myopt.translate_header = true;
4313 myopt.translate_columns = translate_columns;
4314 myopt.n_translate_columns = lengthof(translate_columns);
4315
4316 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4317 }
4318
4319 PQclear(res);
4320 return true;
4321}
#define pg_log_error_internal(...)
Definition logging.h:162
bool hide_tableam
Definition settings.h:171

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, _psqlSettings::hide_tableam, initPQExpBuffer(), lengthof, _psqlSettings::logfile, pg_log_error, pg_log_error_internal, _psqlSettings::popt, PQclear, PQntuples, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, _psqlSettings::quiet, _psqlSettings::sversion, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTSConfigs()

bool listTSConfigs ( const char pattern,
bool  verbose 
)
extern

Definition at line 5768 of file describe.c.

5769{
5771 PGresult *res;
5773
5774 if (verbose)
5775 return listTSConfigsVerbose(pattern);
5776
5778
5779 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search configurations"));
5781 "SELECT\n"
5782 " n.nspname as \"%s\",\n"
5783 " c.cfgname as \"%s\",\n"
5784 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5785 "FROM pg_catalog.pg_ts_config c\n"
5786 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5787 gettext_noop("Schema"),
5788 gettext_noop("Name"),
5789 gettext_noop("Description")
5790 );
5791
5792 if (!validateSQLNamePattern(&buf, pattern, false, false,
5793 "n.nspname", "c.cfgname", NULL,
5794 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5795 NULL, 3))
5796 {
5798 return false;
5799 }
5800
5801 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5802
5803 res = PSQLexec(buf.data);
5805 if (!res)
5806 return false;
5807
5808 myopt.title = _("List of text search configurations");
5809 myopt.translate_header = true;
5810
5811 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5812
5813 PQclear(res);
5814 return true;
5815}
static bool listTSConfigsVerbose(const char *pattern)
Definition describe.c:5818

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), listTSConfigsVerbose(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTSDictionaries()

bool listTSDictionaries ( const char pattern,
bool  verbose 
)
extern

Definition at line 5636 of file describe.c.

5637{
5639 PGresult *res;
5641
5643
5644 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search dictionaries"));
5646 "SELECT\n"
5647 " n.nspname as \"%s\",\n"
5648 " d.dictname as \"%s\",\n",
5649 gettext_noop("Schema"),
5650 gettext_noop("Name"));
5651
5652 if (verbose)
5653 {
5655 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5656 " pg_catalog.pg_ts_template t\n"
5657 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5658 " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5659 " d.dictinitoption as \"%s\",\n",
5660 gettext_noop("Template"),
5661 gettext_noop("Init options"));
5662 }
5663
5665 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5666 gettext_noop("Description"));
5667
5668 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
5669 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5670
5671 if (!validateSQLNamePattern(&buf, pattern, false, false,
5672 "n.nspname", "d.dictname", NULL,
5673 "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5674 NULL, 3))
5675 {
5677 return false;
5678 }
5679
5680 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5681
5682 res = PSQLexec(buf.data);
5684 if (!res)
5685 return false;
5686
5687 myopt.title = _("List of text search dictionaries");
5688 myopt.translate_header = true;
5689
5690 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5691
5692 PQclear(res);
5693 return true;
5694}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTSParsers()

bool listTSParsers ( const char pattern,
bool  verbose 
)
extern

Definition at line 5384 of file describe.c.

5385{
5387 PGresult *res;
5389
5390 if (verbose)
5391 return listTSParsersVerbose(pattern);
5392
5394
5395 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search parsers"));
5397 "SELECT\n"
5398 " n.nspname as \"%s\",\n"
5399 " p.prsname as \"%s\",\n"
5400 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5401 "FROM pg_catalog.pg_ts_parser p\n"
5402 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5403 gettext_noop("Schema"),
5404 gettext_noop("Name"),
5405 gettext_noop("Description")
5406 );
5407
5408 if (!validateSQLNamePattern(&buf, pattern, false, false,
5409 "n.nspname", "p.prsname", NULL,
5410 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5411 NULL, 3))
5412 {
5414 return false;
5415 }
5416
5417 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5418
5419 res = PSQLexec(buf.data);
5421 if (!res)
5422 return false;
5423
5424 myopt.title = _("List of text search parsers");
5425 myopt.translate_header = true;
5426
5427 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5428
5429 PQclear(res);
5430 return true;
5431}
static bool listTSParsersVerbose(const char *pattern)
Definition describe.c:5437

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), listTSParsersVerbose(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTSTemplates()

bool listTSTemplates ( const char pattern,
bool  verbose 
)
extern

Definition at line 5702 of file describe.c.

5703{
5705 PGresult *res;
5707
5709
5710 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search templates"));
5711 if (verbose)
5713 "SELECT\n"
5714 " n.nspname AS \"%s\",\n"
5715 " t.tmplname AS \"%s\",\n"
5716 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5717 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5718 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5719 gettext_noop("Schema"),
5720 gettext_noop("Name"),
5721 gettext_noop("Init"),
5722 gettext_noop("Lexize"),
5723 gettext_noop("Description"));
5724 else
5726 "SELECT\n"
5727 " n.nspname AS \"%s\",\n"
5728 " t.tmplname AS \"%s\",\n"
5729 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5730 gettext_noop("Schema"),
5731 gettext_noop("Name"),
5732 gettext_noop("Description"));
5733
5734 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
5735 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5736
5737 if (!validateSQLNamePattern(&buf, pattern, false, false,
5738 "n.nspname", "t.tmplname", NULL,
5739 "pg_catalog.pg_ts_template_is_visible(t.oid)",
5740 NULL, 3))
5741 {
5743 return false;
5744 }
5745
5746 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5747
5748 res = PSQLexec(buf.data);
5750 if (!res)
5751 return false;
5752
5753 myopt.title = _("List of text search templates");
5754 myopt.translate_header = true;
5755
5756 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5757
5758 PQclear(res);
5759 return true;
5760}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listUserMappings()

bool listUserMappings ( const char pattern,
bool  verbose 
)
extern

Definition at line 6126 of file describe.c.

6127{
6129 PGresult *res;
6131
6133
6134 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching user mappings"));
6136 "SELECT um.srvname AS \"%s\",\n"
6137 " um.usename AS \"%s\"",
6138 gettext_noop("Server"),
6139 gettext_noop("User name"));
6140
6141 if (verbose)
6143 ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
6144 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6145 " pg_catalog.quote_ident(option_name) || ' ' || "
6146 " pg_catalog.quote_literal(option_value) FROM "
6147 " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
6148 " END AS \"%s\"",
6149 gettext_noop("FDW options"));
6150
6151 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
6152
6153 if (!validateSQLNamePattern(&buf, pattern, false, false,
6154 NULL, "um.srvname", "um.usename", NULL,
6155 NULL, 1))
6156 {
6158 return false;
6159 }
6160
6161 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6162
6163 res = PSQLexec(buf.data);
6165 if (!res)
6166 return false;
6167
6168 myopt.title = _("List of user mappings");
6169 myopt.translate_header = true;
6170
6171 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6172
6173 PQclear(res);
6174 return true;
6175}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ objectDescription()

bool objectDescription ( const char pattern,
bool  showSystem 
)
extern

Definition at line 1255 of file describe.c.

1256{
1258 PGresult *res;
1260 static const bool translate_columns[] = {false, false, true, false};
1261
1263
1264 printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching object comments"));
1266 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1267 "FROM (\n",
1268 gettext_noop("Schema"),
1269 gettext_noop("Name"),
1270 gettext_noop("Object"),
1271 gettext_noop("Description"));
1272
1273 /* Table constraint descriptions */
1275 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1276 " n.nspname as nspname,\n"
1277 " CAST(pgc.conname AS pg_catalog.text) as name,"
1278 " CAST('%s' AS pg_catalog.text) as object\n"
1279 " FROM pg_catalog.pg_constraint pgc\n"
1280 " JOIN pg_catalog.pg_class c "
1281 "ON c.oid = pgc.conrelid\n"
1282 " LEFT JOIN pg_catalog.pg_namespace n "
1283 " ON n.oid = c.relnamespace\n",
1284 gettext_noop("table constraint"));
1285
1286 if (!showSystem && !pattern)
1287 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1288 " AND n.nspname <> 'information_schema'\n");
1289
1290 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1291 false, "n.nspname", "pgc.conname", NULL,
1292 "pg_catalog.pg_table_is_visible(c.oid)",
1293 NULL, 3))
1294 goto error_return;
1295
1296 /* Domain constraint descriptions */
1298 "UNION ALL\n"
1299 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1300 " n.nspname as nspname,\n"
1301 " CAST(pgc.conname AS pg_catalog.text) as name,"
1302 " CAST('%s' AS pg_catalog.text) as object\n"
1303 " FROM pg_catalog.pg_constraint pgc\n"
1304 " JOIN pg_catalog.pg_type t "
1305 "ON t.oid = pgc.contypid\n"
1306 " LEFT JOIN pg_catalog.pg_namespace n "
1307 " ON n.oid = t.typnamespace\n",
1308 gettext_noop("domain constraint"));
1309
1310 if (!showSystem && !pattern)
1311 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1312 " AND n.nspname <> 'information_schema'\n");
1313
1314 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1315 false, "n.nspname", "pgc.conname", NULL,
1316 "pg_catalog.pg_type_is_visible(t.oid)",
1317 NULL, 3))
1318 goto error_return;
1319
1320 /* Operator class descriptions */
1322 "UNION ALL\n"
1323 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1324 " n.nspname as nspname,\n"
1325 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1326 " CAST('%s' AS pg_catalog.text) as object\n"
1327 " FROM pg_catalog.pg_opclass o\n"
1328 " JOIN pg_catalog.pg_am am ON "
1329 "o.opcmethod = am.oid\n"
1330 " JOIN pg_catalog.pg_namespace n ON "
1331 "n.oid = o.opcnamespace\n",
1332 gettext_noop("operator class"));
1333
1334 if (!showSystem && !pattern)
1335 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1336 " AND n.nspname <> 'information_schema'\n");
1337
1338 if (!validateSQLNamePattern(&buf, pattern, true, false,
1339 "n.nspname", "o.opcname", NULL,
1340 "pg_catalog.pg_opclass_is_visible(o.oid)",
1341 NULL, 3))
1342 goto error_return;
1343
1344 /* Operator family descriptions */
1346 "UNION ALL\n"
1347 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1348 " n.nspname as nspname,\n"
1349 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1350 " CAST('%s' AS pg_catalog.text) as object\n"
1351 " FROM pg_catalog.pg_opfamily opf\n"
1352 " JOIN pg_catalog.pg_am am "
1353 "ON opf.opfmethod = am.oid\n"
1354 " JOIN pg_catalog.pg_namespace n "
1355 "ON opf.opfnamespace = n.oid\n",
1356 gettext_noop("operator family"));
1357
1358 if (!showSystem && !pattern)
1359 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1360 " AND n.nspname <> 'information_schema'\n");
1361
1362 if (!validateSQLNamePattern(&buf, pattern, true, false,
1363 "n.nspname", "opf.opfname", NULL,
1364 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1365 NULL, 3))
1366 goto error_return;
1367
1368 /* Rule descriptions (ignore rules for views) */
1370 "UNION ALL\n"
1371 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1372 " n.nspname as nspname,\n"
1373 " CAST(r.rulename AS pg_catalog.text) as name,"
1374 " CAST('%s' AS pg_catalog.text) as object\n"
1375 " FROM pg_catalog.pg_rewrite r\n"
1376 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1377 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1378 " WHERE r.rulename != '_RETURN'\n",
1379 gettext_noop("rule"));
1380
1381 if (!showSystem && !pattern)
1382 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1383 " AND n.nspname <> 'information_schema'\n");
1384
1385 if (!validateSQLNamePattern(&buf, pattern, true, false,
1386 "n.nspname", "r.rulename", NULL,
1387 "pg_catalog.pg_table_is_visible(c.oid)",
1388 NULL, 3))
1389 goto error_return;
1390
1391 /* Trigger descriptions */
1393 "UNION ALL\n"
1394 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1395 " n.nspname as nspname,\n"
1396 " CAST(t.tgname AS pg_catalog.text) as name,"
1397 " CAST('%s' AS pg_catalog.text) as object\n"
1398 " FROM pg_catalog.pg_trigger t\n"
1399 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1400 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1401 gettext_noop("trigger"));
1402
1403 if (!showSystem && !pattern)
1404 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1405 " AND n.nspname <> 'information_schema'\n");
1406
1407 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1408 "n.nspname", "t.tgname", NULL,
1409 "pg_catalog.pg_table_is_visible(c.oid)",
1410 NULL, 3))
1411 goto error_return;
1412
1414 ") AS tt\n"
1415 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1416
1417 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1418
1419 res = PSQLexec(buf.data);
1421 if (!res)
1422 return false;
1423
1424 myopt.title = _("Object descriptions");
1425 myopt.translate_header = true;
1426 myopt.translate_columns = translate_columns;
1427 myopt.n_translate_columns = lengthof(translate_columns);
1428
1429 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1430
1431 PQclear(res);
1432 return true;
1433
1436 return false;
1437}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d().

◆ permissionsList()

bool permissionsList ( const char pattern,
bool  showSystem 
)
extern

Definition at line 1036 of file describe.c.

1037{
1039 PGresult *res;
1041 static const bool translate_columns[] = {false, false, true, false, false, false};
1042
1044
1045 /*
1046 * we ignore indexes and toast tables since they have no meaningful rights
1047 */
1048 printfPQExpBuffer(&buf, "/* %s */\n",
1049 _("Get access privileges of matching relations"));
1051 "SELECT n.nspname as \"%s\",\n"
1052 " c.relname as \"%s\",\n"
1053 " CASE c.relkind"
1054 " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
1055 " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
1056 " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
1057 " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
1058 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
1059 " WHEN " CppAsString2(RELKIND_PROPGRAPH) " THEN '%s'"
1060 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
1061 " END as \"%s\",\n"
1062 " ",
1063 gettext_noop("Schema"),
1064 gettext_noop("Name"),
1065 gettext_noop("table"),
1066 gettext_noop("view"),
1067 gettext_noop("materialized view"),
1068 gettext_noop("sequence"),
1069 gettext_noop("foreign table"),
1070 gettext_noop("property graph"),
1071 gettext_noop("partitioned table"),
1072 gettext_noop("Type"));
1073
1074 printACLColumn(&buf, "c.relacl");
1075
1076 /*
1077 * The formatting of attacl should match printACLColumn(). However, we
1078 * need no special case for an empty attacl, because the backend always
1079 * optimizes that back to NULL.
1080 */
1082 ",\n pg_catalog.array_to_string(ARRAY(\n"
1083 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1084 " FROM pg_catalog.pg_attribute a\n"
1085 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1086 " ), E'\\n') AS \"%s\"",
1087 gettext_noop("Column privileges"));
1088
1090 ",\n pg_catalog.array_to_string(ARRAY(\n"
1091 " SELECT polname\n"
1092 " || CASE WHEN NOT polpermissive THEN\n"
1093 " E' (RESTRICTIVE)'\n"
1094 " ELSE '' END\n"
1095 " || CASE WHEN polcmd != '*' THEN\n"
1096 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1097 " ELSE E':'\n"
1098 " END\n"
1099 " || CASE WHEN polqual IS NOT NULL THEN\n"
1100 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1101 " ELSE E''\n"
1102 " END\n"
1103 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1104 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1105 " ELSE E''\n"
1106 " END"
1107 " || CASE WHEN polroles <> '{0}' THEN\n"
1108 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1109 " ARRAY(\n"
1110 " SELECT rolname\n"
1111 " FROM pg_catalog.pg_roles\n"
1112 " WHERE oid = ANY (polroles)\n"
1113 " ORDER BY 1\n"
1114 " ), E', ')\n"
1115 " ELSE E''\n"
1116 " END\n"
1117 " FROM pg_catalog.pg_policy pol\n"
1118 " WHERE polrelid = c.oid), E'\\n')\n"
1119 " AS \"%s\"",
1120 gettext_noop("Policies"));
1121
1122 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
1123 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1124 "WHERE c.relkind IN ("
1132
1133 if (!showSystem && !pattern)
1134 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1135 " AND n.nspname <> 'information_schema'\n");
1136
1137 if (!validateSQLNamePattern(&buf, pattern, true, false,
1138 "n.nspname", "c.relname", NULL,
1139 "pg_catalog.pg_table_is_visible(c.oid)",
1140 NULL, 3))
1141 goto error_return;
1142
1143 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
1144
1145 res = PSQLexec(buf.data);
1146 if (!res)
1147 goto error_return;
1148
1149 printfPQExpBuffer(&buf, _("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
1158 PQclear(res);
1159 return true;
1160
1163 return false;
1164}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, fb(), gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, _psqlSettings::popt, PQclear, printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, termPQExpBuffer(), and validateSQLNamePattern().

Referenced by exec_command_d(), and exec_command_z().