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

Go to the source code of this file.

Functions

bool describeAggregates (const char *pattern, bool verbose, bool showSystem)
 
bool describeAccessMethods (const char *pattern, bool verbose)
 
bool describeTablespaces (const char *pattern, bool verbose)
 
bool describeFunctions (const char *functypes, const char *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 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 
)

Definition at line 147 of file describe.c.

148{
150 PGresult *res;
151 printQueryOpt myopt = pset.popt;
152 static const bool translate_columns[] = {false, true, false, false};
153
154 if (pset.sversion < 90600)
155 {
156 char sverbuf[32];
157
158 pg_log_error("The server (version %s) does not support access methods.",
160 sverbuf, sizeof(sverbuf)));
161 return true;
162 }
163
165
167 "SELECT amname AS \"%s\",\n"
168 " CASE amtype"
169 " WHEN " CppAsString2(AMTYPE_INDEX) " THEN '%s'"
170 " WHEN " CppAsString2(AMTYPE_TABLE) " THEN '%s'"
171 " END AS \"%s\"",
172 gettext_noop("Name"),
173 gettext_noop("Index"),
174 gettext_noop("Table"),
175 gettext_noop("Type"));
176
177 if (verbose)
178 {
180 ",\n amhandler AS \"%s\",\n"
181 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
182 gettext_noop("Handler"),
183 gettext_noop("Description"));
184 }
185
187 "\nFROM pg_catalog.pg_am\n");
188
189 if (!validateSQLNamePattern(&buf, pattern, false, false,
190 NULL, "amname", NULL,
191 NULL,
192 NULL, 1))
193 {
195 return false;
196 }
197
198 appendPQExpBufferStr(&buf, "ORDER BY 1;");
199
200 res = PSQLexec(buf.data);
202 if (!res)
203 return false;
204
205 myopt.title = _("List of access methods");
206 myopt.translate_header = true;
207 myopt.translate_columns = translate_columns;
208 myopt.n_translate_columns = lengthof(translate_columns);
209
210 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
211
212 PQclear(res);
213 return true;
214}
PGresult * PSQLexec(const char *query)
Definition: common.c:620
#define gettext_noop(x)
Definition: c.h:1153
#define CppAsString2(x)
Definition: c.h:349
#define lengthof(array)
Definition: c.h:745
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:6284
#define _(x)
Definition: elog.c:90
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3549
int verbose
#define pg_log_error(...)
Definition: logging.h:106
static char * buf
Definition: pg_test_fsync.c:72
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
PsqlSettings pset
Definition: startup.c:32
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
printQueryOpt popt
Definition: settings.h:100
FILE * logfile
Definition: settings.h:131
FILE * queryFout
Definition: settings.h:93
const bool * translate_columns
Definition: print.h:190
char * title
Definition: print.h:187
bool translate_header
Definition: print.h:189
int n_translate_columns
Definition: print.h:192

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

Referenced by exec_command_d().

◆ describeAggregates()

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

Definition at line 77 of file describe.c.

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

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

Referenced by exec_command_d().

◆ describeConfigurationParameters()

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

Definition at line 4655 of file describe.c.

4657{
4659 PGresult *res;
4660 printQueryOpt myopt = pset.popt;
4661
4664 "SELECT s.name AS \"%s\", "
4665 "pg_catalog.current_setting(s.name) AS \"%s\"",
4666 gettext_noop("Parameter"),
4667 gettext_noop("Value"));
4668
4669 if (verbose)
4670 {
4672 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4673 gettext_noop("Type"),
4674 gettext_noop("Context"));
4675 if (pset.sversion >= 150000)
4676 printACLColumn(&buf, "p.paracl");
4677 else
4678 appendPQExpBuffer(&buf, "NULL AS \"%s\"",
4679 gettext_noop("Access privileges"));
4680 }
4681
4682 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_settings s\n");
4683
4684 if (verbose && pset.sversion >= 150000)
4686 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4687 " ON pg_catalog.lower(s.name) = p.parname\n");
4688
4689 if (pattern)
4690 processSQLNamePattern(pset.db, &buf, pattern,
4691 false, false,
4692 NULL, "pg_catalog.lower(s.name)", NULL,
4693 NULL, NULL, NULL);
4694 else
4695 appendPQExpBufferStr(&buf, "WHERE s.source <> 'default' AND\n"
4696 " s.setting IS DISTINCT FROM s.boot_val\n");
4697
4698 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4699
4700 res = PSQLexec(buf.data);
4702 if (!res)
4703 return false;
4704
4705 if (pattern)
4706 myopt.title = _("List of configuration parameters");
4707 else
4708 myopt.title = _("List of non-default configuration parameters");
4709 myopt.translate_header = true;
4710
4711 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4712
4713 PQclear(res);
4714 return true;
4715}
static void printACLColumn(PQExpBuffer buf, const char *colname)
Definition: describe.c:6795
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)
Definition: string_utils.c:891
PGconn * db
Definition: settings.h:91

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, _psqlSettings::db, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), processSQLNamePattern(), pset, PSQLexec(), _psqlSettings::queryFout, res, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, 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 
)

Definition at line 294 of file describe.c.

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

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, formatPGVersionNumber(), gettext_noop, i, initPQExpBuffer(), lengthof, _psqlSettings::logfile, map_typename_pattern(), printQueryOpt::n_translate_columns, pg_log_error, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, snprintf, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, 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 
)

Definition at line 792 of file describe.c.

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

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

Referenced by exec_command_dfo().

◆ describePublications()

bool describePublications ( const char *  pattern)

Definition at line 6463 of file describe.c.

6464{
6466 int i;
6467 PGresult *res;
6468 bool has_pubtruncate;
6469 bool has_pubgencols;
6470 bool has_pubviaroot;
6471
6472 PQExpBufferData title;
6473 printTableContent cont;
6474
6475 if (pset.sversion < 100000)
6476 {
6477 char sverbuf[32];
6478
6479 pg_log_error("The server (version %s) does not support publications.",
6481 sverbuf, sizeof(sverbuf)));
6482 return true;
6483 }
6484
6485 has_pubtruncate = (pset.sversion >= 110000);
6486 has_pubgencols = (pset.sversion >= 180000);
6487 has_pubviaroot = (pset.sversion >= 130000);
6488
6490
6492 "SELECT oid, pubname,\n"
6493 " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6494 " puballtables, pubinsert, pubupdate, pubdelete");
6495 if (has_pubtruncate)
6497 ", pubtruncate");
6498 if (has_pubgencols)
6500 ", pubgencols");
6501 if (has_pubviaroot)
6503 ", pubviaroot");
6504
6506 "\nFROM pg_catalog.pg_publication\n");
6507
6508 if (!validateSQLNamePattern(&buf, pattern, false, false,
6509 NULL, "pubname", NULL,
6510 NULL,
6511 NULL, 1))
6512 {
6514 return false;
6515 }
6516
6517 appendPQExpBufferStr(&buf, "ORDER BY 2;");
6518
6519 res = PSQLexec(buf.data);
6520 if (!res)
6521 {
6523 return false;
6524 }
6525
6526 if (PQntuples(res) == 0)
6527 {
6528 if (!pset.quiet)
6529 {
6530 if (pattern)
6531 pg_log_error("Did not find any publication named \"%s\".",
6532 pattern);
6533 else
6534 pg_log_error("Did not find any publications.");
6535 }
6536
6538 PQclear(res);
6539 return false;
6540 }
6541
6542 for (i = 0; i < PQntuples(res); i++)
6543 {
6544 const char align = 'l';
6545 int ncols = 5;
6546 int nrows = 1;
6547 char *pubid = PQgetvalue(res, i, 0);
6548 char *pubname = PQgetvalue(res, i, 1);
6549 bool puballtables = strcmp(PQgetvalue(res, i, 3), "t") == 0;
6550 printTableOpt myopt = pset.popt.topt;
6551
6552 if (has_pubtruncate)
6553 ncols++;
6554 if (has_pubgencols)
6555 ncols++;
6556 if (has_pubviaroot)
6557 ncols++;
6558
6559 initPQExpBuffer(&title);
6560 printfPQExpBuffer(&title, _("Publication %s"), pubname);
6561 printTableInit(&cont, &myopt, title.data, ncols, nrows);
6562
6563 printTableAddHeader(&cont, gettext_noop("Owner"), true, align);
6564 printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
6565 printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
6566 printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
6567 printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
6568 if (has_pubtruncate)
6569 printTableAddHeader(&cont, gettext_noop("Truncates"), true, align);
6570 if (has_pubgencols)
6571 printTableAddHeader(&cont, gettext_noop("Generated columns"), true, align);
6572 if (has_pubviaroot)
6573 printTableAddHeader(&cont, gettext_noop("Via root"), true, align);
6574
6575 printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
6576 printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
6577 printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
6578 printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
6579 printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
6580 if (has_pubtruncate)
6581 printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
6582 if (has_pubgencols)
6583 printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
6584 if (has_pubviaroot)
6585 printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
6586
6587 if (!puballtables)
6588 {
6589 /* Get the tables for the specified publication */
6591 "SELECT n.nspname, c.relname");
6592 if (pset.sversion >= 150000)
6593 {
6595 ", pg_get_expr(pr.prqual, c.oid)");
6597 ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6598 " pg_catalog.array_to_string("
6599 " ARRAY(SELECT attname\n"
6600 " FROM\n"
6601 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6602 " pg_catalog.pg_attribute\n"
6603 " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6604 " ELSE NULL END)");
6605 }
6606 else
6608 ", NULL, NULL");
6610 "\nFROM pg_catalog.pg_class c,\n"
6611 " pg_catalog.pg_namespace n,\n"
6612 " pg_catalog.pg_publication_rel pr\n"
6613 "WHERE c.relnamespace = n.oid\n"
6614 " AND c.oid = pr.prrelid\n"
6615 " AND pr.prpubid = '%s'\n"
6616 "ORDER BY 1,2", pubid);
6617 if (!addFooterToPublicationDesc(&buf, _("Tables:"), false, &cont))
6618 goto error_return;
6619
6620 if (pset.sversion >= 150000)
6621 {
6622 /* Get the schemas for the specified publication */
6624 "SELECT n.nspname\n"
6625 "FROM pg_catalog.pg_namespace n\n"
6626 " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6627 "WHERE pn.pnpubid = '%s'\n"
6628 "ORDER BY 1", pubid);
6629 if (!addFooterToPublicationDesc(&buf, _("Tables from schemas:"),
6630 true, &cont))
6631 goto error_return;
6632 }
6633 }
6634
6635 printTable(&cont, pset.queryFout, false, pset.logfile);
6636 printTableCleanup(&cont);
6637
6638 termPQExpBuffer(&title);
6639 }
6640
6642 PQclear(res);
6643
6644 return true;
6645
6646error_return:
6647 printTableCleanup(&cont);
6648 PQclear(res);
6650 termPQExpBuffer(&title);
6651 return false;
6652}
static bool addFooterToPublicationDesc(PQExpBuffer buf, const char *footermsg, bool as_schema, printTableContent *const cont)
Definition: describe.c:6417
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3481
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
Definition: print.c:3172
void printTableCleanup(printTableContent *const content)
Definition: print.c:3353
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
Definition: print.c:3260
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
Definition: print.c:3443
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
Definition: print.c:3220
printTableOpt topt
Definition: print.h:185

References _, addFooterToPublicationDesc(), appendPQExpBuffer(), appendPQExpBufferStr(), buf, PQExpBufferData::data, formatPGVersionNumber(), 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, res, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::topt, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ describeRoleGrants()

bool describeRoleGrants ( const char *  pattern,
bool  showSystem 
)

Definition at line 3925 of file describe.c.

3926{
3928 PGresult *res;
3929 printQueryOpt myopt = pset.popt;
3930
3933 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3934 " pg_catalog.concat_ws(', ',\n",
3935 gettext_noop("Role name"),
3936 gettext_noop("Member of"));
3937
3938 if (pset.sversion >= 160000)
3940 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3941 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3942 " CASE WHEN pam.set_option THEN 'SET' END\n");
3943 else
3945 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3946 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3947 " 'SET'\n");
3948
3950 " ) AS \"%s\",\n"
3951 " g.rolname AS \"%s\"\n",
3952 gettext_noop("Options"),
3953 gettext_noop("Grantor"));
3954
3956 "FROM pg_catalog.pg_roles m\n"
3957 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3958 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3959 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3960
3961 if (!showSystem && !pattern)
3962 appendPQExpBufferStr(&buf, "WHERE m.rolname !~ '^pg_'\n");
3963
3964 if (!validateSQLNamePattern(&buf, pattern, false, false,
3965 NULL, "m.rolname", NULL, NULL,
3966 NULL, 1))
3967 {
3969 return false;
3970 }
3971
3972 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;\n");
3973
3974 res = PSQLexec(buf.data);
3976 if (!res)
3977 return false;
3978
3979 myopt.title = _("List of role grants");
3980 myopt.translate_header = true;
3981
3982 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3983
3984 PQclear(res);
3985 return true;
3986}

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

Referenced by exec_command_d().

◆ describeRoles()

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

Definition at line 3709 of file describe.c.

3710{
3712 PGresult *res;
3713 printTableContent cont;
3714 printTableOpt myopt = pset.popt.topt;
3715 int ncols = 2;
3716 int nrows = 0;
3717 int i;
3718 int conns;
3719 const char align = 'l';
3720 char **attr;
3721
3722 myopt.default_footer = false;
3723
3725
3727 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3728 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3729 " r.rolconnlimit, r.rolvaliduntil");
3730
3731 if (verbose)
3732 {
3733 appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
3734 ncols++;
3735 }
3736 appendPQExpBufferStr(&buf, "\n, r.rolreplication");
3737
3738 if (pset.sversion >= 90500)
3739 {
3740 appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
3741 }
3742
3743 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
3744
3745 if (!showSystem && !pattern)
3746 appendPQExpBufferStr(&buf, "WHERE r.rolname !~ '^pg_'\n");
3747
3748 if (!validateSQLNamePattern(&buf, pattern, false, false,
3749 NULL, "r.rolname", NULL, NULL,
3750 NULL, 1))
3751 {
3753 return false;
3754 }
3755
3756 appendPQExpBufferStr(&buf, "ORDER BY 1;");
3757
3758 res = PSQLexec(buf.data);
3759 if (!res)
3760 return false;
3761
3762 nrows = PQntuples(res);
3763 attr = pg_malloc0((nrows + 1) * sizeof(*attr));
3764
3765 printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
3766
3767 printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
3768 printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
3769
3770 if (verbose)
3771 printTableAddHeader(&cont, gettext_noop("Description"), true, align);
3772
3773 for (i = 0; i < nrows; i++)
3774 {
3775 printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
3776
3778 if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
3779 add_role_attribute(&buf, _("Superuser"));
3780
3781 if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
3782 add_role_attribute(&buf, _("No inheritance"));
3783
3784 if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
3785 add_role_attribute(&buf, _("Create role"));
3786
3787 if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
3788 add_role_attribute(&buf, _("Create DB"));
3789
3790 if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
3791 add_role_attribute(&buf, _("Cannot login"));
3792
3793 if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0)
3794 add_role_attribute(&buf, _("Replication"));
3795
3796 if (pset.sversion >= 90500)
3797 if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
3798 add_role_attribute(&buf, _("Bypass RLS"));
3799
3800 conns = atoi(PQgetvalue(res, i, 6));
3801 if (conns >= 0)
3802 {
3803 if (buf.len > 0)
3804 appendPQExpBufferChar(&buf, '\n');
3805
3806 if (conns == 0)
3807 appendPQExpBufferStr(&buf, _("No connections"));
3808 else
3809 appendPQExpBuffer(&buf, ngettext("%d connection",
3810 "%d connections",
3811 conns),
3812 conns);
3813 }
3814
3815 if (strcmp(PQgetvalue(res, i, 7), "") != 0)
3816 {
3817 if (buf.len > 0)
3818 appendPQExpBufferChar(&buf, '\n');
3819 appendPQExpBufferStr(&buf, _("Password valid until "));
3821 }
3822
3823 attr[i] = pg_strdup(buf.data);
3824
3825 printTableAddCell(&cont, attr[i], false, false);
3826
3827 if (verbose)
3828 printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
3829 }
3831
3832 printTable(&cont, pset.queryFout, false, pset.logfile);
3833 printTableCleanup(&cont);
3834
3835 for (i = 0; i < nrows; i++)
3836 free(attr[i]);
3837 free(attr);
3838
3839 PQclear(res);
3840 return true;
3841}
#define ngettext(s, p, n)
Definition: c.h:1138
static void add_role_attribute(PQExpBuffer buf, const char *const str)
Definition: describe.c:3844
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
#define free(a)
Definition: header.h:65
static IsoConnInfo * conns
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
bool default_footer
Definition: print.h:129

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

Referenced by exec_command_d().

◆ describeSubscriptions()

bool describeSubscriptions ( const char *  pattern,
bool  verbose 
)

Definition at line 6661 of file describe.c.

6662{
6664 PGresult *res;
6665 printQueryOpt myopt = pset.popt;
6666 static const bool translate_columns[] = {false, false, false, false,
6667 false, false, false, false, false, false, false, false, false, false,
6668 false};
6669
6670 if (pset.sversion < 100000)
6671 {
6672 char sverbuf[32];
6673
6674 pg_log_error("The server (version %s) does not support subscriptions.",
6676 sverbuf, sizeof(sverbuf)));
6677 return true;
6678 }
6679
6681
6683 "SELECT subname AS \"%s\"\n"
6684 ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6685 ", subenabled AS \"%s\"\n"
6686 ", subpublications AS \"%s\"\n",
6687 gettext_noop("Name"),
6688 gettext_noop("Owner"),
6689 gettext_noop("Enabled"),
6690 gettext_noop("Publication"));
6691
6692 if (verbose)
6693 {
6694 /* Binary mode and streaming are only supported in v14 and higher */
6695 if (pset.sversion >= 140000)
6696 {
6698 ", subbinary AS \"%s\"\n",
6699 gettext_noop("Binary"));
6700
6701 if (pset.sversion >= 160000)
6703 ", (CASE substream\n"
6704 " WHEN " CppAsString2(LOGICALREP_STREAM_OFF) " THEN 'off'\n"
6705 " WHEN " CppAsString2(LOGICALREP_STREAM_ON) " THEN 'on'\n"
6706 " WHEN " CppAsString2(LOGICALREP_STREAM_PARALLEL) " THEN 'parallel'\n"
6707 " END) AS \"%s\"\n",
6708 gettext_noop("Streaming"));
6709 else
6711 ", substream AS \"%s\"\n",
6712 gettext_noop("Streaming"));
6713 }
6714
6715 /* Two_phase and disable_on_error are only supported in v15 and higher */
6716 if (pset.sversion >= 150000)
6718 ", subtwophasestate AS \"%s\"\n"
6719 ", subdisableonerr AS \"%s\"\n",
6720 gettext_noop("Two-phase commit"),
6721 gettext_noop("Disable on error"));
6722
6723 if (pset.sversion >= 160000)
6725 ", suborigin AS \"%s\"\n"
6726 ", subpasswordrequired AS \"%s\"\n"
6727 ", subrunasowner AS \"%s\"\n",
6728 gettext_noop("Origin"),
6729 gettext_noop("Password required"),
6730 gettext_noop("Run as owner?"));
6731
6732 if (pset.sversion >= 170000)
6734 ", subfailover AS \"%s\"\n",
6735 gettext_noop("Failover"));
6736
6738 ", subsynccommit AS \"%s\"\n"
6739 ", subconninfo AS \"%s\"\n",
6740 gettext_noop("Synchronous commit"),
6741 gettext_noop("Conninfo"));
6742
6743 /* Skip LSN is only supported in v15 and higher */
6744 if (pset.sversion >= 150000)
6746 ", subskiplsn AS \"%s\"\n",
6747 gettext_noop("Skip LSN"));
6748 }
6749
6750 /* Only display subscriptions in current database. */
6752 "FROM pg_catalog.pg_subscription\n"
6753 "WHERE subdbid = (SELECT oid\n"
6754 " FROM pg_catalog.pg_database\n"
6755 " WHERE datname = pg_catalog.current_database())");
6756
6757 if (!validateSQLNamePattern(&buf, pattern, true, false,
6758 NULL, "subname", NULL,
6759 NULL,
6760 NULL, 1))
6761 {
6763 return false;
6764 }
6765
6766 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6767
6768 res = PSQLexec(buf.data);
6770 if (!res)
6771 return false;
6772
6773 myopt.title = _("List of subscriptions");
6774 myopt.translate_header = true;
6775 myopt.translate_columns = translate_columns;
6776 myopt.n_translate_columns = lengthof(translate_columns);
6777
6778 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6779
6780 PQclear(res);
6781 return true;
6782}

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

Referenced by exec_command_d().

◆ describeTableDetails()

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

Definition at line 1482 of file describe.c.

1483{
1485 PGresult *res;
1486 int i;
1487
1489
1491 "SELECT c.oid,\n"
1492 " n.nspname,\n"
1493 " c.relname\n"
1494 "FROM pg_catalog.pg_class c\n"
1495 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1496
1497 if (!showSystem && !pattern)
1498 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1499 " AND n.nspname <> 'information_schema'\n");
1500
1501 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1502 "n.nspname", "c.relname", NULL,
1503 "pg_catalog.pg_table_is_visible(c.oid)",
1504 NULL, 3))
1505 {
1507 return false;
1508 }
1509
1510 appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1511
1512 res = PSQLexec(buf.data);
1514 if (!res)
1515 return false;
1516
1517 if (PQntuples(res) == 0)
1518 {
1519 if (!pset.quiet)
1520 {
1521 if (pattern)
1522 pg_log_error("Did not find any relation named \"%s\".",
1523 pattern);
1524 else
1525 pg_log_error("Did not find any relations.");
1526 }
1527 PQclear(res);
1528 return false;
1529 }
1530
1531 for (i = 0; i < PQntuples(res); i++)
1532 {
1533 const char *oid;
1534 const char *nspname;
1535 const char *relname;
1536
1537 oid = PQgetvalue(res, i, 0);
1538 nspname = PQgetvalue(res, i, 1);
1539 relname = PQgetvalue(res, i, 2);
1540
1541 if (!describeOneTableDetails(nspname, relname, oid, verbose))
1542 {
1543 PQclear(res);
1544 return false;
1545 }
1546 if (cancel_pressed)
1547 {
1548 PQclear(res);
1549 return false;
1550 }
1551 }
1552
1553 PQclear(res);
1554 return true;
1555}
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
Definition: describe.c:1565
volatile sig_atomic_t cancel_pressed
Definition: print.c:43
NameData relname
Definition: pg_class.h:38

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

Referenced by exec_command_d().

◆ describeTablespaces()

bool describeTablespaces ( const char *  pattern,
bool  verbose 
)

Definition at line 221 of file describe.c.

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

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

Referenced by exec_command_d().

◆ describeTypes()

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

Definition at line 637 of file describe.c.

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

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

Referenced by exec_command_d().

◆ listAllDbs()

bool listAllDbs ( const char *  pattern,
bool  verbose 
)

Definition at line 944 of file describe.c.

945{
946 PGresult *res;
948 printQueryOpt myopt = pset.popt;
949
951
953 "SELECT\n"
954 " d.datname as \"%s\",\n"
955 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
956 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
957 gettext_noop("Name"),
958 gettext_noop("Owner"),
959 gettext_noop("Encoding"));
960 if (pset.sversion >= 150000)
962 " CASE d.datlocprovider "
963 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' "
964 "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' "
965 "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' "
966 "END AS \"%s\",\n",
967 gettext_noop("Locale Provider"));
968 else
970 " 'libc' AS \"%s\",\n",
971 gettext_noop("Locale Provider"));
973 " d.datcollate as \"%s\",\n"
974 " d.datctype as \"%s\",\n",
975 gettext_noop("Collate"),
976 gettext_noop("Ctype"));
977 if (pset.sversion >= 170000)
979 " d.datlocale as \"%s\",\n",
980 gettext_noop("Locale"));
981 else if (pset.sversion >= 150000)
983 " d.daticulocale as \"%s\",\n",
984 gettext_noop("Locale"));
985 else
987 " NULL as \"%s\",\n",
988 gettext_noop("Locale"));
989 if (pset.sversion >= 160000)
991 " d.daticurules as \"%s\",\n",
992 gettext_noop("ICU Rules"));
993 else
995 " NULL as \"%s\",\n",
996 gettext_noop("ICU Rules"));
998 printACLColumn(&buf, "d.datacl");
999 if (verbose)
1001 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
1002 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
1003 " ELSE 'No Access'\n"
1004 " END as \"%s\""
1005 ",\n t.spcname as \"%s\""
1006 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
1007 gettext_noop("Size"),
1008 gettext_noop("Tablespace"),
1009 gettext_noop("Description"));
1011 "\nFROM pg_catalog.pg_database d\n");
1012 if (verbose)
1014 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
1015
1016 if (pattern)
1017 {
1018 if (!validateSQLNamePattern(&buf, pattern, false, false,
1019 NULL, "d.datname", NULL, NULL,
1020 NULL, 1))
1021 {
1023 return false;
1024 }
1025 }
1026
1027 appendPQExpBufferStr(&buf, "ORDER BY 1;");
1028 res = PSQLexec(buf.data);
1030 if (!res)
1031 return false;
1032
1033 myopt.title = _("List of databases");
1034 myopt.translate_header = true;
1035
1036 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1037
1038 PQclear(res);
1039 return true;
1040}

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

Referenced by exec_command_list(), and main().

◆ listCasts()

bool listCasts ( const char *  pattern,
bool  verbose 
)

Definition at line 4899 of file describe.c.

4900{
4902 PGresult *res;
4903 printQueryOpt myopt = pset.popt;
4904 static const bool translate_columns[] = {false, false, false, true, true, false};
4905
4907
4909 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4910 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4911 gettext_noop("Source type"),
4912 gettext_noop("Target type"));
4913
4914 /*
4915 * We don't attempt to localize '(binary coercible)' or '(with inout)',
4916 * because there's too much risk of gettext translating a function name
4917 * that happens to match some string in the PO database.
4918 */
4920 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4921 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4922 " ELSE p.proname\n"
4923 " END AS \"%s\",\n",
4924 COERCION_METHOD_BINARY,
4925 COERCION_METHOD_INOUT,
4926 gettext_noop("Function"));
4927
4929 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4930 " WHEN c.castcontext = '%c' THEN '%s'\n"
4931 " ELSE '%s'\n"
4932 " END AS \"%s\"",
4933 COERCION_CODE_EXPLICIT,
4934 gettext_noop("no"),
4935 COERCION_CODE_ASSIGNMENT,
4936 gettext_noop("in assignment"),
4937 gettext_noop("yes"),
4938 gettext_noop("Implicit?"));
4939
4940 if (verbose)
4942 ",\n CASE WHEN p.proleakproof THEN '%s'\n"
4943 " ELSE '%s'\n"
4944 " END AS \"%s\",\n"
4945 " d.description AS \"%s\"",
4946 gettext_noop("yes"),
4947 gettext_noop("no"),
4948 gettext_noop("Leakproof?"),
4949 gettext_noop("Description"));
4950
4951 /*
4952 * We need a left join to pg_proc for binary casts; the others are just
4953 * paranoia.
4954 */
4956 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4957 " ON c.castfunc = p.oid\n"
4958 " LEFT JOIN pg_catalog.pg_type ts\n"
4959 " ON c.castsource = ts.oid\n"
4960 " LEFT JOIN pg_catalog.pg_namespace ns\n"
4961 " ON ns.oid = ts.typnamespace\n"
4962 " LEFT JOIN pg_catalog.pg_type tt\n"
4963 " ON c.casttarget = tt.oid\n"
4964 " LEFT JOIN pg_catalog.pg_namespace nt\n"
4965 " ON nt.oid = tt.typnamespace\n");
4966
4967 if (verbose)
4969 " LEFT JOIN pg_catalog.pg_description d\n"
4970 " ON d.classoid = c.tableoid AND d.objoid = "
4971 "c.oid AND d.objsubid = 0\n");
4972
4973 appendPQExpBufferStr(&buf, "WHERE ( (true");
4974
4975 /*
4976 * Match name pattern against either internal or external name of either
4977 * castsource or casttarget
4978 */
4979 if (!validateSQLNamePattern(&buf, pattern, true, false,
4980 "ns.nspname", "ts.typname",
4981 "pg_catalog.format_type(ts.oid, NULL)",
4982 "pg_catalog.pg_type_is_visible(ts.oid)",
4983 NULL, 3))
4984 goto error_return;
4985
4986 appendPQExpBufferStr(&buf, ") OR (true");
4987
4988 if (!validateSQLNamePattern(&buf, pattern, true, false,
4989 "nt.nspname", "tt.typname",
4990 "pg_catalog.format_type(tt.oid, NULL)",
4991 "pg_catalog.pg_type_is_visible(tt.oid)",
4992 NULL, 3))
4993 goto error_return;
4994
4995 appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
4996
4997 res = PSQLexec(buf.data);
4999 if (!res)
5000 return false;
5001
5002 myopt.title = _("List of casts");
5003 myopt.translate_header = true;
5004 myopt.translate_columns = translate_columns;
5005 myopt.n_translate_columns = lengthof(translate_columns);
5006
5007 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5008
5009 PQclear(res);
5010 return true;
5011
5012error_return:
5014 return false;
5015}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listCollations()

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

Definition at line 5023 of file describe.c.

5024{
5026 PGresult *res;
5027 printQueryOpt myopt = pset.popt;
5028 static const bool translate_columns[] = {false, false, false, false, false, false, false, true, false};
5029
5031
5033 "SELECT\n"
5034 " n.nspname AS \"%s\",\n"
5035 " c.collname AS \"%s\",\n",
5036 gettext_noop("Schema"),
5037 gettext_noop("Name"));
5038
5039 if (pset.sversion >= 100000)
5041 " CASE c.collprovider "
5042 "WHEN " CppAsString2(COLLPROVIDER_DEFAULT) " THEN 'default' "
5043 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN) " THEN 'builtin' "
5044 "WHEN " CppAsString2(COLLPROVIDER_LIBC) " THEN 'libc' "
5045 "WHEN " CppAsString2(COLLPROVIDER_ICU) " THEN 'icu' "
5046 "END AS \"%s\",\n",
5047 gettext_noop("Provider"));
5048 else
5050 " 'libc' AS \"%s\",\n",
5051 gettext_noop("Provider"));
5052
5054 " c.collcollate AS \"%s\",\n"
5055 " c.collctype AS \"%s\",\n",
5056 gettext_noop("Collate"),
5057 gettext_noop("Ctype"));
5058
5059 if (pset.sversion >= 170000)
5061 " c.colllocale AS \"%s\",\n",
5062 gettext_noop("Locale"));
5063 else if (pset.sversion >= 150000)
5065 " c.colliculocale AS \"%s\",\n",
5066 gettext_noop("Locale"));
5067 else
5069 " c.collcollate AS \"%s\",\n",
5070 gettext_noop("Locale"));
5071
5072 if (pset.sversion >= 160000)
5074 " c.collicurules AS \"%s\",\n",
5075 gettext_noop("ICU Rules"));
5076 else
5078 " NULL AS \"%s\",\n",
5079 gettext_noop("ICU Rules"));
5080
5081 if (pset.sversion >= 120000)
5083 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5084 gettext_noop("yes"), gettext_noop("no"),
5085 gettext_noop("Deterministic?"));
5086 else
5088 " '%s' AS \"%s\"",
5089 gettext_noop("yes"),
5090 gettext_noop("Deterministic?"));
5091
5092 if (verbose)
5094 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5095 gettext_noop("Description"));
5096
5098 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5099 "WHERE n.oid = c.collnamespace\n");
5100
5101 if (!showSystem && !pattern)
5102 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
5103 " AND n.nspname <> 'information_schema'\n");
5104
5105 /*
5106 * Hide collations that aren't usable in the current database's encoding.
5107 * If you think to change this, note that pg_collation_is_visible rejects
5108 * unusable collations, so you will need to hack name pattern processing
5109 * somehow to avoid inconsistent behavior.
5110 */
5111 appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5112
5113 if (!validateSQLNamePattern(&buf, pattern, true, false,
5114 "n.nspname", "c.collname", NULL,
5115 "pg_catalog.pg_collation_is_visible(c.oid)",
5116 NULL, 3))
5117 {
5119 return false;
5120 }
5121
5122 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5123
5124 res = PSQLexec(buf.data);
5126 if (!res)
5127 return false;
5128
5129 myopt.title = _("List of collations");
5130 myopt.translate_header = true;
5131 myopt.translate_columns = translate_columns;
5132 myopt.n_translate_columns = lengthof(translate_columns);
5133
5134 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5135
5136 PQclear(res);
5137 return true;
5138}

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

Referenced by exec_command_d().

◆ listConversions()

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

Definition at line 4575 of file describe.c.

4576{
4578 PGresult *res;
4579 printQueryOpt myopt = pset.popt;
4580 static const bool translate_columns[] =
4581 {false, false, false, false, true, false};
4582
4584
4586 "SELECT n.nspname AS \"%s\",\n"
4587 " c.conname AS \"%s\",\n"
4588 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4589 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4590 " CASE WHEN c.condefault THEN '%s'\n"
4591 " ELSE '%s' END AS \"%s\"",
4592 gettext_noop("Schema"),
4593 gettext_noop("Name"),
4594 gettext_noop("Source"),
4595 gettext_noop("Destination"),
4596 gettext_noop("yes"), gettext_noop("no"),
4597 gettext_noop("Default?"));
4598
4599 if (verbose)
4601 ",\n d.description AS \"%s\"",
4602 gettext_noop("Description"));
4603
4605 "\nFROM pg_catalog.pg_conversion c\n"
4606 " JOIN pg_catalog.pg_namespace n "
4607 "ON n.oid = c.connamespace\n");
4608
4609 if (verbose)
4611 "LEFT JOIN pg_catalog.pg_description d "
4612 "ON d.classoid = c.tableoid\n"
4613 " AND d.objoid = c.oid "
4614 "AND d.objsubid = 0\n");
4615
4616 appendPQExpBufferStr(&buf, "WHERE true\n");
4617
4618 if (!showSystem && !pattern)
4619 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4620 " AND n.nspname <> 'information_schema'\n");
4621
4622 if (!validateSQLNamePattern(&buf, pattern, true, false,
4623 "n.nspname", "c.conname", NULL,
4624 "pg_catalog.pg_conversion_is_visible(c.oid)",
4625 NULL, 3))
4626 {
4628 return false;
4629 }
4630
4631 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4632
4633 res = PSQLexec(buf.data);
4635 if (!res)
4636 return false;
4637
4638 myopt.title = _("List of conversions");
4639 myopt.translate_header = true;
4640 myopt.translate_columns = translate_columns;
4641 myopt.n_translate_columns = lengthof(translate_columns);
4642
4643 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4644
4645 PQclear(res);
4646 return true;
4647}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listDbRoleSettings()

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

Definition at line 3856 of file describe.c.

3857{
3859 PGresult *res;
3860 printQueryOpt myopt = pset.popt;
3861 bool havewhere;
3862
3864
3865 printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
3866 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3867 "FROM pg_catalog.pg_db_role_setting s\n"
3868 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3869 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3870 gettext_noop("Role"),
3871 gettext_noop("Database"),
3872 gettext_noop("Settings"));
3873 if (!validateSQLNamePattern(&buf, pattern, false, false,
3874 NULL, "r.rolname", NULL, NULL, &havewhere, 1))
3875 goto error_return;
3876 if (!validateSQLNamePattern(&buf, pattern2, havewhere, false,
3877 NULL, "d.datname", NULL, NULL,
3878 NULL, 1))
3879 goto error_return;
3880 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3881
3882 res = PSQLexec(buf.data);
3884 if (!res)
3885 return false;
3886
3887 /*
3888 * Most functions in this file are content to print an empty table when
3889 * there are no matching objects. We intentionally deviate from that
3890 * here, but only in !quiet mode, because of the possibility that the user
3891 * is confused about what the two pattern arguments mean.
3892 */
3893 if (PQntuples(res) == 0 && !pset.quiet)
3894 {
3895 if (pattern && pattern2)
3896 pg_log_error("Did not find any settings for role \"%s\" and database \"%s\".",
3897 pattern, pattern2);
3898 else if (pattern)
3899 pg_log_error("Did not find any settings for role \"%s\".",
3900 pattern);
3901 else
3902 pg_log_error("Did not find any settings.");
3903 }
3904 else
3905 {
3906 myopt.title = _("List of settings");
3907 myopt.translate_header = true;
3908
3909 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
3910 }
3911
3912 PQclear(res);
3913 return true;
3914
3915error_return:
3917 return false;
3918}

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

Referenced by exec_command_d().

◆ listDefaultACLs()

bool listDefaultACLs ( const char *  pattern)

Definition at line 1212 of file describe.c.

1213{
1215 PGresult *res;
1216 printQueryOpt myopt = pset.popt;
1217 static const bool translate_columns[] = {false, false, true, false};
1218
1220
1222 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1223 " n.nspname AS \"%s\",\n"
1224 " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1225 " ",
1226 gettext_noop("Owner"),
1227 gettext_noop("Schema"),
1228 DEFACLOBJ_RELATION,
1229 gettext_noop("table"),
1230 DEFACLOBJ_SEQUENCE,
1231 gettext_noop("sequence"),
1232 DEFACLOBJ_FUNCTION,
1233 gettext_noop("function"),
1234 DEFACLOBJ_TYPE,
1235 gettext_noop("type"),
1236 DEFACLOBJ_NAMESPACE,
1237 gettext_noop("schema"),
1238 gettext_noop("Type"));
1239
1240 printACLColumn(&buf, "d.defaclacl");
1241
1242 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
1243 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1244
1245 if (!validateSQLNamePattern(&buf, pattern, false, false,
1246 NULL,
1247 "n.nspname",
1248 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1249 NULL,
1250 NULL, 3))
1251 goto error_return;
1252
1253 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1254
1255 res = PSQLexec(buf.data);
1256 if (!res)
1257 goto error_return;
1258
1259 printfPQExpBuffer(&buf, _("Default access privileges"));
1260 myopt.title = buf.data;
1261 myopt.translate_header = true;
1262 myopt.translate_columns = translate_columns;
1263 myopt.n_translate_columns = lengthof(translate_columns);
1264
1265 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1266
1268 PQclear(res);
1269 return true;
1270
1271error_return:
1273 return false;
1274}

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listDomains()

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

Definition at line 4492 of file describe.c.

4493{
4495 PGresult *res;
4496 printQueryOpt myopt = pset.popt;
4497
4499
4501 "SELECT n.nspname as \"%s\",\n"
4502 " t.typname as \"%s\",\n"
4503 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4504 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4505 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4506 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4507 " t.typdefault as \"%s\",\n"
4508 " pg_catalog.array_to_string(ARRAY(\n"
4509 " 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"
4510 " ), ' ') as \"%s\"",
4511 gettext_noop("Schema"),
4512 gettext_noop("Name"),
4513 gettext_noop("Type"),
4514 gettext_noop("Collation"),
4515 gettext_noop("Nullable"),
4516 gettext_noop("Default"),
4517 gettext_noop("Check"));
4518
4519 if (verbose)
4520 {
4521 appendPQExpBufferStr(&buf, ",\n ");
4522 printACLColumn(&buf, "t.typacl");
4524 ",\n d.description as \"%s\"",
4525 gettext_noop("Description"));
4526 }
4527
4529 "\nFROM pg_catalog.pg_type t\n"
4530 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4531
4532 if (verbose)
4534 " LEFT JOIN pg_catalog.pg_description d "
4535 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4536 "AND d.objsubid = 0\n");
4537
4538 appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
4539
4540 if (!showSystem && !pattern)
4541 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4542 " AND n.nspname <> 'information_schema'\n");
4543
4544 if (!validateSQLNamePattern(&buf, pattern, true, false,
4545 "n.nspname", "t.typname", NULL,
4546 "pg_catalog.pg_type_is_visible(t.oid)",
4547 NULL, 3))
4548 {
4550 return false;
4551 }
4552
4553 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4554
4555 res = PSQLexec(buf.data);
4557 if (!res)
4558 return false;
4559
4560 myopt.title = _("List of domains");
4561 myopt.translate_header = true;
4562
4563 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4564
4565 PQclear(res);
4566 return true;
4567}

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

Referenced by exec_command_d().

◆ listEventTriggers()

bool listEventTriggers ( const char *  pattern,
bool  verbose 
)

Definition at line 4723 of file describe.c.

4724{
4726 PGresult *res;
4727 printQueryOpt myopt = pset.popt;
4728 static const bool translate_columns[] =
4729 {false, false, false, true, false, false, false};
4730
4731 if (pset.sversion < 90300)
4732 {
4733 char sverbuf[32];
4734
4735 pg_log_error("The server (version %s) does not support event triggers.",
4737 sverbuf, sizeof(sverbuf)));
4738 return true;
4739 }
4740
4742
4744 "SELECT evtname as \"%s\", "
4745 "evtevent as \"%s\", "
4746 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4747 " case evtenabled when 'O' then '%s'"
4748 " when 'R' then '%s'"
4749 " when 'A' then '%s'"
4750 " when 'D' then '%s' end as \"%s\",\n"
4751 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4752 "pg_catalog.array_to_string(array(select x"
4753 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4754 gettext_noop("Name"),
4755 gettext_noop("Event"),
4756 gettext_noop("Owner"),
4757 gettext_noop("enabled"),
4758 gettext_noop("replica"),
4759 gettext_noop("always"),
4760 gettext_noop("disabled"),
4761 gettext_noop("Enabled"),
4762 gettext_noop("Function"),
4763 gettext_noop("Tags"));
4764 if (verbose)
4766 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4767 gettext_noop("Description"));
4769 "\nFROM pg_catalog.pg_event_trigger e ");
4770
4771 if (!validateSQLNamePattern(&buf, pattern, false, false,
4772 NULL, "evtname", NULL, NULL,
4773 NULL, 1))
4774 {
4776 return false;
4777 }
4778
4779 appendPQExpBufferStr(&buf, "ORDER BY 1");
4780
4781 res = PSQLexec(buf.data);
4783 if (!res)
4784 return false;
4785
4786 myopt.title = _("List of event triggers");
4787 myopt.translate_header = true;
4788 myopt.translate_columns = translate_columns;
4789 myopt.n_translate_columns = lengthof(translate_columns);
4790
4791 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4792
4793 PQclear(res);
4794 return true;
4795}

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

Referenced by exec_command_d().

◆ listExtendedStats()

bool listExtendedStats ( const char *  pattern)

Definition at line 4803 of file describe.c.

4804{
4806 PGresult *res;
4807 printQueryOpt myopt = pset.popt;
4808
4809 if (pset.sversion < 100000)
4810 {
4811 char sverbuf[32];
4812
4813 pg_log_error("The server (version %s) does not support extended statistics.",
4815 sverbuf, sizeof(sverbuf)));
4816 return true;
4817 }
4818
4821 "SELECT \n"
4822 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4823 "es.stxname AS \"%s\", \n",
4824 gettext_noop("Schema"),
4825 gettext_noop("Name"));
4826
4827 if (pset.sversion >= 140000)
4829 "pg_catalog.format('%%s FROM %%s', \n"
4830 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4831 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4832 gettext_noop("Definition"));
4833 else
4835 "pg_catalog.format('%%s FROM %%s', \n"
4836 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4837 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4838 " JOIN pg_catalog.pg_attribute a \n"
4839 " ON (es.stxrelid = a.attrelid \n"
4840 " AND a.attnum = s.attnum \n"
4841 " AND NOT a.attisdropped)), \n"
4842 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4843 gettext_noop("Definition"));
4844
4846 ",\nCASE WHEN " CppAsString2(STATS_EXT_NDISTINCT) " = any(es.stxkind) THEN 'defined' \n"
4847 "END AS \"%s\", \n"
4848 "CASE WHEN " CppAsString2(STATS_EXT_DEPENDENCIES) " = any(es.stxkind) THEN 'defined' \n"
4849 "END AS \"%s\"",
4850 gettext_noop("Ndistinct"),
4851 gettext_noop("Dependencies"));
4852
4853 /*
4854 * Include the MCV statistics kind.
4855 */
4856 if (pset.sversion >= 120000)
4857 {
4859 ",\nCASE WHEN " CppAsString2(STATS_EXT_MCV) " = any(es.stxkind) THEN 'defined' \n"
4860 "END AS \"%s\" ",
4861 gettext_noop("MCV"));
4862 }
4863
4865 " \nFROM pg_catalog.pg_statistic_ext es \n");
4866
4867 if (!validateSQLNamePattern(&buf, pattern,
4868 false, false,
4869 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text", "es.stxname",
4870 NULL, "pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4871 NULL, 3))
4872 {
4874 return false;
4875 }
4876
4877 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4878
4879 res = PSQLexec(buf.data);
4881 if (!res)
4882 return false;
4883
4884 myopt.title = _("List of extended statistics");
4885 myopt.translate_header = true;
4886
4887 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4888
4889 PQclear(res);
4890 return true;
4891}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, formatPGVersionNumber(), gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, pg_log_error, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listExtensionContents()

bool listExtensionContents ( const char *  pattern)

Definition at line 6173 of file describe.c.

6174{
6176 PGresult *res;
6177 int i;
6178
6181 "SELECT e.extname, e.oid\n"
6182 "FROM pg_catalog.pg_extension e\n");
6183
6184 if (!validateSQLNamePattern(&buf, pattern,
6185 false, false,
6186 NULL, "e.extname", NULL,
6187 NULL,
6188 NULL, 1))
6189 {
6191 return false;
6192 }
6193
6194 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6195
6196 res = PSQLexec(buf.data);
6198 if (!res)
6199 return false;
6200
6201 if (PQntuples(res) == 0)
6202 {
6203 if (!pset.quiet)
6204 {
6205 if (pattern)
6206 pg_log_error("Did not find any extension named \"%s\".",
6207 pattern);
6208 else
6209 pg_log_error("Did not find any extensions.");
6210 }
6211 PQclear(res);
6212 return false;
6213 }
6214
6215 for (i = 0; i < PQntuples(res); i++)
6216 {
6217 const char *extname;
6218 const char *oid;
6219
6220 extname = PQgetvalue(res, i, 0);
6221 oid = PQgetvalue(res, i, 1);
6222
6223 if (!listOneExtensionContents(extname, oid))
6224 {
6225 PQclear(res);
6226 return false;
6227 }
6228 if (cancel_pressed)
6229 {
6230 PQclear(res);
6231 return false;
6232 }
6233 }
6234
6235 PQclear(res);
6236 return true;
6237}
static bool listOneExtensionContents(const char *extname, const char *oid)
Definition: describe.c:6240

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

Referenced by exec_command_d().

◆ listExtensions()

bool listExtensions ( const char *  pattern)

Definition at line 6122 of file describe.c.

6123{
6125 PGresult *res;
6126 printQueryOpt myopt = pset.popt;
6127
6130 "SELECT e.extname AS \"%s\", "
6131 "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
6132 "FROM pg_catalog.pg_extension e "
6133 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
6134 "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
6135 "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
6136 gettext_noop("Name"),
6137 gettext_noop("Version"),
6138 gettext_noop("Schema"),
6139 gettext_noop("Description"));
6140
6141 if (!validateSQLNamePattern(&buf, pattern,
6142 false, false,
6143 NULL, "e.extname", NULL,
6144 NULL,
6145 NULL, 1))
6146 {
6148 return false;
6149 }
6150
6151 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6152
6153 res = PSQLexec(buf.data);
6155 if (!res)
6156 return false;
6157
6158 myopt.title = _("List of installed extensions");
6159 myopt.translate_header = true;
6160
6161 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6162
6163 PQclear(res);
6164 return true;
6165}

References _, appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ listForeignDataWrappers()

bool listForeignDataWrappers ( const char *  pattern,
bool  verbose 
)

Definition at line 5848 of file describe.c.

5849{
5851 PGresult *res;
5852 printQueryOpt myopt = pset.popt;
5853
5856 "SELECT fdw.fdwname AS \"%s\",\n"
5857 " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5858 " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5859 " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5860 gettext_noop("Name"),
5861 gettext_noop("Owner"),
5862 gettext_noop("Handler"),
5863 gettext_noop("Validator"));
5864
5865 if (verbose)
5866 {
5867 appendPQExpBufferStr(&buf, ",\n ");
5868 printACLColumn(&buf, "fdwacl");
5870 ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5871 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5872 " pg_catalog.quote_ident(option_name) || ' ' || "
5873 " pg_catalog.quote_literal(option_value) FROM "
5874 " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5875 " END AS \"%s\""
5876 ",\n d.description AS \"%s\" ",
5877 gettext_noop("FDW options"),
5878 gettext_noop("Description"));
5879 }
5880
5881 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
5882
5883 if (verbose)
5885 "LEFT JOIN pg_catalog.pg_description d\n"
5886 " ON d.classoid = fdw.tableoid "
5887 "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5888
5889 if (!validateSQLNamePattern(&buf, pattern, false, false,
5890 NULL, "fdwname", NULL, NULL,
5891 NULL, 1))
5892 {
5894 return false;
5895 }
5896
5897 appendPQExpBufferStr(&buf, "ORDER BY 1;");
5898
5899 res = PSQLexec(buf.data);
5901 if (!res)
5902 return false;
5903
5904 myopt.title = _("List of foreign-data wrappers");
5905 myopt.translate_header = true;
5906
5907 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5908
5909 PQclear(res);
5910 return true;
5911}

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

Referenced by exec_command_d().

◆ listForeignServers()

bool listForeignServers ( const char *  pattern,
bool  verbose 
)

Definition at line 5919 of file describe.c.

5920{
5922 PGresult *res;
5923 printQueryOpt myopt = pset.popt;
5924
5927 "SELECT s.srvname AS \"%s\",\n"
5928 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5929 " f.fdwname AS \"%s\"",
5930 gettext_noop("Name"),
5931 gettext_noop("Owner"),
5932 gettext_noop("Foreign-data wrapper"));
5933
5934 if (verbose)
5935 {
5936 appendPQExpBufferStr(&buf, ",\n ");
5937 printACLColumn(&buf, "s.srvacl");
5939 ",\n"
5940 " s.srvtype AS \"%s\",\n"
5941 " s.srvversion AS \"%s\",\n"
5942 " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5943 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5944 " pg_catalog.quote_ident(option_name) || ' ' || "
5945 " pg_catalog.quote_literal(option_value) FROM "
5946 " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
5947 " END AS \"%s\",\n"
5948 " d.description AS \"%s\"",
5949 gettext_noop("Type"),
5950 gettext_noop("Version"),
5951 gettext_noop("FDW options"),
5952 gettext_noop("Description"));
5953 }
5954
5956 "\nFROM pg_catalog.pg_foreign_server s\n"
5957 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
5958
5959 if (verbose)
5961 "LEFT JOIN pg_catalog.pg_description d\n "
5962 "ON d.classoid = s.tableoid AND d.objoid = s.oid "
5963 "AND d.objsubid = 0\n");
5964
5965 if (!validateSQLNamePattern(&buf, pattern, false, false,
5966 NULL, "s.srvname", NULL, NULL,
5967 NULL, 1))
5968 {
5970 return false;
5971 }
5972
5973 appendPQExpBufferStr(&buf, "ORDER BY 1;");
5974
5975 res = PSQLexec(buf.data);
5977 if (!res)
5978 return false;
5979
5980 myopt.title = _("List of foreign servers");
5981 myopt.translate_header = true;
5982
5983 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5984
5985 PQclear(res);
5986 return true;
5987}

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

Referenced by exec_command_d().

◆ listForeignTables()

bool listForeignTables ( const char *  pattern,
bool  verbose 
)

Definition at line 6050 of file describe.c.

6051{
6053 PGresult *res;
6054 printQueryOpt myopt = pset.popt;
6055
6058 "SELECT n.nspname AS \"%s\",\n"
6059 " c.relname AS \"%s\",\n"
6060 " s.srvname AS \"%s\"",
6061 gettext_noop("Schema"),
6062 gettext_noop("Table"),
6063 gettext_noop("Server"));
6064
6065 if (verbose)
6067 ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
6068 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6069 " pg_catalog.quote_ident(option_name) || ' ' || "
6070 " pg_catalog.quote_literal(option_value) FROM "
6071 " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
6072 " END AS \"%s\",\n"
6073 " d.description AS \"%s\"",
6074 gettext_noop("FDW options"),
6075 gettext_noop("Description"));
6076
6078 "\nFROM pg_catalog.pg_foreign_table ft\n"
6079 " INNER JOIN pg_catalog.pg_class c"
6080 " ON c.oid = ft.ftrelid\n"
6081 " INNER JOIN pg_catalog.pg_namespace n"
6082 " ON n.oid = c.relnamespace\n"
6083 " INNER JOIN pg_catalog.pg_foreign_server s"
6084 " ON s.oid = ft.ftserver\n");
6085 if (verbose)
6087 " LEFT JOIN pg_catalog.pg_description d\n"
6088 " ON d.classoid = c.tableoid AND "
6089 "d.objoid = c.oid AND d.objsubid = 0\n");
6090
6091 if (!validateSQLNamePattern(&buf, pattern, false, false,
6092 "n.nspname", "c.relname", NULL,
6093 "pg_catalog.pg_table_is_visible(c.oid)",
6094 NULL, 3))
6095 {
6097 return false;
6098 }
6099
6100 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6101
6102 res = PSQLexec(buf.data);
6104 if (!res)
6105 return false;
6106
6107 myopt.title = _("List of foreign tables");
6108 myopt.translate_header = true;
6109
6110 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6111
6112 PQclear(res);
6113 return true;
6114}

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

Referenced by exec_command_d().

◆ listLanguages()

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

Definition at line 4416 of file describe.c.

4417{
4419 PGresult *res;
4420 printQueryOpt myopt = pset.popt;
4421
4423
4425 "SELECT l.lanname AS \"%s\",\n"
4426 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4427 " l.lanpltrusted AS \"%s\"",
4428 gettext_noop("Name"),
4429 gettext_noop("Owner"),
4430 gettext_noop("Trusted"));
4431
4432 if (verbose)
4433 {
4435 ",\n NOT l.lanispl AS \"%s\",\n"
4436 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4437 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4438 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4439 gettext_noop("Internal language"),
4440 gettext_noop("Call handler"),
4441 gettext_noop("Validator"),
4442 gettext_noop("Inline handler"));
4443 printACLColumn(&buf, "l.lanacl");
4444 }
4445
4447 ",\n d.description AS \"%s\""
4448 "\nFROM pg_catalog.pg_language l\n"
4449 "LEFT JOIN pg_catalog.pg_description d\n"
4450 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4451 " AND d.objsubid = 0\n",
4452 gettext_noop("Description"));
4453
4454 if (pattern)
4455 {
4456 if (!validateSQLNamePattern(&buf, pattern, false, false,
4457 NULL, "l.lanname", NULL, NULL,
4458 NULL, 2))
4459 {
4461 return false;
4462 }
4463 }
4464
4465 if (!showSystem && !pattern)
4466 appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
4467
4468
4469 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4470
4471 res = PSQLexec(buf.data);
4473 if (!res)
4474 return false;
4475
4476 myopt.title = _("List of languages");
4477 myopt.translate_header = true;
4478
4479 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4480
4481 PQclear(res);
4482 return true;
4483}

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

Referenced by exec_command_d().

◆ listLargeObjects()

bool listLargeObjects ( bool  verbose)

Definition at line 7199 of file describe.c.

7200{
7202 PGresult *res;
7203 printQueryOpt myopt = pset.popt;
7204
7206
7208 "SELECT oid as \"%s\",\n"
7209 " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
7210 gettext_noop("ID"),
7211 gettext_noop("Owner"));
7212
7213 if (verbose)
7214 {
7215 printACLColumn(&buf, "lomacl");
7216 appendPQExpBufferStr(&buf, ",\n ");
7217 }
7218
7220 "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
7221 "FROM pg_catalog.pg_largeobject_metadata\n"
7222 "ORDER BY oid",
7223 gettext_noop("Description"));
7224
7225 res = PSQLexec(buf.data);
7227 if (!res)
7228 return false;
7229
7230 myopt.title = _("Large objects");
7231 myopt.translate_header = true;
7232
7233 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7234
7235 PQclear(res);
7236 return true;
7237}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), _psqlSettings::logfile, _psqlSettings::popt, PQclear(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, 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 
)

Definition at line 6813 of file describe.c.

6815{
6817 PGresult *res;
6818 printQueryOpt myopt = pset.popt;
6819 bool have_where = false;
6820 static const bool translate_columns[] = {false, false, false, false, false, false, false};
6821
6823
6825 "SELECT\n"
6826 " am.amname AS \"%s\",\n"
6827 " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6828 " CASE\n"
6829 " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6830 " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6831 " ELSE NULL\n"
6832 " END AS \"%s\",\n"
6833 " CASE\n"
6834 " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6835 " THEN pg_catalog.format('%%I', c.opcname)\n"
6836 " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6837 " END AS \"%s\",\n"
6838 " (CASE WHEN c.opcdefault\n"
6839 " THEN '%s'\n"
6840 " ELSE '%s'\n"
6841 " END) AS \"%s\"",
6842 gettext_noop("AM"),
6843 gettext_noop("Input type"),
6844 gettext_noop("Storage type"),
6845 gettext_noop("Operator class"),
6846 gettext_noop("yes"),
6847 gettext_noop("no"),
6848 gettext_noop("Default?"));
6849 if (verbose)
6851 ",\n CASE\n"
6852 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6853 " THEN pg_catalog.format('%%I', of.opfname)\n"
6854 " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
6855 " END AS \"%s\",\n"
6856 " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6857 gettext_noop("Operator family"),
6858 gettext_noop("Owner"));
6860 "\nFROM pg_catalog.pg_opclass c\n"
6861 " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6862 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6863 " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6864 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
6865 if (verbose)
6867 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6868 " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6869
6870 if (access_method_pattern)
6871 if (!validateSQLNamePattern(&buf, access_method_pattern,
6872 false, false, NULL, "am.amname", NULL, NULL,
6873 &have_where, 1))
6874 goto error_return;
6875 if (type_pattern)
6876 {
6877 /* Match type name pattern against either internal or external name */
6878 if (!validateSQLNamePattern(&buf, type_pattern, have_where, false,
6879 "tn.nspname", "t.typname",
6880 "pg_catalog.format_type(t.oid, NULL)",
6881 "pg_catalog.pg_type_is_visible(t.oid)",
6882 NULL, 3))
6883 goto error_return;
6884 }
6885
6886 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
6887 res = PSQLexec(buf.data);
6889 if (!res)
6890 return false;
6891
6892 myopt.title = _("List of operator classes");
6893 myopt.translate_header = true;
6894 myopt.translate_columns = translate_columns;
6895 myopt.n_translate_columns = lengthof(translate_columns);
6896
6897 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6898
6899 PQclear(res);
6900 return true;
6901
6902error_return:
6904 return false;
6905}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listOperatorFamilies()

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

Definition at line 6914 of file describe.c.

6916{
6918 PGresult *res;
6919 printQueryOpt myopt = pset.popt;
6920 bool have_where = false;
6921 static const bool translate_columns[] = {false, false, false, false};
6922
6924
6926 "SELECT\n"
6927 " am.amname AS \"%s\",\n"
6928 " CASE\n"
6929 " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
6930 " THEN pg_catalog.format('%%I', f.opfname)\n"
6931 " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
6932 " END AS \"%s\",\n"
6933 " (SELECT\n"
6934 " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
6935 " FROM pg_catalog.pg_opclass oc\n"
6936 " WHERE oc.opcfamily = f.oid) \"%s\"",
6937 gettext_noop("AM"),
6938 gettext_noop("Operator family"),
6939 gettext_noop("Applicable types"));
6940 if (verbose)
6942 ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
6943 gettext_noop("Owner"));
6945 "\nFROM pg_catalog.pg_opfamily f\n"
6946 " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
6947 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
6948
6949 if (access_method_pattern)
6950 if (!validateSQLNamePattern(&buf, access_method_pattern,
6951 false, false, NULL, "am.amname", NULL, NULL,
6952 &have_where, 1))
6953 goto error_return;
6954 if (type_pattern)
6955 {
6957 " %s EXISTS (\n"
6958 " SELECT 1\n"
6959 " FROM pg_catalog.pg_type t\n"
6960 " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
6961 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
6962 " WHERE oc.opcfamily = f.oid\n",
6963 have_where ? "AND" : "WHERE");
6964 /* Match type name pattern against either internal or external name */
6965 if (!validateSQLNamePattern(&buf, type_pattern, true, false,
6966 "tn.nspname", "t.typname",
6967 "pg_catalog.format_type(t.oid, NULL)",
6968 "pg_catalog.pg_type_is_visible(t.oid)",
6969 NULL, 3))
6970 goto error_return;
6971 appendPQExpBufferStr(&buf, " )\n");
6972 }
6973
6974 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6975 res = PSQLexec(buf.data);
6977 if (!res)
6978 return false;
6979
6980 myopt.title = _("List of operator families");
6981 myopt.translate_header = true;
6982 myopt.translate_columns = translate_columns;
6983 myopt.n_translate_columns = lengthof(translate_columns);
6984
6985 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6986
6987 PQclear(res);
6988 return true;
6989
6990error_return:
6992 return false;
6993}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listOpFamilyFunctions()

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

Definition at line 7110 of file describe.c.

7112{
7114 PGresult *res;
7115 printQueryOpt myopt = pset.popt;
7116 bool have_where = false;
7117 static const bool translate_columns[] = {false, false, false, false, false, false};
7118
7120
7122 "SELECT\n"
7123 " am.amname AS \"%s\",\n"
7124 " CASE\n"
7125 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7126 " THEN pg_catalog.format('%%I', of.opfname)\n"
7127 " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
7128 " END AS \"%s\",\n"
7129 " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
7130 " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
7131 " ap.amprocnum AS \"%s\"\n",
7132 gettext_noop("AM"),
7133 gettext_noop("Operator family"),
7134 gettext_noop("Registered left type"),
7135 gettext_noop("Registered right type"),
7136 gettext_noop("Number"));
7137
7138 if (!verbose)
7140 ", p.proname AS \"%s\"\n",
7141 gettext_noop("Function"));
7142 else
7144 ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
7145 gettext_noop("Function"));
7146
7148 "FROM pg_catalog.pg_amproc ap\n"
7149 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
7150 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
7151 " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
7152 " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
7153
7154 if (access_method_pattern)
7155 {
7156 if (!validateSQLNamePattern(&buf, access_method_pattern,
7157 false, false, NULL, "am.amname",
7158 NULL, NULL,
7159 &have_where, 1))
7160 goto error_return;
7161 }
7162 if (family_pattern)
7163 {
7164 if (!validateSQLNamePattern(&buf, family_pattern, have_where, false,
7165 "ns.nspname", "of.opfname", NULL, NULL,
7166 NULL, 3))
7167 goto error_return;
7168 }
7169
7170 appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
7171 " ap.amproclefttype = ap.amprocrighttype DESC,\n"
7172 " 3, 4, 5;");
7173
7174 res = PSQLexec(buf.data);
7176 if (!res)
7177 return false;
7178
7179 myopt.title = _("List of support functions of operator families");
7180 myopt.translate_header = true;
7181 myopt.translate_columns = translate_columns;
7182 myopt.n_translate_columns = lengthof(translate_columns);
7183
7184 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7185
7186 PQclear(res);
7187 return true;
7188
7189error_return:
7191 return false;
7192}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listOpFamilyOperators()

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

Definition at line 7003 of file describe.c.

7005{
7007 PGresult *res;
7008 printQueryOpt myopt = pset.popt;
7009 bool have_where = false;
7010
7011 static const bool translate_columns[] = {false, false, false, false, false, false, true};
7012
7014
7016 "SELECT\n"
7017 " am.amname AS \"%s\",\n"
7018 " CASE\n"
7019 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7020 " THEN pg_catalog.format('%%I', of.opfname)\n"
7021 " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
7022 " END AS \"%s\",\n"
7023 " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
7024 " o.amopstrategy AS \"%s\",\n"
7025 " CASE o.amoppurpose\n"
7026 " WHEN " CppAsString2(AMOP_ORDER) " THEN '%s'\n"
7027 " WHEN " CppAsString2(AMOP_SEARCH) " THEN '%s'\n"
7028 " END AS \"%s\"\n",
7029 gettext_noop("AM"),
7030 gettext_noop("Operator family"),
7031 gettext_noop("Operator"),
7032 gettext_noop("Strategy"),
7033 gettext_noop("ordering"),
7034 gettext_noop("search"),
7035 gettext_noop("Purpose"));
7036
7037 if (verbose)
7039 ", ofs.opfname AS \"%s\",\n"
7040 " CASE\n"
7041 " WHEN p.proleakproof THEN '%s'\n"
7042 " ELSE '%s'\n"
7043 " END AS \"%s\"\n",
7044 gettext_noop("Sort opfamily"),
7045 gettext_noop("yes"),
7046 gettext_noop("no"),
7047 gettext_noop("Leakproof?"));
7049 "FROM pg_catalog.pg_amop o\n"
7050 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
7051 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
7052 " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
7053 if (verbose)
7055 " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n"
7056 " LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
7057 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = op.oprcode\n");
7058
7059 if (access_method_pattern)
7060 {
7061 if (!validateSQLNamePattern(&buf, access_method_pattern,
7062 false, false, NULL, "am.amname",
7063 NULL, NULL,
7064 &have_where, 1))
7065 goto error_return;
7066 }
7067
7068 if (family_pattern)
7069 {
7070 if (!validateSQLNamePattern(&buf, family_pattern, have_where, false,
7071 "nsf.nspname", "of.opfname", NULL, NULL,
7072 NULL, 3))
7073 goto error_return;
7074 }
7075
7076 appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n"
7077 " o.amoplefttype = o.amoprighttype DESC,\n"
7078 " pg_catalog.format_type(o.amoplefttype, NULL),\n"
7079 " pg_catalog.format_type(o.amoprighttype, NULL),\n"
7080 " o.amopstrategy;");
7081
7082 res = PSQLexec(buf.data);
7084 if (!res)
7085 return false;
7086
7087 myopt.title = _("List of operators of operator families");
7088 myopt.translate_header = true;
7089 myopt.translate_columns = translate_columns;
7090 myopt.n_translate_columns = lengthof(translate_columns);
7091
7092 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
7093
7094 PQclear(res);
7095 return true;
7096
7097error_return:
7099 return false;
7100}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, CppAsString2, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listPartitionedTables()

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

Definition at line 4206 of file describe.c.

4207{
4208 bool showTables = strchr(reltypes, 't') != NULL;
4209 bool showIndexes = strchr(reltypes, 'i') != NULL;
4210 bool showNested = strchr(reltypes, 'n') != NULL;
4212 PQExpBufferData title;
4213 PGresult *res;
4214 printQueryOpt myopt = pset.popt;
4215 bool translate_columns[] = {false, false, false, false, false, false, false, false, false, false};
4216 const char *tabletitle;
4217 bool mixed_output = false;
4218
4219 /*
4220 * Note: Declarative table partitioning is only supported as of Pg 10.0.
4221 */
4222 if (pset.sversion < 100000)
4223 {
4224 char sverbuf[32];
4225
4226 pg_log_error("The server (version %s) does not support declarative table partitioning.",
4228 sverbuf, sizeof(sverbuf)));
4229 return true;
4230 }
4231
4232 /* If no relation kind was selected, show them all */
4233 if (!showTables && !showIndexes)
4234 showTables = showIndexes = true;
4235
4236 if (showIndexes && !showTables)
4237 tabletitle = _("List of partitioned indexes"); /* \dPi */
4238 else if (showTables && !showIndexes)
4239 tabletitle = _("List of partitioned tables"); /* \dPt */
4240 else
4241 {
4242 /* show all kinds */
4243 tabletitle = _("List of partitioned relations");
4244 mixed_output = true;
4245 }
4246
4248
4250 "SELECT n.nspname as \"%s\",\n"
4251 " c.relname as \"%s\",\n"
4252 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4253 gettext_noop("Schema"),
4254 gettext_noop("Name"),
4255 gettext_noop("Owner"));
4256
4257 if (mixed_output)
4258 {
4260 ",\n CASE c.relkind"
4261 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
4262 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
4263 " END as \"%s\"",
4264 gettext_noop("partitioned table"),
4265 gettext_noop("partitioned index"),
4266 gettext_noop("Type"));
4267
4268 translate_columns[3] = true;
4269 }
4270
4271 if (showNested || pattern)
4273 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4274 gettext_noop("Parent name"));
4275
4276 if (showIndexes)
4278 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4279 gettext_noop("Table"));
4280
4281 if (verbose)
4282 {
4283 /*
4284 * Table access methods were introduced in v12, and can be set on
4285 * partitioned tables since v17.
4286 */
4287 appendPQExpBuffer(&buf, ",\n am.amname as \"%s\"",
4288 gettext_noop("Access method"));
4289
4290 if (showNested)
4291 {
4293 ",\n s.dps as \"%s\"",
4294 gettext_noop("Leaf partition size"));
4296 ",\n s.tps as \"%s\"",
4297 gettext_noop("Total size"));
4298 }
4299 else
4300 /* Sizes of all partitions are considered in this case. */
4302 ",\n s.tps as \"%s\"",
4303 gettext_noop("Total size"));
4304
4306 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4307 gettext_noop("Description"));
4308 }
4309
4311 "\nFROM pg_catalog.pg_class c"
4312 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4313
4314 if (showIndexes)
4316 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4317 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4318
4319 if (showNested || pattern)
4321 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4322
4323 if (verbose)
4324 {
4326 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4327
4328 if (pset.sversion < 120000)
4329 {
4331 ",\n LATERAL (WITH RECURSIVE d\n"
4332 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4333 " FROM pg_catalog.pg_inherits\n"
4334 " WHERE inhparent = c.oid\n"
4335 " UNION ALL\n"
4336 " SELECT inhrelid, level + 1\n"
4337 " FROM pg_catalog.pg_inherits i\n"
4338 " JOIN d ON i.inhparent = d.oid)\n"
4339 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4340 "d.oid))) AS tps,\n"
4341 " pg_catalog.pg_size_pretty(sum("
4342 "\n CASE WHEN d.level = 1"
4343 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4344 " FROM d) s");
4345 }
4346 else
4347 {
4348 /* PostgreSQL 12 has pg_partition_tree function */
4350 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4351 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4352 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4353 " ELSE 0 END)) AS dps"
4354 ",\n pg_catalog.pg_size_pretty(sum("
4355 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4356 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4357 }
4358 }
4359
4360 appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4361 if (showTables)
4362 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
4363 if (showIndexes)
4364 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
4365 appendPQExpBufferStr(&buf, "''"); /* dummy */
4366 appendPQExpBufferStr(&buf, ")\n");
4367
4368 appendPQExpBufferStr(&buf, !showNested && !pattern ?
4369 " AND NOT c.relispartition\n" : "");
4370
4371 if (!pattern)
4372 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4373 " AND n.nspname !~ '^pg_toast'\n"
4374 " AND n.nspname <> 'information_schema'\n");
4375
4376 if (!validateSQLNamePattern(&buf, pattern, true, false,
4377 "n.nspname", "c.relname", NULL,
4378 "pg_catalog.pg_table_is_visible(c.oid)",
4379 NULL, 3))
4380 {
4382 return false;
4383 }
4384
4385 appendPQExpBuffer(&buf, "ORDER BY \"Schema\", %s%s\"Name\";",
4386 mixed_output ? "\"Type\" DESC, " : "",
4387 showNested || pattern ? "\"Parent name\" NULLS FIRST, " : "");
4388
4389 res = PSQLexec(buf.data);
4391 if (!res)
4392 return false;
4393
4394 initPQExpBuffer(&title);
4395 appendPQExpBufferStr(&title, tabletitle);
4396
4397 myopt.title = title.data;
4398 myopt.translate_header = true;
4399 myopt.translate_columns = translate_columns;
4400 myopt.n_translate_columns = lengthof(translate_columns);
4401
4402 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4403
4404 termPQExpBuffer(&title);
4405
4406 PQclear(res);
4407 return true;
4408}

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

Referenced by exec_command_d().

◆ listPublications()

bool listPublications ( const char *  pattern)

Definition at line 6337 of file describe.c.

6338{
6340 PGresult *res;
6341 printQueryOpt myopt = pset.popt;
6342 static const bool translate_columns[] = {false, false, false, false, false, false, false, false, false};
6343
6344 if (pset.sversion < 100000)
6345 {
6346 char sverbuf[32];
6347
6348 pg_log_error("The server (version %s) does not support publications.",
6350 sverbuf, sizeof(sverbuf)));
6351 return true;
6352 }
6353
6355
6357 "SELECT pubname AS \"%s\",\n"
6358 " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6359 " puballtables AS \"%s\",\n"
6360 " pubinsert AS \"%s\",\n"
6361 " pubupdate AS \"%s\",\n"
6362 " pubdelete AS \"%s\"",
6363 gettext_noop("Name"),
6364 gettext_noop("Owner"),
6365 gettext_noop("All tables"),
6366 gettext_noop("Inserts"),
6367 gettext_noop("Updates"),
6368 gettext_noop("Deletes"));
6369 if (pset.sversion >= 110000)
6371 ",\n pubtruncate AS \"%s\"",
6372 gettext_noop("Truncates"));
6373 if (pset.sversion >= 180000)
6375 ",\n pubgencols AS \"%s\"",
6376 gettext_noop("Generated columns"));
6377 if (pset.sversion >= 130000)
6379 ",\n pubviaroot AS \"%s\"",
6380 gettext_noop("Via root"));
6381
6383 "\nFROM pg_catalog.pg_publication\n");
6384
6385 if (!validateSQLNamePattern(&buf, pattern, false, false,
6386 NULL, "pubname", NULL,
6387 NULL,
6388 NULL, 1))
6389 {
6391 return false;
6392 }
6393
6394 appendPQExpBufferStr(&buf, "ORDER BY 1;");
6395
6396 res = PSQLexec(buf.data);
6398 if (!res)
6399 return false;
6400
6401 myopt.title = _("List of publications");
6402 myopt.translate_header = true;
6403 myopt.translate_columns = translate_columns;
6404 myopt.n_translate_columns = lengthof(translate_columns);
6405
6406 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6407
6408 PQclear(res);
6409
6410 return true;
6411}

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

Referenced by exec_command_d().

◆ listSchemas()

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

Definition at line 5146 of file describe.c.

5147{
5149 PGresult *res;
5150 printQueryOpt myopt = pset.popt;
5151 int pub_schema_tuples = 0;
5152 char **footers = NULL;
5153
5156 "SELECT n.nspname AS \"%s\",\n"
5157 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5158 gettext_noop("Name"),
5159 gettext_noop("Owner"));
5160
5161 if (verbose)
5162 {
5163 appendPQExpBufferStr(&buf, ",\n ");
5164 printACLColumn(&buf, "n.nspacl");
5166 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5167 gettext_noop("Description"));
5168 }
5169
5171 "\nFROM pg_catalog.pg_namespace n\n");
5172
5173 if (!showSystem && !pattern)
5175 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5176
5177 if (!validateSQLNamePattern(&buf, pattern,
5178 !showSystem && !pattern, false,
5179 NULL, "n.nspname", NULL,
5180 NULL,
5181 NULL, 2))
5182 goto error_return;
5183
5184 appendPQExpBufferStr(&buf, "ORDER BY 1;");
5185
5186 res = PSQLexec(buf.data);
5187 if (!res)
5188 goto error_return;
5189
5190 myopt.title = _("List of schemas");
5191 myopt.translate_header = true;
5192
5193 if (pattern && pset.sversion >= 150000)
5194 {
5195 PGresult *result;
5196 int i;
5197
5199 "SELECT pubname \n"
5200 "FROM pg_catalog.pg_publication p\n"
5201 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5202 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5203 "WHERE n.nspname = '%s'\n"
5204 "ORDER BY 1",
5205 pattern);
5206 result = PSQLexec(buf.data);
5207 if (!result)
5208 goto error_return;
5209 else
5210 pub_schema_tuples = PQntuples(result);
5211
5212 if (pub_schema_tuples > 0)
5213 {
5214 /*
5215 * Allocate memory for footers. Size of footers will be 1 (for
5216 * storing "Publications:" string) + publication schema mapping
5217 * count + 1 (for storing NULL).
5218 */
5219 footers = (char **) pg_malloc((1 + pub_schema_tuples + 1) * sizeof(char *));
5220 footers[0] = pg_strdup(_("Publications:"));
5221
5222 /* Might be an empty set - that's ok */
5223 for (i = 0; i < pub_schema_tuples; i++)
5224 {
5225 printfPQExpBuffer(&buf, " \"%s\"",
5226 PQgetvalue(result, i, 0));
5227
5228 footers[i + 1] = pg_strdup(buf.data);
5229 }
5230
5231 footers[i + 1] = NULL;
5232 myopt.footers = footers;
5233 }
5234
5235 PQclear(result);
5236 }
5237
5238 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5239
5241 PQclear(res);
5242
5243 /* Free the memory allocated for the footer */
5244 if (footers)
5245 {
5246 char **footer = NULL;
5247
5248 for (footer = footers; *footer; footer++)
5249 pg_free(*footer);
5250
5251 pg_free(footers);
5252 }
5253
5254 return true;
5255
5256error_return:
5258 return false;
5259}
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void pg_free(void *ptr)
Definition: fe_memutils.c:105
char ** footers
Definition: print.h:188

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, printQueryOpt::footers, gettext_noop, i, initPQExpBuffer(), _psqlSettings::logfile, pg_free(), pg_malloc(), pg_strdup(), _psqlSettings::popt, PQclear(), PQgetvalue(), PQntuples(), printACLColumn(), printfPQExpBuffer(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, _psqlSettings::sversion, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_header, validateSQLNamePattern(), and verbose.

Referenced by exec_command_d().

◆ listTables()

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

Definition at line 4004 of file describe.c.

4005{
4006 bool showTables = strchr(tabtypes, 't') != NULL;
4007 bool showIndexes = strchr(tabtypes, 'i') != NULL;
4008 bool showViews = strchr(tabtypes, 'v') != NULL;
4009 bool showMatViews = strchr(tabtypes, 'm') != NULL;
4010 bool showSeq = strchr(tabtypes, 's') != NULL;
4011 bool showForeign = strchr(tabtypes, 'E') != NULL;
4012
4014 PGresult *res;
4015 printQueryOpt myopt = pset.popt;
4016 int cols_so_far;
4017 bool translate_columns[] = {false, false, true, false, false, false, false, false, false};
4018
4019 /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
4020 if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
4021 showTables = showViews = showMatViews = showSeq = showForeign = true;
4022
4024
4026 "SELECT n.nspname as \"%s\",\n"
4027 " c.relname as \"%s\",\n"
4028 " CASE c.relkind"
4029 " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
4030 " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
4031 " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
4032 " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'"
4033 " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
4034 " WHEN " CppAsString2(RELKIND_TOASTVALUE) " THEN '%s'"
4035 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
4036 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
4037 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'"
4038 " END as \"%s\",\n"
4039 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4040 gettext_noop("Schema"),
4041 gettext_noop("Name"),
4042 gettext_noop("table"),
4043 gettext_noop("view"),
4044 gettext_noop("materialized view"),
4045 gettext_noop("index"),
4046 gettext_noop("sequence"),
4047 gettext_noop("TOAST table"),
4048 gettext_noop("foreign table"),
4049 gettext_noop("partitioned table"),
4050 gettext_noop("partitioned index"),
4051 gettext_noop("Type"),
4052 gettext_noop("Owner"));
4053 cols_so_far = 4;
4054
4055 if (showIndexes)
4056 {
4058 ",\n c2.relname as \"%s\"",
4059 gettext_noop("Table"));
4060 cols_so_far++;
4061 }
4062
4063 if (verbose)
4064 {
4065 /*
4066 * Show whether a relation is permanent, temporary, or unlogged.
4067 */
4069 ",\n CASE c.relpersistence "
4070 "WHEN " CppAsString2(RELPERSISTENCE_PERMANENT) " THEN '%s' "
4071 "WHEN " CppAsString2(RELPERSISTENCE_TEMP) " THEN '%s' "
4072 "WHEN " CppAsString2(RELPERSISTENCE_UNLOGGED) " THEN '%s' "
4073 "END as \"%s\"",
4074 gettext_noop("permanent"),
4075 gettext_noop("temporary"),
4076 gettext_noop("unlogged"),
4077 gettext_noop("Persistence"));
4078 translate_columns[cols_so_far] = true;
4079
4080 /*
4081 * We don't bother to count cols_so_far below here, as there's no need
4082 * to; this might change with future additions to the output columns.
4083 */
4084
4085 /*
4086 * Access methods exist for tables, materialized views and indexes.
4087 * This has been introduced in PostgreSQL 12 for tables.
4088 */
4089 if (pset.sversion >= 120000 && !pset.hide_tableam &&
4090 (showTables || showMatViews || showIndexes))
4092 ",\n am.amname as \"%s\"",
4093 gettext_noop("Access method"));
4094
4096 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4097 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4098 gettext_noop("Size"),
4099 gettext_noop("Description"));
4100 }
4101
4103 "\nFROM pg_catalog.pg_class c"
4104 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4105
4106 if (pset.sversion >= 120000 && !pset.hide_tableam &&
4107 (showTables || showMatViews || showIndexes))
4109 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4110
4111 if (showIndexes)
4113 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4114 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4115
4116 appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
4117 if (showTables)
4118 {
4119 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_RELATION) ","
4120 CppAsString2(RELKIND_PARTITIONED_TABLE) ",");
4121 /* with 'S' or a pattern, allow 't' to match TOAST tables too */
4122 if (showSystem || pattern)
4123 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_TOASTVALUE) ",");
4124 }
4125 if (showViews)
4126 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_VIEW) ",");
4127 if (showMatViews)
4128 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_MATVIEW) ",");
4129 if (showIndexes)
4130 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_INDEX) ","
4131 CppAsString2(RELKIND_PARTITIONED_INDEX) ",");
4132 if (showSeq)
4133 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ",");
4134 if (showSystem || pattern)
4135 appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */
4136 if (showForeign)
4137 appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ",");
4138
4139 appendPQExpBufferStr(&buf, "''"); /* dummy */
4140 appendPQExpBufferStr(&buf, ")\n");
4141
4142 if (!showSystem && !pattern)
4143 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
4144 " AND n.nspname !~ '^pg_toast'\n"
4145 " AND n.nspname <> 'information_schema'\n");
4146
4147 if (!validateSQLNamePattern(&buf, pattern, true, false,
4148 "n.nspname", "c.relname", NULL,
4149 "pg_catalog.pg_table_is_visible(c.oid)",
4150 NULL, 3))
4151 {
4153 return false;
4154 }
4155
4156 appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
4157
4158 res = PSQLexec(buf.data);
4160 if (!res)
4161 return false;
4162
4163 /*
4164 * Most functions in this file are content to print an empty table when
4165 * there are no matching objects. We intentionally deviate from that
4166 * here, but only in !quiet mode, for historical reasons.
4167 */
4168 if (PQntuples(res) == 0 && !pset.quiet)
4169 {
4170 if (pattern)
4171 pg_log_error("Did not find any relation named \"%s\".",
4172 pattern);
4173 else
4174 pg_log_error("Did not find any relations.");
4175 }
4176 else
4177 {
4178 myopt.title = _("List of relations");
4179 myopt.translate_header = true;
4180 myopt.translate_columns = translate_columns;
4181 myopt.n_translate_columns = lengthof(translate_columns);
4182
4183 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
4184 }
4185
4186 PQclear(res);
4187 return true;
4188}
bool hide_tableam
Definition: settings.h:153

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

Referenced by exec_command_d().

◆ listTSConfigs()

bool listTSConfigs ( const char *  pattern,
bool  verbose 
)

Definition at line 5644 of file describe.c.

5645{
5647 PGresult *res;
5648 printQueryOpt myopt = pset.popt;
5649
5650 if (verbose)
5651 return listTSConfigsVerbose(pattern);
5652
5654
5656 "SELECT\n"
5657 " n.nspname as \"%s\",\n"
5658 " c.cfgname as \"%s\",\n"
5659 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5660 "FROM pg_catalog.pg_ts_config c\n"
5661 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5662 gettext_noop("Schema"),
5663 gettext_noop("Name"),
5664 gettext_noop("Description")
5665 );
5666
5667 if (!validateSQLNamePattern(&buf, pattern, false, false,
5668 "n.nspname", "c.cfgname", NULL,
5669 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5670 NULL, 3))
5671 {
5673 return false;
5674 }
5675
5676 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5677
5678 res = PSQLexec(buf.data);
5680 if (!res)
5681 return false;
5682
5683 myopt.title = _("List of text search configurations");
5684 myopt.translate_header = true;
5685
5686 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5687
5688 PQclear(res);
5689 return true;
5690}
static bool listTSConfigsVerbose(const char *pattern)
Definition: describe.c:5693

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

Referenced by exec_command_d().

◆ listTSDictionaries()

bool listTSDictionaries ( const char *  pattern,
bool  verbose 
)

Definition at line 5514 of file describe.c.

5515{
5517 PGresult *res;
5518 printQueryOpt myopt = pset.popt;
5519
5521
5523 "SELECT\n"
5524 " n.nspname as \"%s\",\n"
5525 " d.dictname as \"%s\",\n",
5526 gettext_noop("Schema"),
5527 gettext_noop("Name"));
5528
5529 if (verbose)
5530 {
5532 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5533 " pg_catalog.pg_ts_template t\n"
5534 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5535 " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5536 " d.dictinitoption as \"%s\",\n",
5537 gettext_noop("Template"),
5538 gettext_noop("Init options"));
5539 }
5540
5542 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5543 gettext_noop("Description"));
5544
5545 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
5546 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5547
5548 if (!validateSQLNamePattern(&buf, pattern, false, false,
5549 "n.nspname", "d.dictname", NULL,
5550 "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5551 NULL, 3))
5552 {
5554 return false;
5555 }
5556
5557 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5558
5559 res = PSQLexec(buf.data);
5561 if (!res)
5562 return false;
5563
5564 myopt.title = _("List of text search dictionaries");
5565 myopt.translate_header = true;
5566
5567 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5568
5569 PQclear(res);
5570 return true;
5571}

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

Referenced by exec_command_d().

◆ listTSParsers()

bool listTSParsers ( const char *  pattern,
bool  verbose 
)

Definition at line 5267 of file describe.c.

5268{
5270 PGresult *res;
5271 printQueryOpt myopt = pset.popt;
5272
5273 if (verbose)
5274 return listTSParsersVerbose(pattern);
5275
5277
5279 "SELECT\n"
5280 " n.nspname as \"%s\",\n"
5281 " p.prsname as \"%s\",\n"
5282 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5283 "FROM pg_catalog.pg_ts_parser p\n"
5284 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5285 gettext_noop("Schema"),
5286 gettext_noop("Name"),
5287 gettext_noop("Description")
5288 );
5289
5290 if (!validateSQLNamePattern(&buf, pattern, false, false,
5291 "n.nspname", "p.prsname", NULL,
5292 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5293 NULL, 3))
5294 {
5296 return false;
5297 }
5298
5299 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5300
5301 res = PSQLexec(buf.data);
5303 if (!res)
5304 return false;
5305
5306 myopt.title = _("List of text search parsers");
5307 myopt.translate_header = true;
5308
5309 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5310
5311 PQclear(res);
5312 return true;
5313}
static bool listTSParsersVerbose(const char *pattern)
Definition: describe.c:5319

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

Referenced by exec_command_d().

◆ listTSTemplates()

bool listTSTemplates ( const char *  pattern,
bool  verbose 
)

Definition at line 5579 of file describe.c.

5580{
5582 PGresult *res;
5583 printQueryOpt myopt = pset.popt;
5584
5586
5587 if (verbose)
5589 "SELECT\n"
5590 " n.nspname AS \"%s\",\n"
5591 " t.tmplname AS \"%s\",\n"
5592 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5593 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5594 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5595 gettext_noop("Schema"),
5596 gettext_noop("Name"),
5597 gettext_noop("Init"),
5598 gettext_noop("Lexize"),
5599 gettext_noop("Description"));
5600 else
5602 "SELECT\n"
5603 " n.nspname AS \"%s\",\n"
5604 " t.tmplname AS \"%s\",\n"
5605 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5606 gettext_noop("Schema"),
5607 gettext_noop("Name"),
5608 gettext_noop("Description"));
5609
5610 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
5611 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5612
5613 if (!validateSQLNamePattern(&buf, pattern, false, false,
5614 "n.nspname", "t.tmplname", NULL,
5615 "pg_catalog.pg_ts_template_is_visible(t.oid)",
5616 NULL, 3))
5617 {
5619 return false;
5620 }
5621
5622 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
5623
5624 res = PSQLexec(buf.data);
5626 if (!res)
5627 return false;
5628
5629 myopt.title = _("List of text search templates");
5630 myopt.translate_header = true;
5631
5632 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
5633
5634 PQclear(res);
5635 return true;
5636}

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

Referenced by exec_command_d().

◆ listUserMappings()

bool listUserMappings ( const char *  pattern,
bool  verbose 
)

Definition at line 5995 of file describe.c.

5996{
5998 PGresult *res;
5999 printQueryOpt myopt = pset.popt;
6000
6003 "SELECT um.srvname AS \"%s\",\n"
6004 " um.usename AS \"%s\"",
6005 gettext_noop("Server"),
6006 gettext_noop("User name"));
6007
6008 if (verbose)
6010 ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
6011 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6012 " pg_catalog.quote_ident(option_name) || ' ' || "
6013 " pg_catalog.quote_literal(option_value) FROM "
6014 " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
6015 " END AS \"%s\"",
6016 gettext_noop("FDW options"));
6017
6018 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
6019
6020 if (!validateSQLNamePattern(&buf, pattern, false, false,
6021 NULL, "um.srvname", "um.usename", NULL,
6022 NULL, 1))
6023 {
6025 return false;
6026 }
6027
6028 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
6029
6030 res = PSQLexec(buf.data);
6032 if (!res)
6033 return false;
6034
6035 myopt.title = _("List of user mappings");
6036 myopt.translate_header = true;
6037
6038 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
6039
6040 PQclear(res);
6041 return true;
6042}

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

Referenced by exec_command_d().

◆ objectDescription()

bool objectDescription ( const char *  pattern,
bool  showSystem 
)

Definition at line 1289 of file describe.c.

1290{
1292 PGresult *res;
1293 printQueryOpt myopt = pset.popt;
1294 static const bool translate_columns[] = {false, false, true, false};
1295
1297
1299 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1300 "FROM (\n",
1301 gettext_noop("Schema"),
1302 gettext_noop("Name"),
1303 gettext_noop("Object"),
1304 gettext_noop("Description"));
1305
1306 /* Table constraint descriptions */
1308 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1309 " n.nspname as nspname,\n"
1310 " CAST(pgc.conname AS pg_catalog.text) as name,"
1311 " CAST('%s' AS pg_catalog.text) as object\n"
1312 " FROM pg_catalog.pg_constraint pgc\n"
1313 " JOIN pg_catalog.pg_class c "
1314 "ON c.oid = pgc.conrelid\n"
1315 " LEFT JOIN pg_catalog.pg_namespace n "
1316 " ON n.oid = c.relnamespace\n",
1317 gettext_noop("table constraint"));
1318
1319 if (!showSystem && !pattern)
1320 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1321 " AND n.nspname <> 'information_schema'\n");
1322
1323 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1324 false, "n.nspname", "pgc.conname", NULL,
1325 "pg_catalog.pg_table_is_visible(c.oid)",
1326 NULL, 3))
1327 goto error_return;
1328
1329 /* Domain constraint descriptions */
1331 "UNION ALL\n"
1332 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1333 " n.nspname as nspname,\n"
1334 " CAST(pgc.conname AS pg_catalog.text) as name,"
1335 " CAST('%s' AS pg_catalog.text) as object\n"
1336 " FROM pg_catalog.pg_constraint pgc\n"
1337 " JOIN pg_catalog.pg_type t "
1338 "ON t.oid = pgc.contypid\n"
1339 " LEFT JOIN pg_catalog.pg_namespace n "
1340 " ON n.oid = t.typnamespace\n",
1341 gettext_noop("domain constraint"));
1342
1343 if (!showSystem && !pattern)
1344 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1345 " AND n.nspname <> 'information_schema'\n");
1346
1347 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern,
1348 false, "n.nspname", "pgc.conname", NULL,
1349 "pg_catalog.pg_type_is_visible(t.oid)",
1350 NULL, 3))
1351 goto error_return;
1352
1353 /* Operator class descriptions */
1355 "UNION ALL\n"
1356 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1357 " n.nspname as nspname,\n"
1358 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1359 " CAST('%s' AS pg_catalog.text) as object\n"
1360 " FROM pg_catalog.pg_opclass o\n"
1361 " JOIN pg_catalog.pg_am am ON "
1362 "o.opcmethod = am.oid\n"
1363 " JOIN pg_catalog.pg_namespace n ON "
1364 "n.oid = o.opcnamespace\n",
1365 gettext_noop("operator class"));
1366
1367 if (!showSystem && !pattern)
1368 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1369 " AND n.nspname <> 'information_schema'\n");
1370
1371 if (!validateSQLNamePattern(&buf, pattern, true, false,
1372 "n.nspname", "o.opcname", NULL,
1373 "pg_catalog.pg_opclass_is_visible(o.oid)",
1374 NULL, 3))
1375 goto error_return;
1376
1377 /* Operator family descriptions */
1379 "UNION ALL\n"
1380 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1381 " n.nspname as nspname,\n"
1382 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1383 " CAST('%s' AS pg_catalog.text) as object\n"
1384 " FROM pg_catalog.pg_opfamily opf\n"
1385 " JOIN pg_catalog.pg_am am "
1386 "ON opf.opfmethod = am.oid\n"
1387 " JOIN pg_catalog.pg_namespace n "
1388 "ON opf.opfnamespace = n.oid\n",
1389 gettext_noop("operator family"));
1390
1391 if (!showSystem && !pattern)
1392 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1393 " AND n.nspname <> 'information_schema'\n");
1394
1395 if (!validateSQLNamePattern(&buf, pattern, true, false,
1396 "n.nspname", "opf.opfname", NULL,
1397 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1398 NULL, 3))
1399 goto error_return;
1400
1401 /* Rule descriptions (ignore rules for views) */
1403 "UNION ALL\n"
1404 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1405 " n.nspname as nspname,\n"
1406 " CAST(r.rulename AS pg_catalog.text) as name,"
1407 " CAST('%s' AS pg_catalog.text) as object\n"
1408 " FROM pg_catalog.pg_rewrite r\n"
1409 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1410 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1411 " WHERE r.rulename != '_RETURN'\n",
1412 gettext_noop("rule"));
1413
1414 if (!showSystem && !pattern)
1415 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1416 " AND n.nspname <> 'information_schema'\n");
1417
1418 if (!validateSQLNamePattern(&buf, pattern, true, false,
1419 "n.nspname", "r.rulename", NULL,
1420 "pg_catalog.pg_table_is_visible(c.oid)",
1421 NULL, 3))
1422 goto error_return;
1423
1424 /* Trigger descriptions */
1426 "UNION ALL\n"
1427 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1428 " n.nspname as nspname,\n"
1429 " CAST(t.tgname AS pg_catalog.text) as name,"
1430 " CAST('%s' AS pg_catalog.text) as object\n"
1431 " FROM pg_catalog.pg_trigger t\n"
1432 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1433 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1434 gettext_noop("trigger"));
1435
1436 if (!showSystem && !pattern)
1437 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1438 " AND n.nspname <> 'information_schema'\n");
1439
1440 if (!validateSQLNamePattern(&buf, pattern, !showSystem && !pattern, false,
1441 "n.nspname", "t.tgname", NULL,
1442 "pg_catalog.pg_table_is_visible(c.oid)",
1443 NULL, 3))
1444 goto error_return;
1445
1447 ") AS tt\n"
1448 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1449
1450 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1451
1452 res = PSQLexec(buf.data);
1454 if (!res)
1455 return false;
1456
1457 myopt.title = _("Object descriptions");
1458 myopt.translate_header = true;
1459 myopt.translate_columns = translate_columns;
1460 myopt.n_translate_columns = lengthof(translate_columns);
1461
1462 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1463
1464 PQclear(res);
1465 return true;
1466
1467error_return:
1469 return false;
1470}

References _, appendPQExpBuffer(), appendPQExpBufferStr(), buf, gettext_noop, initPQExpBuffer(), lengthof, _psqlSettings::logfile, printQueryOpt::n_translate_columns, _psqlSettings::popt, PQclear(), printQuery(), pset, PSQLexec(), _psqlSettings::queryFout, res, termPQExpBuffer(), printQueryOpt::title, printQueryOpt::translate_columns, printQueryOpt::translate_header, and validateSQLNamePattern().

Referenced by exec_command_d().

◆ permissionsList()

bool permissionsList ( const char *  pattern,
bool  showSystem 
)

Definition at line 1048 of file describe.c.

1049{
1051 PGresult *res;
1052 printQueryOpt myopt = pset.popt;
1053 static const bool translate_columns[] = {false, false, true, false, false, false};
1054
1056
1057 /*
1058 * we ignore indexes and toast tables since they have no meaningful rights
1059 */
1061 "SELECT n.nspname as \"%s\",\n"
1062 " c.relname as \"%s\",\n"
1063 " CASE c.relkind"
1064 " WHEN " CppAsString2(RELKIND_RELATION) " THEN '%s'"
1065 " WHEN " CppAsString2(RELKIND_VIEW) " THEN '%s'"
1066 " WHEN " CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
1067 " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
1068 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
1069 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
1070 " END as \"%s\",\n"
1071 " ",
1072 gettext_noop("Schema"),
1073 gettext_noop("Name"),
1074 gettext_noop("table"),
1075 gettext_noop("view"),
1076 gettext_noop("materialized view"),
1077 gettext_noop("sequence"),
1078 gettext_noop("foreign table"),
1079 gettext_noop("partitioned table"),
1080 gettext_noop("Type"));
1081
1082 printACLColumn(&buf, "c.relacl");
1083
1084 /*
1085 * The formatting of attacl should match printACLColumn(). However, we
1086 * need no special case for an empty attacl, because the backend always
1087 * optimizes that back to NULL.
1088 */
1090 ",\n pg_catalog.array_to_string(ARRAY(\n"
1091 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1092 " FROM pg_catalog.pg_attribute a\n"
1093 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1094 " ), E'\\n') AS \"%s\"",
1095 gettext_noop("Column privileges"));
1096
1097 if (pset.sversion >= 90500 && pset.sversion < 100000)
1099 ",\n pg_catalog.array_to_string(ARRAY(\n"
1100 " SELECT polname\n"
1101 " || CASE WHEN polcmd != '*' THEN\n"
1102 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1103 " ELSE E':'\n"
1104 " END\n"
1105 " || CASE WHEN polqual IS NOT NULL THEN\n"
1106 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1107 " ELSE E''\n"
1108 " END\n"
1109 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1110 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1111 " ELSE E''\n"
1112 " END"
1113 " || CASE WHEN polroles <> '{0}' THEN\n"
1114 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1115 " ARRAY(\n"
1116 " SELECT rolname\n"
1117 " FROM pg_catalog.pg_roles\n"
1118 " WHERE oid = ANY (polroles)\n"
1119 " ORDER BY 1\n"
1120 " ), E', ')\n"
1121 " ELSE E''\n"
1122 " END\n"
1123 " FROM pg_catalog.pg_policy pol\n"
1124 " WHERE polrelid = c.oid), E'\\n')\n"
1125 " AS \"%s\"",
1126 gettext_noop("Policies"));
1127
1128 if (pset.sversion >= 100000)
1130 ",\n pg_catalog.array_to_string(ARRAY(\n"
1131 " SELECT polname\n"
1132 " || CASE WHEN NOT polpermissive THEN\n"
1133 " E' (RESTRICTIVE)'\n"
1134 " ELSE '' END\n"
1135 " || CASE WHEN polcmd != '*' THEN\n"
1136 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1137 " ELSE E':'\n"
1138 " END\n"
1139 " || CASE WHEN polqual IS NOT NULL THEN\n"
1140 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1141 " ELSE E''\n"
1142 " END\n"
1143 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1144 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1145 " ELSE E''\n"
1146 " END"
1147 " || CASE WHEN polroles <> '{0}' THEN\n"
1148 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1149 " ARRAY(\n"
1150 " SELECT rolname\n"
1151 " FROM pg_catalog.pg_roles\n"
1152 " WHERE oid = ANY (polroles)\n"
1153 " ORDER BY 1\n"
1154 " ), E', ')\n"
1155 " ELSE E''\n"
1156 " END\n"
1157 " FROM pg_catalog.pg_policy pol\n"
1158 " WHERE polrelid = c.oid), E'\\n')\n"
1159 " AS \"%s\"",
1160 gettext_noop("Policies"));
1161
1162 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
1163 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1164 "WHERE c.relkind IN ("
1165 CppAsString2(RELKIND_RELATION) ","
1166 CppAsString2(RELKIND_VIEW) ","
1167 CppAsString2(RELKIND_MATVIEW) ","
1168 CppAsString2(RELKIND_SEQUENCE) ","
1169 CppAsString2(RELKIND_FOREIGN_TABLE) ","
1170 CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
1171
1172 if (!showSystem && !pattern)
1173 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1174 " AND n.nspname <> 'information_schema'\n");
1175
1176 if (!validateSQLNamePattern(&buf, pattern, true, false,
1177 "n.nspname", "c.relname", NULL,
1178 "pg_catalog.pg_table_is_visible(c.oid)",
1179 NULL, 3))
1180 goto error_return;
1181
1182 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
1183
1184 res = PSQLexec(buf.data);
1185 if (!res)
1186 goto error_return;
1187
1188 printfPQExpBuffer(&buf, _("Access privileges"));
1189 myopt.title = buf.data;
1190 myopt.translate_header = true;
1191 myopt.translate_columns = translate_columns;
1192 myopt.n_translate_columns = lengthof(translate_columns);
1193
1194 printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
1195
1197 PQclear(res);
1198 return true;
1199
1200error_return:
1202 return false;
1203}

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

Referenced by exec_command_d(), and exec_command_z().