2 * psql - the PostgreSQL interactive terminal
4 * Support for the various \d ("describe") commands. Note that the current
5 * expectation is that all functions in this file will succeed when working
6 * with servers of versions 7.4 and up. It's okay to omit irrelevant
7 * information for an old server, but not to fail outright.
9 * Copyright (c) 2000-2011, PostgreSQL Global Development Group
11 * src/bin/psql/describe.c
13 #include "postgres_fe.h"
19 #include "dumputils.h"
23 #include "variables.h"
26 static bool describeOneTableDetails(const char *schemaname,
27 const char *relationname,
30 static void add_tablespace_footer(printTableContent *const cont, char relkind,
31 Oid tablespace, const bool newline);
32 static void add_role_attribute(PQExpBuffer buf, const char *const str);
33 static bool listTSParsersVerbose(const char *pattern);
34 static bool describeOneTSParser(const char *oid, const char *nspname,
36 static bool listTSConfigsVerbose(const char *pattern);
37 static bool describeOneTSConfig(const char *oid, const char *nspname,
39 const char *pnspname, const char *prsname);
40 static void printACLColumn(PQExpBuffer buf, const char *colname);
41 static bool listOneExtensionContents(const char *extname, const char *oid);
45 * Handlers for various slash commands displaying some sort of list
46 * of things in the database.
48 * Note: try to format the queries to look nice in -E output.
54 * Takes an optional regexp to select particular aggregates
57 describeAggregates(const char *pattern, bool verbose, bool showSystem)
61 printQueryOpt myopt = pset.popt;
63 initPQExpBuffer(&buf);
65 printfPQExpBuffer(&buf,
66 "SELECT n.nspname as \"%s\",\n"
67 " p.proname AS \"%s\",\n"
68 " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n",
69 gettext_noop("Schema"),
71 gettext_noop("Result data type"));
73 if (pset.sversion >= 80200)
74 appendPQExpBuffer(&buf,
75 " CASE WHEN p.pronargs = 0\n"
76 " THEN CAST('*' AS pg_catalog.text)\n"
78 " pg_catalog.array_to_string(ARRAY(\n"
80 " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
82 " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
85 gettext_noop("Argument data types"));
87 appendPQExpBuffer(&buf,
88 " pg_catalog.format_type(p.proargtypes[0], NULL) AS \"%s\",\n",
89 gettext_noop("Argument data types"));
91 appendPQExpBuffer(&buf,
92 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
93 "FROM pg_catalog.pg_proc p\n"
94 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
96 gettext_noop("Description"));
98 if (!showSystem && !pattern)
99 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
100 " AND n.nspname <> 'information_schema'\n");
102 processSQLNamePattern(pset.db, &buf, pattern, true, false,
103 "n.nspname", "p.proname", NULL,
104 "pg_catalog.pg_function_is_visible(p.oid)");
106 appendPQExpBuffer(&buf, "ORDER BY 1, 2, 4;");
108 res = PSQLexec(buf.data, false);
109 termPQExpBuffer(&buf);
113 myopt.nullPrint = NULL;
114 myopt.title = _("List of aggregate functions");
115 myopt.translate_header = true;
117 printQuery(res, &myopt, pset.queryFout, pset.logfile);
124 * Takes an optional regexp to select particular tablespaces
127 describeTablespaces(const char *pattern, bool verbose)
131 printQueryOpt myopt = pset.popt;
133 if (pset.sversion < 80000)
135 fprintf(stderr, _("The server (version %d.%d) does not support tablespaces.\n"),
136 pset.sversion / 10000, (pset.sversion / 100) % 100);
140 initPQExpBuffer(&buf);
142 printfPQExpBuffer(&buf,
143 "SELECT spcname AS \"%s\",\n"
144 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
145 " spclocation AS \"%s\"",
146 gettext_noop("Name"),
147 gettext_noop("Owner"),
148 gettext_noop("Location"));
152 appendPQExpBuffer(&buf, ",\n ");
153 printACLColumn(&buf, "spcacl");
156 if (verbose && pset.sversion >= 80200)
157 appendPQExpBuffer(&buf,
158 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
159 gettext_noop("Description"));
161 appendPQExpBuffer(&buf,
162 "\nFROM pg_catalog.pg_tablespace\n");
164 processSQLNamePattern(pset.db, &buf, pattern, false, false,
165 NULL, "spcname", NULL,
168 appendPQExpBuffer(&buf, "ORDER BY 1;");
170 res = PSQLexec(buf.data, false);
171 termPQExpBuffer(&buf);
175 myopt.nullPrint = NULL;
176 myopt.title = _("List of tablespaces");
177 myopt.translate_header = true;
179 printQuery(res, &myopt, pset.queryFout, pset.logfile);
187 * Takes an optional regexp to select particular functions.
189 * As with \d, you can specify the kinds of functions you want:
196 * and you can mix and match these in any order.
199 describeFunctions(const char *functypes, const char *pattern, bool verbose, bool showSystem)
201 bool showAggregate = strchr(functypes, 'a') != NULL;
202 bool showNormal = strchr(functypes, 'n') != NULL;
203 bool showTrigger = strchr(functypes, 't') != NULL;
204 bool showWindow = strchr(functypes, 'w') != NULL;
208 printQueryOpt myopt = pset.popt;
209 static const bool translate_columns[] = {false, false, false, false, true, true, false, false, false, false};
211 if (strlen(functypes) != strspn(functypes, "antwS+"))
213 fprintf(stderr, _("\\df only takes [antwS+] as options\n"));
217 if (showWindow && pset.sversion < 80400)
219 fprintf(stderr, _("\\df does not take a \"w\" option with server version %d.%d\n"),
220 pset.sversion / 10000, (pset.sversion / 100) % 100);
224 if (!showAggregate && !showNormal && !showTrigger && !showWindow)
226 showAggregate = showNormal = showTrigger = true;
227 if (pset.sversion >= 80400)
231 initPQExpBuffer(&buf);
233 printfPQExpBuffer(&buf,
234 "SELECT n.nspname as \"%s\",\n"
235 " p.proname as \"%s\",\n",
236 gettext_noop("Schema"),
237 gettext_noop("Name"));
239 if (pset.sversion >= 80400)
240 appendPQExpBuffer(&buf,
241 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
242 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
244 " WHEN p.proisagg THEN '%s'\n"
245 " WHEN p.proiswindow THEN '%s'\n"
246 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
249 gettext_noop("Result data type"),
250 gettext_noop("Argument data types"),
251 /* translator: "agg" is short for "aggregate" */
253 gettext_noop("window"),
254 gettext_noop("trigger"),
255 gettext_noop("normal"),
256 gettext_noop("Type"));
257 else if (pset.sversion >= 80100)
258 appendPQExpBuffer(&buf,
259 " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
260 " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
261 " CASE WHEN proallargtypes IS NOT NULL THEN\n"
262 " pg_catalog.array_to_string(ARRAY(\n"
265 " WHEN p.proargmodes[s.i] = 'i' THEN ''\n"
266 " WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n"
267 " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n"
268 " WHEN p.proargmodes[s.i] = 'v' THEN 'VARIADIC '\n"
271 " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n"
272 " ELSE p.proargnames[s.i] || ' ' \n"
274 " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n"
276 " pg_catalog.generate_series(1, pg_catalog.array_upper(p.proallargtypes, 1)) AS s(i)\n"
279 " pg_catalog.array_to_string(ARRAY(\n"
282 " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n"
283 " ELSE p.proargnames[s.i+1] || ' '\n"
285 " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
287 " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
291 " WHEN p.proisagg THEN '%s'\n"
292 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
295 gettext_noop("Result data type"),
296 gettext_noop("Argument data types"),
297 /* translator: "agg" is short for "aggregate" */
299 gettext_noop("trigger"),
300 gettext_noop("normal"),
301 gettext_noop("Type"));
303 appendPQExpBuffer(&buf,
304 " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
305 " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
306 " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
308 " WHEN p.proisagg THEN '%s'\n"
309 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
312 gettext_noop("Result data type"),
313 gettext_noop("Argument data types"),
314 /* translator: "agg" is short for "aggregate" */
316 gettext_noop("trigger"),
317 gettext_noop("normal"),
318 gettext_noop("Type"));
321 appendPQExpBuffer(&buf,
323 " WHEN p.provolatile = 'i' THEN '%s'\n"
324 " WHEN p.provolatile = 's' THEN '%s'\n"
325 " WHEN p.provolatile = 'v' THEN '%s'\n"
327 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\",\n"
328 " l.lanname as \"%s\",\n"
329 " p.prosrc as \"%s\",\n"
330 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
331 gettext_noop("immutable"),
332 gettext_noop("stable"),
333 gettext_noop("volatile"),
334 gettext_noop("Volatility"),
335 gettext_noop("Owner"),
336 gettext_noop("Language"),
337 gettext_noop("Source code"),
338 gettext_noop("Description"));
340 appendPQExpBuffer(&buf,
341 "\nFROM pg_catalog.pg_proc p"
342 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
345 appendPQExpBuffer(&buf,
346 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
350 /* filter by function type, if requested */
351 if (showNormal && showAggregate && showTrigger && showWindow)
358 appendPQExpBuffer(&buf, " AND ");
361 appendPQExpBuffer(&buf, "WHERE ");
364 appendPQExpBuffer(&buf, "NOT p.proisagg\n");
369 appendPQExpBuffer(&buf, " AND ");
372 appendPQExpBuffer(&buf, "WHERE ");
375 appendPQExpBuffer(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
377 if (!showWindow && pset.sversion >= 80400)
380 appendPQExpBuffer(&buf, " AND ");
383 appendPQExpBuffer(&buf, "WHERE ");
386 appendPQExpBuffer(&buf, "NOT p.proiswindow\n");
391 bool needs_or = false;
393 appendPQExpBuffer(&buf, "WHERE (\n ");
395 /* Note: at least one of these must be true ... */
398 appendPQExpBuffer(&buf, "p.proisagg\n");
404 appendPQExpBuffer(&buf, " OR ");
405 appendPQExpBuffer(&buf,
406 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
412 appendPQExpBuffer(&buf, " OR ");
413 appendPQExpBuffer(&buf, "p.proiswindow\n");
416 appendPQExpBuffer(&buf, " )\n");
419 processSQLNamePattern(pset.db, &buf, pattern, have_where, false,
420 "n.nspname", "p.proname", NULL,
421 "pg_catalog.pg_function_is_visible(p.oid)");
423 if (!showSystem && !pattern)
424 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
425 " AND n.nspname <> 'information_schema'\n");
427 appendPQExpBuffer(&buf, "ORDER BY 1, 2, 4;");
429 res = PSQLexec(buf.data, false);
430 termPQExpBuffer(&buf);
434 myopt.nullPrint = NULL;
435 myopt.title = _("List of functions");
436 myopt.translate_header = true;
437 myopt.translate_columns = translate_columns;
439 printQuery(res, &myopt, pset.queryFout, pset.logfile);
452 describeTypes(const char *pattern, bool verbose, bool showSystem)
456 printQueryOpt myopt = pset.popt;
458 initPQExpBuffer(&buf);
460 printfPQExpBuffer(&buf,
461 "SELECT n.nspname as \"%s\",\n"
462 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
463 gettext_noop("Schema"),
464 gettext_noop("Name"));
466 appendPQExpBuffer(&buf,
467 " t.typname AS \"%s\",\n"
468 " CASE WHEN t.typrelid != 0\n"
469 " THEN CAST('tuple' AS pg_catalog.text)\n"
470 " WHEN t.typlen < 0\n"
471 " THEN CAST('var' AS pg_catalog.text)\n"
472 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
474 gettext_noop("Internal name"),
475 gettext_noop("Size"));
476 if (verbose && pset.sversion >= 80300)
478 appendPQExpBuffer(&buf,
479 " pg_catalog.array_to_string(\n"
481 " SELECT e.enumlabel\n"
482 " FROM pg_catalog.pg_enum e\n"
483 " WHERE e.enumtypid = t.oid\n");
485 if (pset.sversion >= 90100)
486 appendPQExpBuffer(&buf,
487 " ORDER BY e.enumsortorder\n");
489 appendPQExpBuffer(&buf,
490 " ORDER BY e.oid\n");
492 appendPQExpBuffer(&buf,
496 gettext_noop("Elements"));
499 appendPQExpBuffer(&buf,
500 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
501 gettext_noop("Description"));
503 appendPQExpBuffer(&buf, "FROM pg_catalog.pg_type t\n"
504 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
507 * do not include complex types (typrelid!=0) unless they are standalone
510 appendPQExpBuffer(&buf, "WHERE (t.typrelid = 0 ");
511 appendPQExpBuffer(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c "
512 "WHERE c.oid = t.typrelid))\n");
515 * do not include array types (before 8.3 we have to use the assumption
516 * that their names start with underscore)
518 if (pset.sversion >= 80300)
519 appendPQExpBuffer(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
521 appendPQExpBuffer(&buf, " AND t.typname !~ '^_'\n");
523 if (!showSystem && !pattern)
524 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
525 " AND n.nspname <> 'information_schema'\n");
527 /* Match name pattern against either internal or external name */
528 processSQLNamePattern(pset.db, &buf, pattern, true, false,
529 "n.nspname", "t.typname",
530 "pg_catalog.format_type(t.oid, NULL)",
531 "pg_catalog.pg_type_is_visible(t.oid)");
533 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
535 res = PSQLexec(buf.data, false);
536 termPQExpBuffer(&buf);
540 myopt.nullPrint = NULL;
541 myopt.title = _("List of data types");
542 myopt.translate_header = true;
544 printQuery(res, &myopt, pset.queryFout, pset.logfile);
554 describeOperators(const char *pattern, bool showSystem)
558 printQueryOpt myopt = pset.popt;
560 initPQExpBuffer(&buf);
563 * Note: before Postgres 9.1, we did not assign comments to any built-in
564 * operators, preferring to let the comment on the underlying function
565 * suffice. The coalesce() on the obj_description() calls below supports
566 * this convention by providing a fallback lookup of a comment on the
567 * operator's function. As of 9.1 there is a policy that every built-in
568 * operator should have a comment; so the coalesce() is no longer
569 * necessary so far as built-in operators are concerned. We keep it
570 * anyway, for now, because (1) third-party modules may still be following
571 * the old convention, and (2) we'd need to do it anyway when talking to a
575 printfPQExpBuffer(&buf,
576 "SELECT n.nspname as \"%s\",\n"
577 " o.oprname AS \"%s\",\n"
578 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
579 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
580 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n"
581 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
582 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
583 "FROM pg_catalog.pg_operator o\n"
584 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
585 gettext_noop("Schema"),
586 gettext_noop("Name"),
587 gettext_noop("Left arg type"),
588 gettext_noop("Right arg type"),
589 gettext_noop("Result type"),
590 gettext_noop("Description"));
592 if (!showSystem && !pattern)
593 appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
594 " AND n.nspname <> 'information_schema'\n");
596 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
597 "n.nspname", "o.oprname", NULL,
598 "pg_catalog.pg_operator_is_visible(o.oid)");
600 appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3, 4;");
602 res = PSQLexec(buf.data, false);
603 termPQExpBuffer(&buf);
607 myopt.nullPrint = NULL;
608 myopt.title = _("List of operators");
609 myopt.translate_header = true;
611 printQuery(res, &myopt, pset.queryFout, pset.logfile);
621 * for \l, \list, and -l switch
624 listAllDbs(bool verbose)
628 printQueryOpt myopt = pset.popt;
630 initPQExpBuffer(&buf);
632 printfPQExpBuffer(&buf,
633 "SELECT d.datname as \"%s\",\n"
634 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
635 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
636 gettext_noop("Name"),
637 gettext_noop("Owner"),
638 gettext_noop("Encoding"));
639 if (pset.sversion >= 80400)
640 appendPQExpBuffer(&buf,
641 " d.datcollate as \"%s\",\n"
642 " d.datctype as \"%s\",\n",
643 gettext_noop("Collate"),
644 gettext_noop("Ctype"));
645 appendPQExpBuffer(&buf, " ");
646 printACLColumn(&buf, "d.datacl");
647 if (verbose && pset.sversion >= 80200)
648 appendPQExpBuffer(&buf,
649 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
650 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
651 " ELSE 'No Access'\n"
653 gettext_noop("Size"));
654 if (verbose && pset.sversion >= 80000)
655 appendPQExpBuffer(&buf,
656 ",\n t.spcname as \"%s\"",
657 gettext_noop("Tablespace"));
658 if (verbose && pset.sversion >= 80200)
659 appendPQExpBuffer(&buf,
660 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
661 gettext_noop("Description"));
662 appendPQExpBuffer(&buf,
663 "\nFROM pg_catalog.pg_database d\n");
664 if (verbose && pset.sversion >= 80000)
665 appendPQExpBuffer(&buf,
666 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
667 appendPQExpBuffer(&buf, "ORDER BY 1;");
668 res = PSQLexec(buf.data, false);
669 termPQExpBuffer(&buf);
673 myopt.nullPrint = NULL;
674 myopt.title = _("List of databases");
675 myopt.translate_header = true;
677 printQuery(res, &myopt, pset.queryFout, pset.logfile);
685 * List Tables' Grant/Revoke Permissions
686 * \z (now also \dp -- perhaps more mnemonic)
689 permissionsList(const char *pattern)
693 printQueryOpt myopt = pset.popt;
694 static const bool translate_columns[] = {false, false, true, false, false};
696 initPQExpBuffer(&buf);
699 * we ignore indexes and toast tables since they have no meaningful rights
701 printfPQExpBuffer(&buf,
702 "SELECT n.nspname as \"%s\",\n"
703 " c.relname as \"%s\",\n"
704 " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'S' THEN '%s' WHEN 'f' THEN '%s' END as \"%s\",\n"
706 gettext_noop("Schema"),
707 gettext_noop("Name"),
708 gettext_noop("table"), gettext_noop("view"), gettext_noop("sequence"),
709 gettext_noop("foreign table"),
710 gettext_noop("Type"));
712 printACLColumn(&buf, "c.relacl");
714 if (pset.sversion >= 80400)
715 appendPQExpBuffer(&buf,
716 ",\n pg_catalog.array_to_string(ARRAY(\n"
717 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
718 " FROM pg_catalog.pg_attribute a\n"
719 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
720 " ), E'\\n') AS \"%s\"",
721 gettext_noop("Column access privileges"));
723 appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_class c\n"
724 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
725 "WHERE c.relkind IN ('r', 'v', 'S', 'f')\n");
728 * Unless a schema pattern is specified, we suppress system and temp
729 * tables, since they normally aren't very interesting from a permissions
730 * point of view. You can see 'em by explicit request though, eg with \z
733 processSQLNamePattern(pset.db, &buf, pattern, true, false,
734 "n.nspname", "c.relname", NULL,
735 "n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)");
737 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
739 res = PSQLexec(buf.data, false);
742 termPQExpBuffer(&buf);
746 myopt.nullPrint = NULL;
747 printfPQExpBuffer(&buf, _("Access privileges"));
748 myopt.title = buf.data;
749 myopt.translate_header = true;
750 myopt.translate_columns = translate_columns;
752 printQuery(res, &myopt, pset.queryFout, pset.logfile);
754 termPQExpBuffer(&buf);
763 * List DefaultACLs. The pattern can match either schema or role name.
766 listDefaultACLs(const char *pattern)
770 printQueryOpt myopt = pset.popt;
771 static const bool translate_columns[] = {false, false, true, false};
773 if (pset.sversion < 90000)
775 fprintf(stderr, _("The server (version %d.%d) does not support altering default privileges.\n"),
776 pset.sversion / 10000, (pset.sversion / 100) % 100);
780 initPQExpBuffer(&buf);
782 printfPQExpBuffer(&buf,
783 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
784 " n.nspname AS \"%s\",\n"
785 " CASE d.defaclobjtype WHEN 'r' THEN '%s' WHEN 'S' THEN '%s' WHEN 'f' THEN '%s' END AS \"%s\",\n"
787 gettext_noop("Owner"),
788 gettext_noop("Schema"),
789 gettext_noop("table"),
790 gettext_noop("sequence"),
791 gettext_noop("function"),
792 gettext_noop("Type"));
794 printACLColumn(&buf, "d.defaclacl");
796 appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
797 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
799 processSQLNamePattern(pset.db, &buf, pattern, false, false,
802 "pg_catalog.pg_get_userbyid(d.defaclrole)",
805 appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;");
807 res = PSQLexec(buf.data, false);
810 termPQExpBuffer(&buf);
814 myopt.nullPrint = NULL;
815 printfPQExpBuffer(&buf, _("Default access privileges"));
816 myopt.title = buf.data;
817 myopt.translate_header = true;
818 myopt.translate_columns = translate_columns;
820 printQuery(res, &myopt, pset.queryFout, pset.logfile);
822 termPQExpBuffer(&buf);
829 * Get object comments
833 * Note: This only lists things that actually have a description. For complete
834 * lists of things, there are other \d? commands.
837 objectDescription(const char *pattern, bool showSystem)
841 printQueryOpt myopt = pset.popt;
842 static const bool translate_columns[] = {false, false, true, false};
844 initPQExpBuffer(&buf);
846 appendPQExpBuffer(&buf,
847 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
849 gettext_noop("Schema"),
850 gettext_noop("Name"),
851 gettext_noop("Object"),
852 gettext_noop("Description"));
854 /* Aggregate descriptions */
855 appendPQExpBuffer(&buf,
856 " SELECT p.oid as oid, p.tableoid as tableoid,\n"
857 " n.nspname as nspname,\n"
858 " CAST(p.proname AS pg_catalog.text) as name,"
859 " CAST('%s' AS pg_catalog.text) as object\n"
860 " FROM pg_catalog.pg_proc p\n"
861 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
862 " WHERE p.proisagg\n",
863 gettext_noop("aggregate"));
865 if (!showSystem && !pattern)
866 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
867 " AND n.nspname <> 'information_schema'\n");
869 processSQLNamePattern(pset.db, &buf, pattern, true, false,
870 "n.nspname", "p.proname", NULL,
871 "pg_catalog.pg_function_is_visible(p.oid)");
873 /* Function descriptions */
874 appendPQExpBuffer(&buf,
876 " SELECT p.oid as oid, p.tableoid as tableoid,\n"
877 " n.nspname as nspname,\n"
878 " CAST(p.proname AS pg_catalog.text) as name,"
879 " CAST('%s' AS pg_catalog.text) as object\n"
880 " FROM pg_catalog.pg_proc p\n"
881 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
882 " WHERE NOT p.proisagg\n",
883 gettext_noop("function"));
885 if (!showSystem && !pattern)
886 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
887 " AND n.nspname <> 'information_schema'\n");
889 processSQLNamePattern(pset.db, &buf, pattern, true, false,
890 "n.nspname", "p.proname", NULL,
891 "pg_catalog.pg_function_is_visible(p.oid)");
893 /* Operator descriptions */
894 appendPQExpBuffer(&buf,
896 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
897 " n.nspname as nspname,\n"
898 " CAST(o.oprname AS pg_catalog.text) as name,"
899 " CAST('%s' AS pg_catalog.text) as object\n"
900 " FROM pg_catalog.pg_operator o\n"
901 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
902 gettext_noop("operator"));
904 if (!showSystem && !pattern)
905 appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
906 " AND n.nspname <> 'information_schema'\n");
908 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
909 "n.nspname", "o.oprname", NULL,
910 "pg_catalog.pg_operator_is_visible(o.oid)");
912 /* Type descriptions */
913 appendPQExpBuffer(&buf,
915 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
916 " n.nspname as nspname,\n"
917 " pg_catalog.format_type(t.oid, NULL) as name,"
918 " CAST('%s' AS pg_catalog.text) as object\n"
919 " FROM pg_catalog.pg_type t\n"
920 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n",
921 gettext_noop("data type"));
923 if (!showSystem && !pattern)
924 appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
925 " AND n.nspname <> 'information_schema'\n");
927 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
928 "n.nspname", "pg_catalog.format_type(t.oid, NULL)",
930 "pg_catalog.pg_type_is_visible(t.oid)");
932 /* Relation (tables, views, indexes, sequences) descriptions */
933 appendPQExpBuffer(&buf,
935 " SELECT c.oid as oid, c.tableoid as tableoid,\n"
936 " n.nspname as nspname,\n"
937 " CAST(c.relname AS pg_catalog.text) as name,\n"
939 " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' WHEN 'f' THEN '%s' END"
940 " AS pg_catalog.text) as object\n"
941 " FROM pg_catalog.pg_class c\n"
942 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
943 " WHERE c.relkind IN ('r', 'v', 'i', 'S', 'f')\n",
944 gettext_noop("table"),
945 gettext_noop("view"),
946 gettext_noop("index"),
947 gettext_noop("sequence"),
948 gettext_noop("foreign table"));
950 if (!showSystem && !pattern)
951 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
952 " AND n.nspname <> 'information_schema'\n");
954 processSQLNamePattern(pset.db, &buf, pattern, true, false,
955 "n.nspname", "c.relname", NULL,
956 "pg_catalog.pg_table_is_visible(c.oid)");
958 /* Rule descriptions (ignore rules for views) */
959 appendPQExpBuffer(&buf,
961 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
962 " n.nspname as nspname,\n"
963 " CAST(r.rulename AS pg_catalog.text) as name,"
964 " CAST('%s' AS pg_catalog.text) as object\n"
965 " FROM pg_catalog.pg_rewrite r\n"
966 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
967 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
968 " WHERE r.rulename != '_RETURN'\n",
969 gettext_noop("rule"));
971 if (!showSystem && !pattern)
972 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
973 " AND n.nspname <> 'information_schema'\n");
975 /* XXX not sure what to do about visibility rule here? */
976 processSQLNamePattern(pset.db, &buf, pattern, true, false,
977 "n.nspname", "r.rulename", NULL,
978 "pg_catalog.pg_table_is_visible(c.oid)");
980 /* Trigger descriptions */
981 appendPQExpBuffer(&buf,
983 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
984 " n.nspname as nspname,\n"
985 " CAST(t.tgname AS pg_catalog.text) as name,"
986 " CAST('%s' AS pg_catalog.text) as object\n"
987 " FROM pg_catalog.pg_trigger t\n"
988 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
989 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
990 gettext_noop("trigger"));
992 if (!showSystem && !pattern)
993 appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
994 " AND n.nspname <> 'information_schema'\n");
996 /* XXX not sure what to do about visibility rule here? */
997 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
998 "n.nspname", "t.tgname", NULL,
999 "pg_catalog.pg_table_is_visible(c.oid)");
1001 appendPQExpBuffer(&buf,
1003 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1005 appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;");
1007 res = PSQLexec(buf.data, false);
1008 termPQExpBuffer(&buf);
1012 myopt.nullPrint = NULL;
1013 myopt.title = _("Object descriptions");
1014 myopt.translate_header = true;
1015 myopt.translate_columns = translate_columns;
1017 printQuery(res, &myopt, pset.queryFout, pset.logfile);
1025 * describeTableDetails (for \d)
1027 * This routine finds the tables to be displayed, and calls
1028 * describeOneTableDetails for each one.
1030 * verbose: if true, this is \d+
1033 describeTableDetails(const char *pattern, bool verbose, bool showSystem)
1035 PQExpBufferData buf;
1039 initPQExpBuffer(&buf);
1041 printfPQExpBuffer(&buf,
1045 "FROM pg_catalog.pg_class c\n"
1046 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1048 if (!showSystem && !pattern)
1049 appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1050 " AND n.nspname <> 'information_schema'\n");
1052 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1053 "n.nspname", "c.relname", NULL,
1054 "pg_catalog.pg_table_is_visible(c.oid)");
1056 appendPQExpBuffer(&buf, "ORDER BY 2, 3;");
1058 res = PSQLexec(buf.data, false);
1059 termPQExpBuffer(&buf);
1063 if (PQntuples(res) == 0)
1066 fprintf(stderr, _("Did not find any relation named \"%s\".\n"),
1072 for (i = 0; i < PQntuples(res); i++)
1075 const char *nspname;
1076 const char *relname;
1078 oid = PQgetvalue(res, i, 0);
1079 nspname = PQgetvalue(res, i, 1);
1080 relname = PQgetvalue(res, i, 2);
1082 if (!describeOneTableDetails(nspname, relname, oid, verbose))
1099 * describeOneTableDetails (for \d)
1101 * Unfortunately, the information presented here is so complicated that it
1102 * cannot be done in a single query. So we have to assemble the printed table
1103 * by hand and pass it to the underlying printTable() function.
1106 describeOneTableDetails(const char *schemaname,
1107 const char *relationname,
1111 PQExpBufferData buf;
1112 PGresult *res = NULL;
1113 printTableOpt myopt = pset.popt.topt;
1114 printTableContent cont;
1115 bool printTableInitialized = false;
1117 char *view_def = NULL;
1119 char **seq_values = NULL;
1120 char **modifiers = NULL;
1122 PQExpBufferData title;
1123 PQExpBufferData tmpbuf;
1137 char relpersistence;
1139 bool show_modifiers = false;
1144 /* This output looks confusing in expanded mode. */
1145 myopt.expanded = false;
1147 initPQExpBuffer(&buf);
1148 initPQExpBuffer(&title);
1149 initPQExpBuffer(&tmpbuf);
1151 /* Get general table info */
1152 if (pset.sversion >= 90100)
1154 printfPQExpBuffer(&buf,
1155 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1156 "c.relhastriggers, c.relhasoids, "
1157 "%s, c.reltablespace, "
1158 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1159 "c.relpersistence\n"
1160 "FROM pg_catalog.pg_class c\n "
1161 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1162 "WHERE c.oid = '%s'\n",
1164 "pg_catalog.array_to_string(c.reloptions || "
1165 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1169 else if (pset.sversion >= 90000)
1171 printfPQExpBuffer(&buf,
1172 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1173 "c.relhastriggers, c.relhasoids, "
1174 "%s, c.reltablespace, "
1175 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END\n"
1176 "FROM pg_catalog.pg_class c\n "
1177 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1178 "WHERE c.oid = '%s'\n",
1180 "pg_catalog.array_to_string(c.reloptions || "
1181 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1185 else if (pset.sversion >= 80400)
1187 printfPQExpBuffer(&buf,
1188 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1189 "c.relhastriggers, c.relhasoids, "
1190 "%s, c.reltablespace\n"
1191 "FROM pg_catalog.pg_class c\n "
1192 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1193 "WHERE c.oid = '%s'\n",
1195 "pg_catalog.array_to_string(c.reloptions || "
1196 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1200 else if (pset.sversion >= 80200)
1202 printfPQExpBuffer(&buf,
1203 "SELECT relchecks, relkind, relhasindex, relhasrules, "
1204 "reltriggers <> 0, relhasoids, "
1205 "%s, reltablespace\n"
1206 "FROM pg_catalog.pg_class WHERE oid = '%s'",
1208 "pg_catalog.array_to_string(reloptions, E', ')" : "''"),
1211 else if (pset.sversion >= 80000)
1213 printfPQExpBuffer(&buf,
1214 "SELECT relchecks, relkind, relhasindex, relhasrules, "
1215 "reltriggers <> 0, relhasoids, "
1216 "'', reltablespace\n"
1217 "FROM pg_catalog.pg_class WHERE oid = '%s'",
1222 printfPQExpBuffer(&buf,
1223 "SELECT relchecks, relkind, relhasindex, relhasrules, "
1224 "reltriggers <> 0, relhasoids, "
1226 "FROM pg_catalog.pg_class WHERE oid = '%s'",
1230 res = PSQLexec(buf.data, false);
1234 /* Did we get anything? */
1235 if (PQntuples(res) == 0)
1238 fprintf(stderr, _("Did not find any relation with OID %s.\n"),
1243 tableinfo.checks = atoi(PQgetvalue(res, 0, 0));
1244 tableinfo.relkind = *(PQgetvalue(res, 0, 1));
1245 tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 2), "t") == 0;
1246 tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 3), "t") == 0;
1247 tableinfo.hastriggers = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
1248 tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
1249 tableinfo.reloptions = (pset.sversion >= 80200) ?
1250 strdup(PQgetvalue(res, 0, 6)) : 0;
1251 tableinfo.tablespace = (pset.sversion >= 80000) ?
1252 atooid(PQgetvalue(res, 0, 7)) : 0;
1253 tableinfo.reloftype = (pset.sversion >= 90000 && strcmp(PQgetvalue(res, 0, 8), "") != 0) ?
1254 strdup(PQgetvalue(res, 0, 8)) : 0;
1255 tableinfo.relpersistence = (pset.sversion >= 90100 && strcmp(PQgetvalue(res, 0, 9), "") != 0) ?
1256 PQgetvalue(res, 0, 9)[0] : 0;
1261 * If it's a sequence, fetch its values and store into an array that will
1264 if (tableinfo.relkind == 'S')
1266 printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));
1267 /* must be separate because fmtId isn't reentrant */
1268 appendPQExpBuffer(&buf, ".%s", fmtId(relationname));
1270 res = PSQLexec(buf.data, false);
1274 seq_values = pg_malloc((PQnfields(res) + 1) * sizeof(*seq_values));
1276 for (i = 0; i < PQnfields(res); i++)
1277 seq_values[i] = pg_strdup(PQgetvalue(res, 0, i));
1278 seq_values[i] = NULL;
1284 /* Get column info */
1285 printfPQExpBuffer(&buf, "SELECT a.attname,");
1286 appendPQExpBuffer(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod),"
1287 "\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)"
1288 "\n FROM pg_catalog.pg_attrdef d"
1289 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),"
1290 "\n a.attnotnull, a.attnum");
1291 if (pset.sversion >= 90100)
1292 appendPQExpBuffer(&buf, ",\n (SELECT collname FROM pg_collation WHERE oid = a.attcollation AND collname <> 'default') AS attcollation");
1294 appendPQExpBuffer(&buf, ",\n NULL AS attcollation");
1295 if (tableinfo.relkind == 'i')
1296 appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
1298 appendPQExpBuffer(&buf, ",\n a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
1299 appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
1300 appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1301 appendPQExpBuffer(&buf, "\nORDER BY a.attnum");
1303 res = PSQLexec(buf.data, false);
1306 numrows = PQntuples(res);
1309 switch (tableinfo.relkind)
1312 if (tableinfo.relpersistence == 'u')
1313 printfPQExpBuffer(&title, _("Unlogged table \"%s.%s\""),
1314 schemaname, relationname);
1316 printfPQExpBuffer(&title, _("Table \"%s.%s\""),
1317 schemaname, relationname);
1320 printfPQExpBuffer(&title, _("View \"%s.%s\""),
1321 schemaname, relationname);
1324 printfPQExpBuffer(&title, _("Sequence \"%s.%s\""),
1325 schemaname, relationname);
1328 if (tableinfo.relpersistence == 'u')
1329 printfPQExpBuffer(&title, _("Unlogged index \"%s.%s\""),
1330 schemaname, relationname);
1332 printfPQExpBuffer(&title, _("Index \"%s.%s\""),
1333 schemaname, relationname);
1336 /* not used as of 8.2, but keep it for backwards compatibility */
1337 printfPQExpBuffer(&title, _("Special relation \"%s.%s\""),
1338 schemaname, relationname);
1341 printfPQExpBuffer(&title, _("TOAST table \"%s.%s\""),
1342 schemaname, relationname);
1345 printfPQExpBuffer(&title, _("Composite type \"%s.%s\""),
1346 schemaname, relationname);
1349 printfPQExpBuffer(&title, _("Foreign table \"%s.%s\""),
1350 schemaname, relationname);
1353 /* untranslated unknown relkind */
1354 printfPQExpBuffer(&title, "?%c? \"%s.%s\"",
1355 tableinfo.relkind, schemaname, relationname);
1359 /* Set the number of columns, and their names */
1360 headers[0] = gettext_noop("Column");
1361 headers[1] = gettext_noop("Type");
1364 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1365 tableinfo.relkind == 'f')
1367 show_modifiers = true;
1368 headers[cols++] = gettext_noop("Modifiers");
1369 modifiers = pg_malloc_zero((numrows + 1) * sizeof(*modifiers));
1372 if (tableinfo.relkind == 'S')
1373 headers[cols++] = gettext_noop("Value");
1375 if (tableinfo.relkind == 'i')
1376 headers[cols++] = gettext_noop("Definition");
1380 headers[cols++] = gettext_noop("Storage");
1381 headers[cols++] = gettext_noop("Description");
1384 printTableInit(&cont, &myopt, title.data, cols, numrows);
1385 printTableInitialized = true;
1387 for (i = 0; i < cols; i++)
1388 printTableAddHeader(&cont, headers[i], true, 'l');
1390 /* Check if table is a view */
1391 if (tableinfo.relkind == 'v' && verbose)
1395 printfPQExpBuffer(&buf,
1396 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true)",
1398 result = PSQLexec(buf.data, false);
1402 if (PQntuples(result) > 0)
1403 view_def = pg_strdup(PQgetvalue(result, 0, 0));
1408 /* Generate table cells to be printed */
1409 for (i = 0; i < numrows; i++)
1412 printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
1415 printTableAddCell(&cont, PQgetvalue(res, i, 1), false, false);
1417 /* Modifiers: collate, not null, default */
1420 resetPQExpBuffer(&tmpbuf);
1422 if (!PQgetisnull(res, i, 5))
1425 appendPQExpBufferStr(&tmpbuf, " ");
1426 appendPQExpBuffer(&tmpbuf, _("collate %s"),
1427 PQgetvalue(res, i, 5));
1430 if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
1433 appendPQExpBufferStr(&tmpbuf, " ");
1434 appendPQExpBufferStr(&tmpbuf, _("not null"));
1437 /* handle "default" here */
1438 /* (note: above we cut off the 'default' string at 128) */
1439 if (strlen(PQgetvalue(res, i, 2)) != 0)
1442 appendPQExpBufferStr(&tmpbuf, " ");
1443 /* translator: default values of column definitions */
1444 appendPQExpBuffer(&tmpbuf, _("default %s"),
1445 PQgetvalue(res, i, 2));
1448 modifiers[i] = pg_strdup(tmpbuf.data);
1449 printTableAddCell(&cont, modifiers[i], false, false);
1452 /* Value: for sequences only */
1453 if (tableinfo.relkind == 'S')
1454 printTableAddCell(&cont, seq_values[i], false, false);
1456 /* Expression for index column */
1457 if (tableinfo.relkind == 'i')
1458 printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
1460 /* Storage and Description */
1463 int firstvcol = (tableinfo.relkind == 'i' ? 7 : 6);
1464 char *storage = PQgetvalue(res, i, firstvcol);
1466 /* these strings are literal in our syntax, so not translated. */
1467 printTableAddCell(&cont, (storage[0] == 'p' ? "plain" :
1468 (storage[0] == 'm' ? "main" :
1469 (storage[0] == 'x' ? "extended" :
1470 (storage[0] == 'e' ? "external" :
1473 printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
1479 if (tableinfo.relkind == 'i')
1481 /* Footer information about an index */
1484 printfPQExpBuffer(&buf,
1485 "SELECT i.indisunique, i.indisprimary, i.indisclustered, ");
1486 if (pset.sversion >= 80200)
1487 appendPQExpBuffer(&buf, "i.indisvalid,\n");
1489 appendPQExpBuffer(&buf, "true AS indisvalid,\n");
1490 if (pset.sversion >= 90000)
1491 appendPQExpBuffer(&buf,
1492 " (NOT i.indimmediate) AND "
1493 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
1494 "WHERE conrelid = i.indrelid AND "
1495 "conindid = i.indexrelid AND "
1496 "contype IN ('p','u','x') AND "
1497 "condeferrable) AS condeferrable,\n"
1498 " (NOT i.indimmediate) AND "
1499 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
1500 "WHERE conrelid = i.indrelid AND "
1501 "conindid = i.indexrelid AND "
1502 "contype IN ('p','u','x') AND "
1503 "condeferred) AS condeferred,\n");
1505 appendPQExpBuffer(&buf,
1506 " false AS condeferrable, false AS condeferred,\n");
1507 appendPQExpBuffer(&buf, " a.amname, c2.relname, "
1508 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
1509 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
1510 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
1511 "AND i.indrelid = c2.oid",
1514 result = PSQLexec(buf.data, false);
1517 else if (PQntuples(result) != 1)
1524 char *indisunique = PQgetvalue(result, 0, 0);
1525 char *indisprimary = PQgetvalue(result, 0, 1);
1526 char *indisclustered = PQgetvalue(result, 0, 2);
1527 char *indisvalid = PQgetvalue(result, 0, 3);
1528 char *deferrable = PQgetvalue(result, 0, 4);
1529 char *deferred = PQgetvalue(result, 0, 5);
1530 char *indamname = PQgetvalue(result, 0, 6);
1531 char *indtable = PQgetvalue(result, 0, 7);
1532 char *indpred = PQgetvalue(result, 0, 8);
1534 if (strcmp(indisprimary, "t") == 0)
1535 printfPQExpBuffer(&tmpbuf, _("primary key, "));
1536 else if (strcmp(indisunique, "t") == 0)
1537 printfPQExpBuffer(&tmpbuf, _("unique, "));
1539 resetPQExpBuffer(&tmpbuf);
1540 appendPQExpBuffer(&tmpbuf, "%s, ", indamname);
1542 /* we assume here that index and table are in same schema */
1543 appendPQExpBuffer(&tmpbuf, _("for table \"%s.%s\""),
1544 schemaname, indtable);
1546 if (strlen(indpred))
1547 appendPQExpBuffer(&tmpbuf, _(", predicate (%s)"), indpred);
1549 if (strcmp(indisclustered, "t") == 0)
1550 appendPQExpBuffer(&tmpbuf, _(", clustered"));
1552 if (strcmp(indisvalid, "t") != 0)
1553 appendPQExpBuffer(&tmpbuf, _(", invalid"));
1555 if (strcmp(deferrable, "t") == 0)
1556 appendPQExpBuffer(&tmpbuf, _(", deferrable"));
1558 if (strcmp(deferred, "t") == 0)
1559 appendPQExpBuffer(&tmpbuf, _(", initially deferred"));
1561 printTableAddFooter(&cont, tmpbuf.data);
1562 add_tablespace_footer(&cont, tableinfo.relkind,
1563 tableinfo.tablespace, true);
1570 PGresult *result = NULL;
1572 /* Footer information about a view */
1573 printTableAddFooter(&cont, _("View definition:"));
1574 printTableAddFooter(&cont, view_def);
1577 if (tableinfo.hasrules)
1579 printfPQExpBuffer(&buf,
1580 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
1581 "FROM pg_catalog.pg_rewrite r\n"
1582 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1",
1584 result = PSQLexec(buf.data, false);
1588 if (PQntuples(result) > 0)
1590 printTableAddFooter(&cont, _("Rules:"));
1591 for (i = 0; i < PQntuples(result); i++)
1593 const char *ruledef;
1595 /* Everything after "CREATE RULE" is echoed verbatim */
1596 ruledef = PQgetvalue(result, i, 1);
1599 printfPQExpBuffer(&buf, " %s", ruledef);
1600 printTableAddFooter(&cont, buf.data);
1606 else if (tableinfo.relkind == 'r' || tableinfo.relkind == 'f')
1608 /* Footer information about a table */
1609 PGresult *result = NULL;
1613 if (tableinfo.hasindex)
1615 printfPQExpBuffer(&buf,
1616 "SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, ");
1617 if (pset.sversion >= 80200)
1618 appendPQExpBuffer(&buf, "i.indisvalid, ");
1620 appendPQExpBuffer(&buf, "true as indisvalid, ");
1621 appendPQExpBuffer(&buf, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n ");
1622 if (pset.sversion >= 90000)
1623 appendPQExpBuffer(&buf,
1624 "pg_catalog.pg_get_constraintdef(con.oid, true), "
1625 "contype, condeferrable, condeferred");
1627 appendPQExpBuffer(&buf,
1628 "null AS constraintdef, null AS contype, "
1629 "false AS condeferrable, false AS condeferred");
1630 if (pset.sversion >= 80000)
1631 appendPQExpBuffer(&buf, ", c2.reltablespace");
1632 appendPQExpBuffer(&buf,
1633 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n");
1634 if (pset.sversion >= 90000)
1635 appendPQExpBuffer(&buf,
1636 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n");
1637 appendPQExpBuffer(&buf,
1638 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
1639 "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
1641 result = PSQLexec(buf.data, false);
1645 tuples = PQntuples(result);
1649 printTableAddFooter(&cont, _("Indexes:"));
1650 for (i = 0; i < tuples; i++)
1652 /* untranslated index name */
1653 printfPQExpBuffer(&buf, " \"%s\"",
1654 PQgetvalue(result, i, 0));
1656 /* If exclusion constraint, print the constraintdef */
1657 if (strcmp(PQgetvalue(result, i, 7), "x") == 0)
1659 appendPQExpBuffer(&buf, " %s",
1660 PQgetvalue(result, i, 6));
1664 const char *indexdef;
1665 const char *usingpos;
1667 /* Label as primary key or unique (but not both) */
1668 if (strcmp(PQgetvalue(result, i, 1), "t") == 0)
1669 appendPQExpBuffer(&buf, " PRIMARY KEY,");
1670 else if (strcmp(PQgetvalue(result, i, 2), "t") == 0)
1672 if (strcmp(PQgetvalue(result, i, 7), "u") == 0)
1673 appendPQExpBuffer(&buf, " UNIQUE CONSTRAINT,");
1675 appendPQExpBuffer(&buf, " UNIQUE,");
1678 /* Everything after "USING" is echoed verbatim */
1679 indexdef = PQgetvalue(result, i, 5);
1680 usingpos = strstr(indexdef, " USING ");
1682 indexdef = usingpos + 7;
1683 appendPQExpBuffer(&buf, " %s", indexdef);
1685 /* Need these for deferrable PK/UNIQUE indexes */
1686 if (strcmp(PQgetvalue(result, i, 8), "t") == 0)
1687 appendPQExpBuffer(&buf, " DEFERRABLE");
1689 if (strcmp(PQgetvalue(result, i, 9), "t") == 0)
1690 appendPQExpBuffer(&buf, " INITIALLY DEFERRED");
1693 /* Add these for all cases */
1694 if (strcmp(PQgetvalue(result, i, 3), "t") == 0)
1695 appendPQExpBuffer(&buf, " CLUSTER");
1697 if (strcmp(PQgetvalue(result, i, 4), "t") != 0)
1698 appendPQExpBuffer(&buf, " INVALID");
1700 printTableAddFooter(&cont, buf.data);
1702 /* Print tablespace of the index on the same line */
1703 if (pset.sversion >= 80000)
1704 add_tablespace_footer(&cont, 'i',
1705 atooid(PQgetvalue(result, i, 10)),
1712 /* print table (and column) check constraints */
1713 if (tableinfo.checks)
1715 printfPQExpBuffer(&buf,
1716 "SELECT r.conname, "
1717 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
1718 "FROM pg_catalog.pg_constraint r\n"
1719 "WHERE r.conrelid = '%s' AND r.contype = 'c'\nORDER BY 1",
1721 result = PSQLexec(buf.data, false);
1725 tuples = PQntuples(result);
1729 printTableAddFooter(&cont, _("Check constraints:"));
1730 for (i = 0; i < tuples; i++)
1732 /* untranslated contraint name and def */
1733 printfPQExpBuffer(&buf, " \"%s\" %s",
1734 PQgetvalue(result, i, 0),
1735 PQgetvalue(result, i, 1));
1737 printTableAddFooter(&cont, buf.data);
1743 /* print foreign-key constraints (there are none if no triggers) */
1744 if (tableinfo.hastriggers)
1746 printfPQExpBuffer(&buf,
1748 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef\n");
1749 if (pset.sversion >= 90100)
1750 appendPQExpBuffer(&buf, " ,convalidated\n");
1751 appendPQExpBuffer(&buf, "FROM pg_catalog.pg_constraint r\n"
1752 "WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1",
1754 result = PSQLexec(buf.data, false);
1758 tuples = PQntuples(result);
1762 printTableAddFooter(&cont, _("Foreign-key constraints:"));
1763 for (i = 0; i < tuples; i++)
1765 /* untranslated constraint name and def */
1766 printfPQExpBuffer(&buf, " \"%s\" %s",
1767 PQgetvalue(result, i, 0),
1768 PQgetvalue(result, i, 1));
1770 if (pset.sversion >= 90100 && strcmp(PQgetvalue(result, i, 2), "f") == 0)
1771 appendPQExpBuffer(&buf, " NOT VALID");
1773 printTableAddFooter(&cont, buf.data);
1779 /* print incoming foreign-key references (none if no triggers) */
1780 if (tableinfo.hastriggers)
1782 printfPQExpBuffer(&buf,
1783 "SELECT conname, conrelid::pg_catalog.regclass,\n"
1784 " pg_catalog.pg_get_constraintdef(c.oid, true) as condef\n"
1785 "FROM pg_catalog.pg_constraint c\n"
1786 "WHERE c.confrelid = '%s' AND c.contype = 'f' ORDER BY 1",
1788 result = PSQLexec(buf.data, false);
1792 tuples = PQntuples(result);
1796 printTableAddFooter(&cont, _("Referenced by:"));
1797 for (i = 0; i < tuples; i++)
1799 printfPQExpBuffer(&buf, " TABLE \"%s\" CONSTRAINT \"%s\" %s",
1800 PQgetvalue(result, i, 1),
1801 PQgetvalue(result, i, 0),
1802 PQgetvalue(result, i, 2));
1804 printTableAddFooter(&cont, buf.data);
1811 if (tableinfo.hasrules)
1813 if (pset.sversion >= 80300)
1815 printfPQExpBuffer(&buf,
1816 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
1818 "FROM pg_catalog.pg_rewrite r\n"
1819 "WHERE r.ev_class = '%s' ORDER BY 1",
1824 printfPQExpBuffer(&buf,
1825 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
1826 "'O'::char AS ev_enabled\n"
1827 "FROM pg_catalog.pg_rewrite r\n"
1828 "WHERE r.ev_class = '%s' ORDER BY 1",
1831 result = PSQLexec(buf.data, false);
1835 tuples = PQntuples(result);
1842 for (category = 0; category < 4; category++)
1844 have_heading = false;
1846 for (i = 0; i < tuples; i++)
1848 const char *ruledef;
1849 bool list_rule = false;
1854 if (*PQgetvalue(result, i, 2) == 'O')
1858 if (*PQgetvalue(result, i, 2) == 'D')
1862 if (*PQgetvalue(result, i, 2) == 'A')
1866 if (*PQgetvalue(result, i, 2) == 'R')
1878 printfPQExpBuffer(&buf, _("Rules:"));
1881 printfPQExpBuffer(&buf, _("Disabled rules:"));
1884 printfPQExpBuffer(&buf, _("Rules firing always:"));
1887 printfPQExpBuffer(&buf, _("Rules firing on replica only:"));
1890 printTableAddFooter(&cont, buf.data);
1891 have_heading = true;
1894 /* Everything after "CREATE RULE" is echoed verbatim */
1895 ruledef = PQgetvalue(result, i, 1);
1897 printfPQExpBuffer(&buf, " %s", ruledef);
1898 printTableAddFooter(&cont, buf.data);
1907 * Print triggers next, if any (but only user-defined triggers). This
1908 * could apply to either a table or a view.
1910 if (tableinfo.hastriggers)
1915 printfPQExpBuffer(&buf,
1917 "pg_catalog.pg_get_triggerdef(t.oid%s), "
1919 "FROM pg_catalog.pg_trigger t\n"
1920 "WHERE t.tgrelid = '%s' AND ",
1921 (pset.sversion >= 90000 ? ", true" : ""),
1923 if (pset.sversion >= 90000)
1924 appendPQExpBuffer(&buf, "NOT t.tgisinternal");
1925 else if (pset.sversion >= 80300)
1926 appendPQExpBuffer(&buf, "t.tgconstraint = 0");
1928 appendPQExpBuffer(&buf,
1929 "(NOT tgisconstraint "
1931 " (SELECT 1 FROM pg_catalog.pg_depend d "
1932 " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
1933 " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))");
1934 appendPQExpBuffer(&buf, "\nORDER BY 1");
1936 result = PSQLexec(buf.data, false);
1940 tuples = PQntuples(result);
1948 * split the output into 4 different categories. Enabled
1949 * triggers, disabled triggers and the two special ALWAYS and
1950 * REPLICA configurations.
1952 for (category = 0; category < 4; category++)
1954 have_heading = false;
1955 for (i = 0; i < tuples; i++)
1959 const char *usingpos;
1960 const char *tgenabled;
1963 * Check if this trigger falls into the current
1966 tgenabled = PQgetvalue(result, i, 2);
1967 list_trigger = false;
1971 if (*tgenabled == 'O' || *tgenabled == 't')
1972 list_trigger = true;
1975 if (*tgenabled == 'D' || *tgenabled == 'f')
1976 list_trigger = true;
1979 if (*tgenabled == 'A')
1980 list_trigger = true;
1983 if (*tgenabled == 'R')
1984 list_trigger = true;
1987 if (list_trigger == false)
1990 /* Print the category heading once */
1991 if (have_heading == false)
1996 printfPQExpBuffer(&buf, _("Triggers:"));
1999 printfPQExpBuffer(&buf, _("Disabled triggers:"));
2002 printfPQExpBuffer(&buf, _("Triggers firing always:"));
2005 printfPQExpBuffer(&buf, _("Triggers firing on replica only:"));
2009 printTableAddFooter(&cont, buf.data);
2010 have_heading = true;
2013 /* Everything after "TRIGGER" is echoed verbatim */
2014 tgdef = PQgetvalue(result, i, 1);
2015 usingpos = strstr(tgdef, " TRIGGER ");
2017 tgdef = usingpos + 9;
2019 printfPQExpBuffer(&buf, " %s", tgdef);
2020 printTableAddFooter(&cont, buf.data);
2028 * Finish printing the footer information about a table.
2030 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'f')
2035 /* print foreign server name */
2036 if (tableinfo.relkind == 'f')
2038 /* Footer information about foreign table */
2039 printfPQExpBuffer(&buf,
2040 "SELECT s.srvname\n"
2041 "FROM pg_catalog.pg_foreign_table f,\n"
2042 " pg_catalog.pg_foreign_server s\n"
2043 "WHERE f.ftrelid = %s AND s.oid = f.ftserver",
2045 result = PSQLexec(buf.data, false);
2048 else if (PQntuples(result) != 1)
2054 printfPQExpBuffer(&buf, "Server: %s",
2055 PQgetvalue(result, 0, 0));
2056 printTableAddFooter(&cont, buf.data);
2060 /* print inherited tables */
2061 printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno", oid);
2063 result = PSQLexec(buf.data, false);
2067 tuples = PQntuples(result);
2069 for (i = 0; i < tuples; i++)
2071 const char *s = _("Inherits");
2074 printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0));
2076 printfPQExpBuffer(&buf, "%*s %s", (int) strlen(s), "", PQgetvalue(result, i, 0));
2078 appendPQExpBuffer(&buf, ",");
2080 printTableAddFooter(&cont, buf.data);
2084 /* print child tables */
2085 if (pset.sversion >= 80300)
2086 printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '%s' ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;", oid);
2088 printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '%s' ORDER BY c.relname;", oid);
2090 result = PSQLexec(buf.data, false);
2094 tuples = PQntuples(result);
2098 /* print the number of child tables, if any */
2101 printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples);
2102 printTableAddFooter(&cont, buf.data);
2107 /* display the list of child tables */
2108 const char *ct = _("Child tables");
2110 for (i = 0; i < tuples; i++)
2113 printfPQExpBuffer(&buf, "%s: %s",
2114 ct, PQgetvalue(result, i, 0));
2116 printfPQExpBuffer(&buf, "%*s %s",
2117 (int) strlen(ct), "",
2118 PQgetvalue(result, i, 0));
2120 appendPQExpBuffer(&buf, ",");
2122 printTableAddFooter(&cont, buf.data);
2128 if (tableinfo.reloftype)
2130 printfPQExpBuffer(&buf, _("Typed table of type: %s"), tableinfo.reloftype);
2131 printTableAddFooter(&cont, buf.data);
2134 /* OIDs and options */
2137 const char *s = _("Has OIDs");
2139 printfPQExpBuffer(&buf, "%s: %s", s,
2140 (tableinfo.hasoids ? _("yes") : _("no")));
2141 printTableAddFooter(&cont, buf.data);
2143 /* print reloptions */
2144 if (pset.sversion >= 80200)
2146 if (tableinfo.reloptions && tableinfo.reloptions[0] != '\0')
2148 const char *t = _("Options");
2150 printfPQExpBuffer(&buf, "%s: %s", t,
2151 tableinfo.reloptions);
2152 printTableAddFooter(&cont, buf.data);
2157 add_tablespace_footer(&cont, tableinfo.relkind, tableinfo.tablespace,
2161 printTable(&cont, pset.queryFout, pset.logfile);
2162 printTableCleanup(&cont);
2169 if (printTableInitialized)
2170 printTableCleanup(&cont);
2171 termPQExpBuffer(&buf);
2172 termPQExpBuffer(&title);
2173 termPQExpBuffer(&tmpbuf);
2177 for (ptr = seq_values; *ptr; ptr++)
2184 for (ptr = modifiers; *ptr; ptr++)
2199 * Add a tablespace description to a footer. If 'newline' is true, it is added
2200 * in a new line; otherwise it's appended to the current value of the last
2204 add_tablespace_footer(printTableContent *const cont, char relkind,
2205 Oid tablespace, const bool newline)
2207 /* relkinds for which we support tablespaces */
2208 if (relkind == 'r' || relkind == 'i')
2211 * We ignore the database default tablespace so that users not using
2212 * tablespaces don't need to know about them. This case also covers
2213 * pre-8.0 servers, for which tablespace will always be 0.
2215 if (tablespace != 0)
2217 PGresult *result = NULL;
2218 PQExpBufferData buf;
2220 initPQExpBuffer(&buf);
2221 printfPQExpBuffer(&buf,
2222 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
2223 "WHERE oid = '%u'", tablespace);
2224 result = PSQLexec(buf.data, false);
2227 /* Should always be the case, but.... */
2228 if (PQntuples(result) > 0)
2232 /* Add the tablespace as a new footer */
2233 printfPQExpBuffer(&buf, _("Tablespace: \"%s\""),
2234 PQgetvalue(result, 0, 0));
2235 printTableAddFooter(cont, buf.data);
2239 /* Append the tablespace to the latest footer */
2240 printfPQExpBuffer(&buf, "%s", cont->footer->data);
2243 * translator: before this string there's an index
2244 * description like '"foo_pkey" PRIMARY KEY, btree (a)'
2246 appendPQExpBuffer(&buf, _(", tablespace \"%s\""),
2247 PQgetvalue(result, 0, 0));
2248 printTableSetFooter(cont, buf.data);
2252 termPQExpBuffer(&buf);
2260 * Describes roles. Any schema portion of the pattern is ignored.
2263 describeRoles(const char *pattern, bool verbose)
2265 PQExpBufferData buf;
2267 printTableContent cont;
2268 printTableOpt myopt = pset.popt.topt;
2273 const char align = 'l';
2276 initPQExpBuffer(&buf);
2278 if (pset.sversion >= 80100)
2280 printfPQExpBuffer(&buf,
2281 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
2282 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
2283 " r.rolconnlimit,\n"
2284 " ARRAY(SELECT b.rolname\n"
2285 " FROM pg_catalog.pg_auth_members m\n"
2286 " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
2287 " WHERE m.member = r.oid) as memberof");
2289 if (verbose && pset.sversion >= 80200)
2291 appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
2294 if (pset.sversion >= 90100)
2296 appendPQExpBufferStr(&buf,"\n, r.rolreplication");
2299 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
2301 processSQLNamePattern(pset.db, &buf, pattern, false, false,
2302 NULL, "r.rolname", NULL, NULL);
2306 printfPQExpBuffer(&buf,
2307 "SELECT u.usename AS rolname,\n"
2308 " u.usesuper AS rolsuper,\n"
2309 " true AS rolinherit, false AS rolcreaterole,\n"
2310 " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
2311 " -1 AS rolconnlimit,\n"
2312 " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
2313 "\nFROM pg_catalog.pg_user u\n");
2315 processSQLNamePattern(pset.db, &buf, pattern, false, false,
2316 NULL, "u.usename", NULL, NULL);
2319 appendPQExpBuffer(&buf, "ORDER BY 1;");
2321 res = PSQLexec(buf.data, false);
2325 nrows = PQntuples(res);
2326 attr = pg_malloc_zero((nrows + 1) * sizeof(*attr));
2328 printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
2330 printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
2331 printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
2332 printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
2334 if (verbose && pset.sversion >= 80200)
2335 printTableAddHeader(&cont, gettext_noop("Description"), true, align);
2337 for (i = 0; i < nrows; i++)
2339 printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
2341 resetPQExpBuffer(&buf);
2342 if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
2343 add_role_attribute(&buf, _("Superuser"));
2345 if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
2346 add_role_attribute(&buf, _("No inheritance"));
2348 if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
2349 add_role_attribute(&buf, _("Create role"));
2351 if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
2352 add_role_attribute(&buf, _("Create DB"));
2354 if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
2355 add_role_attribute(&buf, _("Cannot login"));
2357 if (pset.sversion >= 90100)
2358 if (strcmp(PQgetvalue(res, i, (verbose ? 9 : 8)), "t") == 0)
2359 add_role_attribute(&buf, _("Replication"));
2361 conns = atoi(PQgetvalue(res, i, 6));
2365 appendPQExpBufferStr(&buf, "\n");
2368 appendPQExpBuffer(&buf, _("No connections"));
2370 appendPQExpBuffer(&buf, ngettext("%d connection",
2376 attr[i] = pg_strdup(buf.data);
2378 printTableAddCell(&cont, attr[i], false, false);
2380 printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
2382 if (verbose && pset.sversion >= 80200)
2383 printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
2385 termPQExpBuffer(&buf);
2387 printTable(&cont, pset.queryFout, pset.logfile);
2388 printTableCleanup(&cont);
2390 for (i = 0; i < nrows; i++)
2399 add_role_attribute(PQExpBuffer buf, const char *const str)
2402 appendPQExpBufferStr(buf, ", ");
2404 appendPQExpBufferStr(buf, str);
2411 listDbRoleSettings(const char *pattern, const char *pattern2)
2413 PQExpBufferData buf;
2415 printQueryOpt myopt = pset.popt;
2417 initPQExpBuffer(&buf);
2419 if (pset.sversion >= 90000)
2423 printfPQExpBuffer(&buf, "SELECT rolname AS role, datname AS database,\n"
2424 "pg_catalog.array_to_string(setconfig, E'\\n') AS settings\n"
2425 "FROM pg_db_role_setting AS s\n"
2426 "LEFT JOIN pg_database ON pg_database.oid = setdatabase\n"
2427 "LEFT JOIN pg_roles ON pg_roles.oid = setrole\n");
2428 havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
2429 NULL, "pg_roles.rolname", NULL, NULL);
2430 processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
2431 NULL, "pg_database.datname", NULL, NULL);
2432 appendPQExpBufferStr(&buf, "ORDER BY role, database");
2436 fprintf(pset.queryFout,
2437 _("No per-database role settings support in this server version.\n"));
2441 res = PSQLexec(buf.data, false);
2445 if (PQntuples(res) == 0 && !pset.quiet)
2448 fprintf(pset.queryFout, _("No matching settings found.\n"));
2450 fprintf(pset.queryFout, _("No settings found.\n"));
2454 myopt.nullPrint = NULL;
2455 myopt.title = _("List of settings");
2456 myopt.translate_header = true;
2458 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2462 resetPQExpBuffer(&buf);
2470 * handler for \dt, \di, etc.
2472 * tabtypes is an array of characters, specifying what info is desired:
2477 * E - foreign table (Note: different from 'f', the relkind value)
2478 * (any order of the above is fine)
2479 * If tabtypes is empty, we default to \dtvsE.
2482 listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
2484 bool showTables = strchr(tabtypes, 't') != NULL;
2485 bool showIndexes = strchr(tabtypes, 'i') != NULL;
2486 bool showViews = strchr(tabtypes, 'v') != NULL;
2487 bool showSeq = strchr(tabtypes, 's') != NULL;
2488 bool showForeign = strchr(tabtypes, 'E') != NULL;
2490 PQExpBufferData buf;
2492 printQueryOpt myopt = pset.popt;
2493 static const bool translate_columns[] = {false, false, true, false, false, false, false};
2495 if (!(showTables || showIndexes || showViews || showSeq || showForeign))
2496 showTables = showViews = showSeq = showForeign = true;
2498 initPQExpBuffer(&buf);
2501 * Note: as of Pg 8.2, we no longer use relkind 's', but we keep it here
2502 * for backwards compatibility.
2504 printfPQExpBuffer(&buf,
2505 "SELECT n.nspname as \"%s\",\n"
2506 " c.relname as \"%s\",\n"
2507 " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' WHEN 's' THEN '%s' WHEN 'f' THEN '%s' END as \"%s\",\n"
2508 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
2509 gettext_noop("Schema"),
2510 gettext_noop("Name"),
2511 gettext_noop("table"),
2512 gettext_noop("view"),
2513 gettext_noop("index"),
2514 gettext_noop("sequence"),
2515 gettext_noop("special"),
2516 gettext_noop("foreign table"),
2517 gettext_noop("Type"),
2518 gettext_noop("Owner"));
2521 appendPQExpBuffer(&buf,
2522 ",\n c2.relname as \"%s\"",
2523 gettext_noop("Table"));
2525 if (verbose && pset.sversion >= 80100)
2526 appendPQExpBuffer(&buf,
2527 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
2528 gettext_noop("Size"));
2530 appendPQExpBuffer(&buf,
2531 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
2532 gettext_noop("Description"));
2534 appendPQExpBuffer(&buf,
2535 "\nFROM pg_catalog.pg_class c"
2536 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
2538 appendPQExpBuffer(&buf,
2539 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
2540 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
2542 appendPQExpBuffer(&buf, "\nWHERE c.relkind IN (");
2544 appendPQExpBuffer(&buf, "'r',");
2546 appendPQExpBuffer(&buf, "'v',");
2548 appendPQExpBuffer(&buf, "'i',");
2550 appendPQExpBuffer(&buf, "'S',");
2551 if (showSystem || pattern)
2552 appendPQExpBuffer(&buf, "'s',"); /* was RELKIND_SPECIAL in <=
2555 appendPQExpBuffer(&buf, "'f',");
2557 appendPQExpBuffer(&buf, "''"); /* dummy */
2558 appendPQExpBuffer(&buf, ")\n");
2560 if (!showSystem && !pattern)
2561 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
2562 " AND n.nspname <> 'information_schema'\n");
2565 * TOAST objects are suppressed unconditionally. Since we don't provide
2566 * any way to select relkind 't' above, we would never show toast tables
2567 * in any case; it seems a bit confusing to allow their indexes to be
2568 * shown. Use plain \d if you really need to look at a TOAST table/index.
2570 appendPQExpBuffer(&buf, " AND n.nspname !~ '^pg_toast'\n");
2572 processSQLNamePattern(pset.db, &buf, pattern, true, false,
2573 "n.nspname", "c.relname", NULL,
2574 "pg_catalog.pg_table_is_visible(c.oid)");
2576 appendPQExpBuffer(&buf, "ORDER BY 1,2;");
2578 res = PSQLexec(buf.data, false);
2579 termPQExpBuffer(&buf);
2583 if (PQntuples(res) == 0 && !pset.quiet)
2586 fprintf(pset.queryFout, _("No matching relations found.\n"));
2588 fprintf(pset.queryFout, _("No relations found.\n"));
2592 myopt.nullPrint = NULL;
2593 myopt.title = _("List of relations");
2594 myopt.translate_header = true;
2595 myopt.translate_columns = translate_columns;
2597 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2608 * Describes languages.
2611 listLanguages(const char *pattern, bool verbose, bool showSystem)
2613 PQExpBufferData buf;
2615 printQueryOpt myopt = pset.popt;
2617 initPQExpBuffer(&buf);
2619 printfPQExpBuffer(&buf,
2620 "SELECT l.lanname AS \"%s\",\n",
2621 gettext_noop("Name"));
2622 if (pset.sversion >= 80300)
2623 appendPQExpBuffer(&buf,
2624 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
2625 gettext_noop("Owner"));
2627 appendPQExpBuffer(&buf,
2628 " l.lanpltrusted AS \"%s\"",
2629 gettext_noop("Trusted"));
2633 appendPQExpBuffer(&buf,
2634 ",\n NOT l.lanispl AS \"%s\",\n"
2635 " l.lanplcallfoid::regprocedure AS \"%s\",\n"
2636 " l.lanvalidator::regprocedure AS \"%s\",\n ",
2637 gettext_noop("Internal Language"),
2638 gettext_noop("Call Handler"),
2639 gettext_noop("Validator"));
2640 if (pset.sversion >= 90000)
2641 appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n ",
2642 gettext_noop("Inline Handler"));
2643 printACLColumn(&buf, "l.lanacl");
2646 appendPQExpBuffer(&buf,
2647 "\nFROM pg_catalog.pg_language l\n");
2649 processSQLNamePattern(pset.db, &buf, pattern, false, false,
2650 NULL, "l.lanname", NULL, NULL);
2652 if (!showSystem && !pattern)
2653 appendPQExpBuffer(&buf, "WHERE lanplcallfoid != 0\n");
2655 appendPQExpBuffer(&buf, "ORDER BY 1;");
2657 res = PSQLexec(buf.data, false);
2658 termPQExpBuffer(&buf);
2662 myopt.nullPrint = NULL;
2663 myopt.title = _("List of languages");
2664 myopt.translate_header = true;
2666 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2676 * Describes domains.
2679 listDomains(const char *pattern, bool showSystem)
2681 PQExpBufferData buf;
2683 printQueryOpt myopt = pset.popt;
2685 initPQExpBuffer(&buf);
2687 printfPQExpBuffer(&buf,
2688 "SELECT n.nspname as \"%s\",\n"
2689 " t.typname as \"%s\",\n"
2690 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
2691 " CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
2692 " WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
2693 " WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
2696 " pg_catalog.array_to_string(ARRAY(\n"
2697 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
2698 " ), ' ') as \"%s\"\n"
2699 "FROM pg_catalog.pg_type t\n"
2700 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
2701 "WHERE t.typtype = 'd'\n",
2702 gettext_noop("Schema"),
2703 gettext_noop("Name"),
2704 gettext_noop("Type"),
2705 gettext_noop("Modifier"),
2706 gettext_noop("Check"));
2708 if (!showSystem && !pattern)
2709 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
2710 " AND n.nspname <> 'information_schema'\n");
2712 processSQLNamePattern(pset.db, &buf, pattern, true, false,
2713 "n.nspname", "t.typname", NULL,
2714 "pg_catalog.pg_type_is_visible(t.oid)");
2716 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
2718 res = PSQLexec(buf.data, false);
2719 termPQExpBuffer(&buf);
2723 myopt.nullPrint = NULL;
2724 myopt.title = _("List of domains");
2725 myopt.translate_header = true;
2727 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2736 * Describes conversions.
2739 listConversions(const char *pattern, bool showSystem)
2741 PQExpBufferData buf;
2743 printQueryOpt myopt = pset.popt;
2744 static const bool translate_columns[] = {false, false, false, false, true};
2746 initPQExpBuffer(&buf);
2748 printfPQExpBuffer(&buf,
2749 "SELECT n.nspname AS \"%s\",\n"
2750 " c.conname AS \"%s\",\n"
2751 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
2752 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
2753 " CASE WHEN c.condefault THEN '%s'\n"
2754 " ELSE '%s' END AS \"%s\"\n"
2755 "FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
2756 "WHERE n.oid = c.connamespace\n",
2757 gettext_noop("Schema"),
2758 gettext_noop("Name"),
2759 gettext_noop("Source"),
2760 gettext_noop("Destination"),
2761 gettext_noop("yes"), gettext_noop("no"),
2762 gettext_noop("Default?"));
2764 if (!showSystem && !pattern)
2765 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
2766 " AND n.nspname <> 'information_schema'\n");
2768 processSQLNamePattern(pset.db, &buf, pattern, true, false,
2769 "n.nspname", "c.conname", NULL,
2770 "pg_catalog.pg_conversion_is_visible(c.oid)");
2772 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
2774 res = PSQLexec(buf.data, false);
2775 termPQExpBuffer(&buf);
2779 myopt.nullPrint = NULL;
2780 myopt.title = _("List of conversions");
2781 myopt.translate_header = true;
2782 myopt.translate_columns = translate_columns;
2784 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2796 listCasts(const char *pattern)
2798 PQExpBufferData buf;
2800 printQueryOpt myopt = pset.popt;
2801 static const bool translate_columns[] = {false, false, false, true};
2803 initPQExpBuffer(&buf);
2806 * We need a left join to pg_proc for binary casts; the others are just
2807 * paranoia. Also note that we don't attempt to localize '(binary
2808 * coercible)', because there's too much risk of gettext translating a
2809 * function name that happens to match some string in the PO database.
2811 printfPQExpBuffer(&buf,
2812 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
2813 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
2814 " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
2817 " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
2818 " WHEN c.castcontext = 'a' THEN '%s'\n"
2821 "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
2822 " ON c.castfunc = p.oid\n"
2823 " LEFT JOIN pg_catalog.pg_type ts\n"
2824 " ON c.castsource = ts.oid\n"
2825 " LEFT JOIN pg_catalog.pg_namespace ns\n"
2826 " ON ns.oid = ts.typnamespace\n"
2827 " LEFT JOIN pg_catalog.pg_type tt\n"
2828 " ON c.casttarget = tt.oid\n"
2829 " LEFT JOIN pg_catalog.pg_namespace nt\n"
2830 " ON nt.oid = tt.typnamespace\n"
2832 gettext_noop("Source type"),
2833 gettext_noop("Target type"),
2834 gettext_noop("Function"),
2835 gettext_noop("no"), gettext_noop("in assignment"), gettext_noop("yes"),
2836 gettext_noop("Implicit?"));
2839 * Match name pattern against either internal or external name of either
2840 * castsource or casttarget
2842 processSQLNamePattern(pset.db, &buf, pattern, true, false,
2843 "ns.nspname", "ts.typname",
2844 "pg_catalog.format_type(ts.oid, NULL)",
2845 "pg_catalog.pg_type_is_visible(ts.oid)");
2847 appendPQExpBuffer(&buf, ") OR (true");
2849 processSQLNamePattern(pset.db, &buf, pattern, true, false,
2850 "nt.nspname", "tt.typname",
2851 "pg_catalog.format_type(tt.oid, NULL)",
2852 "pg_catalog.pg_type_is_visible(tt.oid)");
2854 appendPQExpBuffer(&buf, ")\nORDER BY 1, 2;");
2856 res = PSQLexec(buf.data, false);
2857 termPQExpBuffer(&buf);
2861 myopt.nullPrint = NULL;
2862 myopt.title = _("List of casts");
2863 myopt.translate_header = true;
2864 myopt.translate_columns = translate_columns;
2866 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2875 * Describes collations
2878 listCollations(const char *pattern, bool verbose, bool showSystem)
2880 PQExpBufferData buf;
2882 printQueryOpt myopt = pset.popt;
2883 static const bool translate_columns[] = {false, false, false, false, false};
2885 initPQExpBuffer(&buf);
2887 printfPQExpBuffer(&buf,
2888 "SELECT n.nspname AS \"%s\",\n"
2889 " c.collname AS \"%s\",\n"
2890 " c.collcollate AS \"%s\",\n"
2891 " c.collctype AS \"%s\"",
2892 gettext_noop("Schema"),
2893 gettext_noop("Name"),
2894 gettext_noop("Collate"),
2895 gettext_noop("Ctype"));
2898 appendPQExpBuffer(&buf,
2899 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
2900 gettext_noop("Description"));
2902 appendPQExpBuffer(&buf,
2903 "FROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
2904 "WHERE n.oid = c.collnamespace\n");
2906 if (!showSystem && !pattern)
2907 appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
2908 " AND n.nspname <> 'information_schema'\n");
2910 processSQLNamePattern(pset.db, &buf, pattern, true, false,
2911 "n.nspname", "c.collname", NULL,
2912 "pg_catalog.pg_collation_is_visible(c.oid)");
2914 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
2916 res = PSQLexec(buf.data, false);
2917 termPQExpBuffer(&buf);
2921 myopt.nullPrint = NULL;
2922 myopt.title = _("List of collations");
2923 myopt.translate_header = true;
2924 myopt.translate_columns = translate_columns;
2926 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2935 * Describes schemas (namespaces)
2938 listSchemas(const char *pattern, bool verbose, bool showSystem)
2940 PQExpBufferData buf;
2942 printQueryOpt myopt = pset.popt;
2944 initPQExpBuffer(&buf);
2945 printfPQExpBuffer(&buf,
2946 "SELECT n.nspname AS \"%s\",\n"
2947 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
2948 gettext_noop("Name"),
2949 gettext_noop("Owner"));
2953 appendPQExpBuffer(&buf, ",\n ");
2954 printACLColumn(&buf, "n.nspacl");
2955 appendPQExpBuffer(&buf,
2956 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
2957 gettext_noop("Description"));
2960 appendPQExpBuffer(&buf,
2961 "\nFROM pg_catalog.pg_namespace n\n");
2963 if (!showSystem && !pattern)
2964 appendPQExpBuffer(&buf,
2965 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
2967 processSQLNamePattern(pset.db, &buf, pattern,
2968 !showSystem && !pattern, false,
2969 NULL, "n.nspname", NULL,
2972 appendPQExpBuffer(&buf, "ORDER BY 1;");
2974 res = PSQLexec(buf.data, false);
2975 termPQExpBuffer(&buf);
2979 myopt.nullPrint = NULL;
2980 myopt.title = _("List of schemas");
2981 myopt.translate_header = true;
2983 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2992 * list text search parsers
2995 listTSParsers(const char *pattern, bool verbose)
2997 PQExpBufferData buf;
2999 printQueryOpt myopt = pset.popt;
3001 if (pset.sversion < 80300)
3003 fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"),
3004 pset.sversion / 10000, (pset.sversion / 100) % 100);
3009 return listTSParsersVerbose(pattern);
3011 initPQExpBuffer(&buf);
3013 printfPQExpBuffer(&buf,
3015 " n.nspname as \"%s\",\n"
3016 " p.prsname as \"%s\",\n"
3017 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
3018 "FROM pg_catalog.pg_ts_parser p \n"
3019 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
3020 gettext_noop("Schema"),
3021 gettext_noop("Name"),
3022 gettext_noop("Description")
3025 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3026 "n.nspname", "p.prsname", NULL,
3027 "pg_catalog.pg_ts_parser_is_visible(p.oid)");
3029 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
3031 res = PSQLexec(buf.data, false);
3032 termPQExpBuffer(&buf);
3036 myopt.nullPrint = NULL;
3037 myopt.title = _("List of text search parsers");
3038 myopt.translate_header = true;
3040 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3047 * full description of parsers
3050 listTSParsersVerbose(const char *pattern)
3052 PQExpBufferData buf;
3056 initPQExpBuffer(&buf);
3058 printfPQExpBuffer(&buf,
3062 "FROM pg_catalog.pg_ts_parser p\n"
3063 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
3066 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3067 "n.nspname", "p.prsname", NULL,
3068 "pg_catalog.pg_ts_parser_is_visible(p.oid)");
3070 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
3072 res = PSQLexec(buf.data, false);
3073 termPQExpBuffer(&buf);
3077 if (PQntuples(res) == 0)
3080 fprintf(stderr, _("Did not find any text search parser named \"%s\".\n"),
3086 for (i = 0; i < PQntuples(res); i++)
3089 const char *nspname = NULL;
3090 const char *prsname;
3092 oid = PQgetvalue(res, i, 0);
3093 if (!PQgetisnull(res, i, 1))
3094 nspname = PQgetvalue(res, i, 1);
3095 prsname = PQgetvalue(res, i, 2);
3097 if (!describeOneTSParser(oid, nspname, prsname))
3115 describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
3117 PQExpBufferData buf;
3120 printQueryOpt myopt = pset.popt;
3121 static const bool translate_columns[] = {true, false, false};
3123 initPQExpBuffer(&buf);
3125 printfPQExpBuffer(&buf,
3126 "SELECT '%s' AS \"%s\", \n"
3127 " p.prsstart::pg_catalog.regproc AS \"%s\", \n"
3128 " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\" \n"
3129 " FROM pg_catalog.pg_ts_parser p \n"
3130 " WHERE p.oid = '%s' \n"
3133 " p.prstoken::pg_catalog.regproc, \n"
3134 " pg_catalog.obj_description(p.prstoken, 'pg_proc') \n"
3135 " FROM pg_catalog.pg_ts_parser p \n"
3136 " WHERE p.oid = '%s' \n"
3139 " p.prsend::pg_catalog.regproc, \n"
3140 " pg_catalog.obj_description(p.prsend, 'pg_proc') \n"
3141 " FROM pg_catalog.pg_ts_parser p \n"
3142 " WHERE p.oid = '%s' \n"
3145 " p.prsheadline::pg_catalog.regproc, \n"
3146 " pg_catalog.obj_description(p.prsheadline, 'pg_proc') \n"
3147 " FROM pg_catalog.pg_ts_parser p \n"
3148 " WHERE p.oid = '%s' \n"
3151 " p.prslextype::pg_catalog.regproc, \n"
3152 " pg_catalog.obj_description(p.prslextype, 'pg_proc') \n"
3153 " FROM pg_catalog.pg_ts_parser p \n"
3154 " WHERE p.oid = '%s' \n",
3155 gettext_noop("Start parse"),
3156 gettext_noop("Method"),
3157 gettext_noop("Function"),
3158 gettext_noop("Description"),
3160 gettext_noop("Get next token"),
3162 gettext_noop("End parse"),
3164 gettext_noop("Get headline"),
3166 gettext_noop("Get token types"),
3169 res = PSQLexec(buf.data, false);
3170 termPQExpBuffer(&buf);
3174 myopt.nullPrint = NULL;
3176 sprintf(title, _("Text search parser \"%s.%s\""), nspname, prsname);
3178 sprintf(title, _("Text search parser \"%s\""), prsname);
3179 myopt.title = title;
3180 myopt.footers = NULL;
3181 myopt.default_footer = false;
3182 myopt.translate_header = true;
3183 myopt.translate_columns = translate_columns;
3185 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3189 initPQExpBuffer(&buf);
3191 printfPQExpBuffer(&buf,
3192 "SELECT t.alias as \"%s\", \n"
3193 " t.description as \"%s\" \n"
3194 "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t \n"
3196 gettext_noop("Token name"),
3197 gettext_noop("Description"),
3200 res = PSQLexec(buf.data, false);
3201 termPQExpBuffer(&buf);
3205 myopt.nullPrint = NULL;
3207 sprintf(title, _("Token types for parser \"%s.%s\""), nspname, prsname);
3209 sprintf(title, _("Token types for parser \"%s\""), prsname);
3210 myopt.title = title;
3211 myopt.footers = NULL;
3212 myopt.default_footer = true;
3213 myopt.translate_header = true;
3214 myopt.translate_columns = NULL;
3216 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3225 * list text search dictionaries
3228 listTSDictionaries(const char *pattern, bool verbose)
3230 PQExpBufferData buf;
3232 printQueryOpt myopt = pset.popt;
3234 if (pset.sversion < 80300)
3236 fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"),
3237 pset.sversion / 10000, (pset.sversion / 100) % 100);
3241 initPQExpBuffer(&buf);
3243 printfPQExpBuffer(&buf,
3245 " n.nspname as \"%s\",\n"
3246 " d.dictname as \"%s\",\n",
3247 gettext_noop("Schema"),
3248 gettext_noop("Name"));
3252 appendPQExpBuffer(&buf,
3253 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM \n"
3254 " pg_catalog.pg_ts_template t \n"
3255 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace \n"
3256 " WHERE d.dicttemplate = t.oid ) AS \"%s\", \n"
3257 " d.dictinitoption as \"%s\", \n",
3258 gettext_noop("Template"),
3259 gettext_noop("Init options"));
3262 appendPQExpBuffer(&buf,
3263 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
3264 gettext_noop("Description"));
3266 appendPQExpBuffer(&buf, "FROM pg_catalog.pg_ts_dict d\n"
3267 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
3269 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3270 "n.nspname", "d.dictname", NULL,
3271 "pg_catalog.pg_ts_dict_is_visible(d.oid)");
3273 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
3275 res = PSQLexec(buf.data, false);
3276 termPQExpBuffer(&buf);
3280 myopt.nullPrint = NULL;
3281 myopt.title = _("List of text search dictionaries");
3282 myopt.translate_header = true;
3284 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3293 * list text search templates
3296 listTSTemplates(const char *pattern, bool verbose)
3298 PQExpBufferData buf;
3300 printQueryOpt myopt = pset.popt;
3302 if (pset.sversion < 80300)
3304 fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"),
3305 pset.sversion / 10000, (pset.sversion / 100) % 100);
3309 initPQExpBuffer(&buf);
3312 printfPQExpBuffer(&buf,
3314 " n.nspname AS \"%s\",\n"
3315 " t.tmplname AS \"%s\",\n"
3316 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
3317 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
3318 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
3319 gettext_noop("Schema"),
3320 gettext_noop("Name"),
3321 gettext_noop("Init"),
3322 gettext_noop("Lexize"),
3323 gettext_noop("Description"));
3325 printfPQExpBuffer(&buf,
3327 " n.nspname AS \"%s\",\n"
3328 " t.tmplname AS \"%s\",\n"
3329 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
3330 gettext_noop("Schema"),
3331 gettext_noop("Name"),
3332 gettext_noop("Description"));
3334 appendPQExpBuffer(&buf, "FROM pg_catalog.pg_ts_template t\n"
3335 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
3337 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3338 "n.nspname", "t.tmplname", NULL,
3339 "pg_catalog.pg_ts_template_is_visible(t.oid)");
3341 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
3343 res = PSQLexec(buf.data, false);
3344 termPQExpBuffer(&buf);
3348 myopt.nullPrint = NULL;
3349 myopt.title = _("List of text search templates");
3350 myopt.translate_header = true;
3352 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3361 * list text search configurations
3364 listTSConfigs(const char *pattern, bool verbose)
3366 PQExpBufferData buf;
3368 printQueryOpt myopt = pset.popt;
3370 if (pset.sversion < 80300)
3372 fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"),
3373 pset.sversion / 10000, (pset.sversion / 100) % 100);
3378 return listTSConfigsVerbose(pattern);
3380 initPQExpBuffer(&buf);
3382 printfPQExpBuffer(&buf,
3384 " n.nspname as \"%s\",\n"
3385 " c.cfgname as \"%s\",\n"
3386 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
3387 "FROM pg_catalog.pg_ts_config c\n"
3388 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace \n",
3389 gettext_noop("Schema"),
3390 gettext_noop("Name"),
3391 gettext_noop("Description")
3394 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3395 "n.nspname", "c.cfgname", NULL,
3396 "pg_catalog.pg_ts_config_is_visible(c.oid)");
3398 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
3400 res = PSQLexec(buf.data, false);
3401 termPQExpBuffer(&buf);
3405 myopt.nullPrint = NULL;
3406 myopt.title = _("List of text search configurations");
3407 myopt.translate_header = true;
3409 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3416 listTSConfigsVerbose(const char *pattern)
3418 PQExpBufferData buf;
3422 initPQExpBuffer(&buf);
3424 printfPQExpBuffer(&buf,
3425 "SELECT c.oid, c.cfgname,\n"
3428 " np.nspname as pnspname \n"
3429 "FROM pg_catalog.pg_ts_config c \n"
3430 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace, \n"
3431 " pg_catalog.pg_ts_parser p \n"
3432 " LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace \n"
3433 "WHERE p.oid = c.cfgparser\n"
3436 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3437 "n.nspname", "c.cfgname", NULL,
3438 "pg_catalog.pg_ts_config_is_visible(c.oid)");
3440 appendPQExpBuffer(&buf, "ORDER BY 3, 2;");
3442 res = PSQLexec(buf.data, false);
3443 termPQExpBuffer(&buf);
3447 if (PQntuples(res) == 0)
3450 fprintf(stderr, _("Did not find any text search configuration named \"%s\".\n"),
3456 for (i = 0; i < PQntuples(res); i++)
3459 const char *cfgname;
3460 const char *nspname = NULL;
3461 const char *prsname;
3462 const char *pnspname = NULL;
3464 oid = PQgetvalue(res, i, 0);
3465 cfgname = PQgetvalue(res, i, 1);
3466 if (!PQgetisnull(res, i, 2))
3467 nspname = PQgetvalue(res, i, 2);
3468 prsname = PQgetvalue(res, i, 3);
3469 if (!PQgetisnull(res, i, 4))
3470 pnspname = PQgetvalue(res, i, 4);
3472 if (!describeOneTSConfig(oid, nspname, cfgname, pnspname, prsname))
3490 describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname,
3491 const char *pnspname, const char *prsname)
3493 PQExpBufferData buf,
3496 printQueryOpt myopt = pset.popt;
3498 initPQExpBuffer(&buf);
3500 printfPQExpBuffer(&buf,
3502 " ( SELECT t.alias FROM \n"
3503 " pg_catalog.ts_token_type(c.cfgparser) AS t \n"
3504 " WHERE t.tokid = m.maptokentype ) AS \"%s\", \n"
3505 " pg_catalog.btrim( \n"
3506 " ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary \n"
3507 " FROM pg_catalog.pg_ts_config_map AS mm \n"
3508 " WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype \n"
3509 " ORDER BY mapcfg, maptokentype, mapseqno \n"
3510 " ) :: pg_catalog.text , \n"
3511 " '{}') AS \"%s\" \n"
3512 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m \n"
3513 "WHERE c.oid = '%s' AND m.mapcfg = c.oid \n"
3514 "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser \n"
3516 gettext_noop("Token"),
3517 gettext_noop("Dictionaries"),
3520 res = PSQLexec(buf.data, false);
3521 termPQExpBuffer(&buf);
3525 initPQExpBuffer(&title);
3528 appendPQExpBuffer(&title, _("Text search configuration \"%s.%s\""),
3531 appendPQExpBuffer(&title, _("Text search configuration \"%s\""),
3535 appendPQExpBuffer(&title, _("\nParser: \"%s.%s\""),
3538 appendPQExpBuffer(&title, _("\nParser: \"%s\""),
3541 myopt.nullPrint = NULL;
3542 myopt.title = title.data;
3543 myopt.footers = NULL;
3544 myopt.default_footer = false;
3545 myopt.translate_header = true;
3547 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3549 termPQExpBuffer(&title);
3559 * Describes foreign-data wrappers
3562 listForeignDataWrappers(const char *pattern, bool verbose)
3564 PQExpBufferData buf;
3566 printQueryOpt myopt = pset.popt;
3568 if (pset.sversion < 80400)
3570 fprintf(stderr, _("The server (version %d.%d) does not support foreign-data wrappers.\n"),
3571 pset.sversion / 10000, (pset.sversion / 100) % 100);
3575 initPQExpBuffer(&buf);
3576 printfPQExpBuffer(&buf,
3577 "SELECT fdwname AS \"%s\",\n"
3578 " pg_catalog.pg_get_userbyid(fdwowner) AS \"%s\",\n",
3579 gettext_noop("Name"),
3580 gettext_noop("Owner"));
3581 if (pset.sversion >= 90100)
3582 appendPQExpBuffer(&buf,
3583 " fdwhandler::pg_catalog.regproc AS \"%s\",\n",
3584 gettext_noop("Handler"));
3585 appendPQExpBuffer(&buf,
3586 " fdwvalidator::pg_catalog.regproc AS \"%s\"",
3587 gettext_noop("Validator"));
3591 appendPQExpBuffer(&buf, ",\n ");
3592 printACLColumn(&buf, "fdwacl");
3593 appendPQExpBuffer(&buf,
3594 ",\n fdwoptions AS \"%s\"",
3595 gettext_noop("Options"));
3598 appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper\n");
3600 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3601 NULL, "fdwname", NULL, NULL);
3603 appendPQExpBuffer(&buf, "ORDER BY 1;");
3605 res = PSQLexec(buf.data, false);
3606 termPQExpBuffer(&buf);
3610 myopt.nullPrint = NULL;
3611 myopt.title = _("List of foreign-data wrappers");
3612 myopt.translate_header = true;
3614 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3623 * Describes foreign servers.
3626 listForeignServers(const char *pattern, bool verbose)
3628 PQExpBufferData buf;
3630 printQueryOpt myopt = pset.popt;
3632 if (pset.sversion < 80400)
3634 fprintf(stderr, _("The server (version %d.%d) does not support foreign servers.\n"),
3635 pset.sversion / 10000, (pset.sversion / 100) % 100);
3639 initPQExpBuffer(&buf);
3640 printfPQExpBuffer(&buf,
3641 "SELECT s.srvname AS \"%s\",\n"
3642 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
3643 " f.fdwname AS \"%s\"",
3644 gettext_noop("Name"),
3645 gettext_noop("Owner"),
3646 gettext_noop("Foreign-data wrapper"));
3650 appendPQExpBuffer(&buf, ",\n ");
3651 printACLColumn(&buf, "s.srvacl");
3652 appendPQExpBuffer(&buf,
3654 " s.srvtype AS \"%s\",\n"
3655 " s.srvversion AS \"%s\",\n"
3656 " s.srvoptions AS \"%s\"",
3657 gettext_noop("Type"),
3658 gettext_noop("Version"),
3659 gettext_noop("Options"));
3662 appendPQExpBuffer(&buf,
3663 "\nFROM pg_catalog.pg_foreign_server s\n"
3664 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
3666 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3667 NULL, "s.srvname", NULL, NULL);
3669 appendPQExpBuffer(&buf, "ORDER BY 1;");
3671 res = PSQLexec(buf.data, false);
3672 termPQExpBuffer(&buf);
3676 myopt.nullPrint = NULL;
3677 myopt.title = _("List of foreign servers");
3678 myopt.translate_header = true;
3680 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3689 * Describes user mappings.
3692 listUserMappings(const char *pattern, bool verbose)
3694 PQExpBufferData buf;
3696 printQueryOpt myopt = pset.popt;
3698 if (pset.sversion < 80400)
3700 fprintf(stderr, _("The server (version %d.%d) does not support user mappings.\n"),
3701 pset.sversion / 10000, (pset.sversion / 100) % 100);
3705 initPQExpBuffer(&buf);
3706 printfPQExpBuffer(&buf,
3707 "SELECT um.srvname AS \"%s\",\n"
3708 " um.usename AS \"%s\"",
3709 gettext_noop("Server"),
3710 gettext_noop("User name"));
3713 appendPQExpBuffer(&buf,
3714 ",\n um.umoptions AS \"%s\"",
3715 gettext_noop("Options"));
3717 appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
3719 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3720 NULL, "um.srvname", "um.usename", NULL);
3722 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
3724 res = PSQLexec(buf.data, false);
3725 termPQExpBuffer(&buf);
3729 myopt.nullPrint = NULL;
3730 myopt.title = _("List of user mappings");
3731 myopt.translate_header = true;
3733 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3742 * Describes foreign tables.
3745 listForeignTables(const char *pattern, bool verbose)
3747 PQExpBufferData buf;
3749 printQueryOpt myopt = pset.popt;
3751 if (pset.sversion < 90100)
3753 fprintf(stderr, _("The server (version %d.%d) does not support foreign tables.\n"),
3754 pset.sversion / 10000, (pset.sversion / 100) % 100);
3758 initPQExpBuffer(&buf);
3759 printfPQExpBuffer(&buf,
3760 "SELECT n.nspname AS \"%s\",\n"
3761 " c.relname AS \"%s\",\n"
3762 " s.srvname AS \"%s\"",
3763 gettext_noop("Schema"),
3764 gettext_noop("Table"),
3765 gettext_noop("Server"));
3768 appendPQExpBuffer(&buf,
3769 ",\n ft.ftoptions AS \"%s\"",
3770 gettext_noop("Options"));
3772 appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_foreign_table ft,");
3773 appendPQExpBuffer(&buf, "\n pg_catalog.pg_class c,");
3774 appendPQExpBuffer(&buf, "\n pg_catalog.pg_namespace n,");
3775 appendPQExpBuffer(&buf, "\n pg_catalog.pg_foreign_server s\n");
3776 appendPQExpBuffer(&buf, "\nWHERE c.oid = ft.ftrelid");
3777 appendPQExpBuffer(&buf, "\nAND s.oid = ft.ftserver\n");
3778 appendPQExpBuffer(&buf, "\nAND n.oid = c.relnamespace\n");
3780 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3781 NULL, "n.nspname", "c.relname", NULL);
3783 appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
3785 res = PSQLexec(buf.data, false);
3786 termPQExpBuffer(&buf);
3790 myopt.nullPrint = NULL;
3791 myopt.title = _("List of foreign tables");
3792 myopt.translate_header = true;
3794 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3803 * Briefly describes installed extensions.
3806 listExtensions(const char *pattern)
3808 PQExpBufferData buf;
3810 printQueryOpt myopt = pset.popt;
3812 if (pset.sversion < 90100)
3814 fprintf(stderr, _("The server (version %d.%d) does not support extensions.\n"),
3815 pset.sversion / 10000, (pset.sversion / 100) % 100);
3819 initPQExpBuffer(&buf);
3820 printfPQExpBuffer(&buf,
3821 "SELECT e.extname AS \"%s\", "
3822 "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
3823 "FROM pg_catalog.pg_extension e "
3824 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
3825 "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
3826 "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
3827 gettext_noop("Name"),
3828 gettext_noop("Version"),
3829 gettext_noop("Schema"),
3830 gettext_noop("Description"));
3832 processSQLNamePattern(pset.db, &buf, pattern,
3834 NULL, "e.extname", NULL,
3837 appendPQExpBuffer(&buf, "ORDER BY 1;");
3839 res = PSQLexec(buf.data, false);
3840 termPQExpBuffer(&buf);
3844 myopt.nullPrint = NULL;
3845 myopt.title = _("List of installed extensions");
3846 myopt.translate_header = true;
3848 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3857 * List contents of installed extensions.
3860 listExtensionContents(const char *pattern)
3862 PQExpBufferData buf;
3866 if (pset.sversion < 90100)
3868 fprintf(stderr, _("The server (version %d.%d) does not support extensions.\n"),
3869 pset.sversion / 10000, (pset.sversion / 100) % 100);
3873 initPQExpBuffer(&buf);
3874 printfPQExpBuffer(&buf,
3875 "SELECT e.extname, e.oid\n"
3876 "FROM pg_catalog.pg_extension e\n");
3878 processSQLNamePattern(pset.db, &buf, pattern,
3880 NULL, "e.extname", NULL,
3883 appendPQExpBuffer(&buf, "ORDER BY 1;");
3885 res = PSQLexec(buf.data, false);
3886 termPQExpBuffer(&buf);
3890 if (PQntuples(res) == 0)
3895 fprintf(stderr, _("Did not find any extension named \"%s\".\n"),
3898 fprintf(stderr, _("Did not find any extensions.\n"));
3904 for (i = 0; i < PQntuples(res); i++)
3906 const char *extname;
3909 extname = PQgetvalue(res, i, 0);
3910 oid = PQgetvalue(res, i, 1);
3912 if (!listOneExtensionContents(extname, oid))
3929 listOneExtensionContents(const char *extname, const char *oid)
3931 PQExpBufferData buf;
3934 printQueryOpt myopt = pset.popt;
3936 initPQExpBuffer(&buf);
3937 printfPQExpBuffer(&buf,
3938 "SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
3939 "FROM pg_catalog.pg_depend\n"
3940 "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
3942 gettext_noop("Object Description"),
3945 res = PSQLexec(buf.data, false);
3946 termPQExpBuffer(&buf);
3950 myopt.nullPrint = NULL;
3951 snprintf(title, sizeof(title), _("Objects in extension \"%s\""), extname);
3952 myopt.title = title;
3953 myopt.translate_header = true;
3955 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3964 * Helper function for consistently formatting ACL (privilege) columns.
3965 * The proper targetlist entry is appended to buf. Note lack of any
3966 * whitespace or comma decoration.
3969 printACLColumn(PQExpBuffer buf, const char *colname)
3971 if (pset.sversion >= 80100)
3972 appendPQExpBuffer(buf,
3973 "pg_catalog.array_to_string(%s, E'\\n') AS \"%s\"",
3974 colname, gettext_noop("Access privileges"));
3976 appendPQExpBuffer(buf,
3977 "pg_catalog.array_to_string(%s, '\\n') AS \"%s\"",
3978 colname, gettext_noop("Access privileges"));